]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/francetv.py
[francetv] Fix f4m extraction completely
[yt-dlp.git] / youtube_dl / extractor / francetv.py
CommitLineData
5d8afe69 1# encoding: utf-8
3c1b4669
PH
2
3from __future__ import unicode_literals
4
5d8afe69 5import re
5b333c1c 6import json
5d8afe69
PR
7
8from .common import InfoExtractor
1cc79574
PH
9from ..compat import (
10 compat_urllib_parse_urlparse,
5d8afe69 11 compat_urlparse,
1cc79574
PH
12)
13from ..utils import (
64892c0b 14 clean_html,
1cc79574 15 ExtractorError,
64892c0b 16 int_or_none,
1cc79574 17 parse_duration,
bc03228a 18 determine_ext,
5d8afe69 19)
6f96e308 20from .dailymotion import DailymotionCloudIE
5d8afe69
PR
21
22
648d25d4 23class FranceTVBaseInfoExtractor(InfoExtractor):
64892c0b
S
24 def _extract_video(self, video_id, catalogue):
25 info = self._download_json(
26 'http://webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=%s&catalogue=%s'
27 % (video_id, catalogue),
28 video_id, 'Downloading video JSON')
29
30 if info.get('status') == 'NOK':
31 raise ExtractorError(
32 '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True)
00e9d396
JMF
33 allowed_countries = info['videos'][0].get('geoblocage')
34 if allowed_countries:
35 georestricted = True
36 geo_info = self._download_json(
37 'http://geo.francetv.fr/ws/edgescape.json', video_id,
38 'Downloading geo restriction info')
39 country = geo_info['reponse']['geo_info']['country_code']
40 if country not in allowed_countries:
41 raise ExtractorError(
42 'The video is not available from your location',
43 expected=True)
44 else:
45 georestricted = False
46
64892c0b
S
47 formats = []
48 for video in info['videos']:
49 if video['statut'] != 'ONLINE':
50 continue
51 video_url = video['url']
52 if not video_url:
53 continue
54 format_id = video['format']
bc03228a
S
55 ext = determine_ext(video_url)
56 if ext == 'f4m':
00e9d396
JMF
57 if georestricted:
58 # See https://github.com/rg3/youtube-dl/issues/3963
59 # m3u8 urls work fine
60 continue
64892c0b 61 f4m_url = self._download_webpage(
ecdbe09e 62 'http://hdfauth.francetv.fr/esi/TA?url=%s' % video_url,
64892c0b
S
63 video_id, 'Downloading f4m manifest token', fatal=False)
64 if f4m_url:
632cbb8e
S
65 formats.extend(self._extract_f4m_formats(
66 f4m_url + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id, 1, format_id))
bc03228a
S
67 elif ext == 'm3u8':
68 formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4', m3u8_id=format_id))
64892c0b
S
69 elif video_url.startswith('rtmp'):
70 formats.append({
71 'url': video_url,
72 'format_id': 'rtmp-%s' % format_id,
73 'ext': 'flv',
74 'preference': 1,
75 })
76 else:
77 formats.append({
78 'url': video_url,
79 'format_id': format_id,
2399535f 80 'preference': -1,
64892c0b
S
81 })
82 self._sort_formats(formats)
648d25d4 83
7e8d73c1
JMF
84 return {
85 'id': video_id,
64892c0b
S
86 'title': info['titre'],
87 'description': clean_html(info['synopsis']),
88 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
5705ee6e 89 'duration': int_or_none(info.get('real_duration')) or parse_duration(info['duree']),
64892c0b 90 'timestamp': int_or_none(info['diffusion']['timestamp']),
7e8d73c1 91 'formats': formats,
7e8d73c1 92 }
648d25d4
JMF
93
94
95class PluzzIE(FranceTVBaseInfoExtractor):
3c1b4669 96 IE_NAME = 'pluzz.francetv.fr'
5d8afe69
PR
97 _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
98
5d13df79 99 # Can't use tests, videos expire in 7 days
5d8afe69
PR
100
101 def _real_extract(self, url):
102 title = re.match(self._VALID_URL, url).group(1)
103 webpage = self._download_webpage(url, title)
104 video_id = self._search_regex(
105 r'data-diffusion="(\d+)"', webpage, 'ID')
64892c0b 106 return self._extract_video(video_id, 'Pluzz')
5d8afe69 107
5d8afe69 108
648d25d4 109class FranceTvInfoIE(FranceTVBaseInfoExtractor):
3c1b4669 110 IE_NAME = 'francetvinfo.fr'
23d3c422 111 _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
5d8afe69 112
5c30b268 113 _TESTS = [{
3c1b4669 114 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
3c1b4669 115 'info_dict': {
5c30b268 116 'id': '84981923',
64892c0b 117 'ext': 'flv',
3c1b4669 118 'title': 'Soir 3',
64892c0b
S
119 'upload_date': '20130826',
120 'timestamp': 1377548400,
648d25d4 121 },
5c30b268
PH
122 }, {
123 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
124 'info_dict': {
125 'id': 'EV_20019',
126 'ext': 'mp4',
127 'title': 'Débat des candidats à la Commission européenne',
128 'description': 'Débat des candidats à la Commission européenne',
129 },
130 'params': {
131 'skip_download': 'HLS (reqires ffmpeg)'
64892c0b
S
132 },
133 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
6f96e308
YCH
134 }, {
135 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
136 'md5': 'f485bda6e185e7d15dbc69b72bae993e',
137 'info_dict': {
138 'id': '556e03339473995ee145930c',
139 'ext': 'mp4',
140 'title': 'Les entreprises familiales : le secret de la réussite',
141 'thumbnail': 're:^https?://.*\.jpe?g$',
142 }
5c30b268 143 }]
648d25d4
JMF
144
145 def _real_extract(self, url):
146 mobj = re.match(self._VALID_URL, url)
147 page_title = mobj.group('title')
148 webpage = self._download_webpage(url, page_title)
6f96e308
YCH
149
150 dmcloud_url = DailymotionCloudIE._extract_dmcloud_url(webpage)
151 if dmcloud_url:
152 return self.url_result(dmcloud_url, 'DailymotionCloud')
153
64892c0b
S
154 video_id, catalogue = self._search_regex(
155 r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
156 return self._extract_video(video_id, catalogue)
a825f330
JMF
157
158
9e606020 159class FranceTVIE(FranceTVBaseInfoExtractor):
3c1b4669
PH
160 IE_NAME = 'francetv'
161 IE_DESC = 'France 2, 3, 4, 5 and Ô'
3f5c6d0c
S
162 _VALID_URL = r'''(?x)
163 https?://
164 (?:
165 (?:www\.)?france[2345o]\.fr/
166 (?:
167 emissions/[^/]+/(?:videos|diffusions)?|
789a12aa
S
168 videos|
169 jt
3f5c6d0c
S
170 )
171 /|
172 embed\.francetv\.fr/\?ue=
173 )
174 (?P<id>[^/?]+)
175 '''
a825f330 176
9e606020
JMF
177 _TESTS = [
178 # france2
179 {
3c1b4669 180 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
64892c0b 181 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
3c1b4669 182 'info_dict': {
64892c0b
S
183 'id': '109169362',
184 'ext': 'flv',
185 'title': '13h15, le dimanche...',
186 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
187 'upload_date': '20140914',
188 'timestamp': 1410693600,
9e606020 189 },
a825f330 190 },
9e606020
JMF
191 # france3
192 {
3c1b4669 193 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
64892c0b 194 'md5': '679bb8f8921f8623bd658fa2f8364da0',
3c1b4669
PH
195 'info_dict': {
196 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
64892c0b 197 'ext': 'mp4',
3c1b4669
PH
198 'title': 'Le scandale du prix des médicaments',
199 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
64892c0b
S
200 'upload_date': '20131113',
201 'timestamp': 1384380000,
9e606020 202 },
a825f330 203 },
9e606020
JMF
204 # france4
205 {
3c1b4669 206 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
64892c0b 207 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
3c1b4669
PH
208 'info_dict': {
209 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
64892c0b 210 'ext': 'mp4',
3c1b4669
PH
211 'title': 'Hero Corp Making of - Extrait 1',
212 'description': 'md5:c87d54871b1790679aec1197e73d650a',
64892c0b
S
213 'upload_date': '20131106',
214 'timestamp': 1383766500,
9e606020
JMF
215 },
216 },
217 # france5
218 {
3c1b4669 219 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
64892c0b 220 'md5': '78f0f4064f9074438e660785bbf2c5d9',
3c1b4669 221 'info_dict': {
64892c0b
S
222 'id': '108961659',
223 'ext': 'flv',
3c1b4669 224 'title': 'C à dire ?!',
64892c0b
S
225 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
226 'upload_date': '20140915',
227 'timestamp': 1410795000,
9e606020
JMF
228 },
229 },
230 # franceo
231 {
3c1b4669 232 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
64892c0b 233 'md5': '52f0bfe202848b15915a2f39aaa8981b',
3c1b4669 234 'info_dict': {
64892c0b
S
235 'id': '108634970',
236 'ext': 'flv',
237 'title': 'Infô Afrique',
3c1b4669 238 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
64892c0b
S
239 'upload_date': '20140915',
240 'timestamp': 1410822000,
9e606020 241 },
9e606020 242 },
3f5c6d0c
S
243 {
244 # francetv embed
245 'url': 'http://embed.francetv.fr/?ue=8d7d3da1e3047c42ade5a5d7dfd3fc87',
246 'info_dict': {
247 'id': 'EV_30231',
248 'ext': 'flv',
249 'title': 'Alcaline, le concert avec Calogero',
250 'description': 'md5:',
251 'upload_date': '20150226',
252 'timestamp': 1424989860,
5705ee6e 253 'duration': 5400,
3f5c6d0c
S
254 },
255 },
256 {
257 'url': 'http://www.france4.fr/emission/highlander/diffusion-du-17-07-2015-04h05',
258 'only_matching': True,
259 },
260 {
261 'url': 'http://www.franceo.fr/videos/125377617',
262 'only_matching': True,
263 }
9e606020 264 ]
a825f330
JMF
265
266 def _real_extract(self, url):
3f5c6d0c
S
267 video_id = self._match_id(url)
268 webpage = self._download_webpage(url, video_id)
64892c0b 269 video_id, catalogue = self._html_search_regex(
3f5c6d0c 270 r'href="http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
64892c0b
S
271 webpage, 'video ID').split('@')
272 return self._extract_video(video_id, catalogue)
5b333c1c
JMF
273
274
275class GenerationQuoiIE(InfoExtractor):
3c1b4669 276 IE_NAME = 'france2.fr:generation-quoi'
c4e817ce 277 _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<id>[^/?#]+)'
5b333c1c
JMF
278
279 _TEST = {
3c1b4669 280 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
3c1b4669 281 'info_dict': {
c4e817ce
PH
282 'id': 'k7FJX8VBcvvLmX4wA5Q',
283 'ext': 'mp4',
3c1b4669
PH
284 'title': 'Génération Quoi - Garde à Vous',
285 'uploader': 'Génération Quoi',
5b333c1c 286 },
3c1b4669 287 'params': {
5b333c1c 288 # It uses Dailymotion
3c1b4669 289 'skip_download': True,
5b333c1c
JMF
290 },
291 }
292
293 def _real_extract(self, url):
c4e817ce
PH
294 display_id = self._match_id(url)
295 info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % display_id)
296 info_json = self._download_webpage(info_url, display_id)
5b333c1c
JMF
297 info = json.loads(info_json)
298 return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
9e1a5b84 299 ie='Dailymotion')
469ec941
JMF
300
301
302class CultureboxIE(FranceTVBaseInfoExtractor):
3c1b4669 303 IE_NAME = 'culturebox.francetvinfo.fr'
23d3c422 304 _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
469ec941
JMF
305
306 _TEST = {
aed2d4b3 307 'url': 'http://culturebox.francetvinfo.fr/live/musique/musique-classique/le-livre-vermeil-de-montserrat-a-la-cathedrale-delne-214511',
ac651e97 308 'md5': '9b88dc156781c4dbebd4c3e066e0b1d6',
3c1b4669 309 'info_dict': {
aed2d4b3 310 'id': 'EV_50111',
ac651e97 311 'ext': 'flv',
aed2d4b3
S
312 'title': "Le Livre Vermeil de Montserrat à la Cathédrale d'Elne",
313 'description': 'md5:f8a4ad202e8fe533e2c493cc12e739d9',
314 'upload_date': '20150320',
315 'timestamp': 1426892400,
316 'duration': 2760.9,
317 },
469ec941
JMF
318 }
319
320 def _real_extract(self, url):
321 mobj = re.match(self._VALID_URL, url)
322 name = mobj.group('name')
184a1974 323
469ec941 324 webpage = self._download_webpage(url, name)
184a1974
S
325
326 if ">Ce live n'est plus disponible en replay<" in webpage:
327 raise ExtractorError('Video %s is not available' % name, expected=True)
328
64892c0b
S
329 video_id, catalogue = self._search_regex(
330 r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
331
332 return self._extract_video(video_id, catalogue)