]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/francetv.py
[extractors] Use new framework for existing embeds (#4307)
[yt-dlp.git] / yt_dlp / extractor / francetv.py
CommitLineData
5d8afe69 1from .common import InfoExtractor
1cc79574 2from ..utils import (
760f8121 3 determine_ext,
1cc79574 4 ExtractorError,
28fe35b4
F
5 format_field,
6 parse_iso8601,
4dfbf869 7 parse_qs,
5d8afe69 8)
3c4fbfec 9from .dailymotion import DailymotionIE
5d8afe69
PR
10
11
648d25d4 12class FranceTVBaseInfoExtractor(InfoExtractor):
79080573
S
13 def _make_url_result(self, video_or_full_id, catalog=None):
14 full_id = 'francetv:%s' % video_or_full_id
15 if '@' not in video_or_full_id and catalog:
99892e99
S
16 full_id += '@%s' % catalog
17 return self.url_result(
79080573
S
18 full_id, ie=FranceTVIE.ie_key(),
19 video_id=video_or_full_id.split('@')[0])
99892e99
S
20
21
22class FranceTVIE(InfoExtractor):
23 _VALID_URL = r'''(?x)
24 (?:
25 https?://
26 sivideo\.webservices\.francetelevisions\.fr/tools/getInfosOeuvre/v2/\?
27 .*?\bidDiffusion=[^&]+|
28 (?:
29 https?://videos\.francetv\.fr/video/|
30 francetv:
31 )
32 (?P<id>[^@]+)(?:@(?P<catalog>.+))?
33 )
34 '''
bfd973ec 35 _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?://)?embed\.francetv\.fr/\?ue=.+?)\1']
99892e99
S
36
37 _TESTS = [{
38 # without catalog
39 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=162311093&callback=_jsonp_loader_callback_request_0',
40 'md5': 'c2248a8de38c4e65ea8fae7b5df2d84f',
41 'info_dict': {
42 'id': '162311093',
43 'ext': 'mp4',
44 'title': '13h15, le dimanche... - Les mystères de Jésus',
45 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
46 'timestamp': 1502623500,
47 'upload_date': '20170813',
48 },
49 }, {
50 # with catalog
51 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=NI_1004933&catalogue=Zouzous&callback=_jsonp_loader_callback_request_4',
52 'only_matching': True,
53 }, {
54 'url': 'http://videos.francetv.fr/video/NI_657393@Regions',
55 'only_matching': True,
56 }, {
57 'url': 'francetv:162311093',
58 'only_matching': True,
59 }, {
60 'url': 'francetv:NI_1004933@Zouzous',
61 'only_matching': True,
62 }, {
63 'url': 'francetv:NI_983319@Info-web',
64 'only_matching': True,
65 }, {
66 'url': 'francetv:NI_983319',
67 'only_matching': True,
68 }, {
69 'url': 'francetv:NI_657393@Regions',
70 'only_matching': True,
760f8121
S
71 }, {
72 # france-3 live
73 'url': 'francetv:SIM_France3',
74 'only_matching': True,
99892e99
S
75 }]
76
6d1ded75 77 def _extract_video(self, video_id, catalogue=None):
99892e99
S
78 # Videos are identified by idDiffusion so catalogue part is optional.
79 # However when provided, some extra formats may be returned so we pass
80 # it if available.
760f8121 81 is_live = None
8bdd16b4 82 videos = []
28fe35b4
F
83 title = None
84 subtitle = None
85 image = None
86 duration = None
87 timestamp = None
88 spritesheets = None
89
90 for device_type in ('desktop', 'mobile'):
91 dinfo = self._download_json(
92 'https://player.webservices.francetelevisions.fr/v1/videos/%s' % video_id,
93 video_id, 'Downloading %s video JSON' % device_type, query={
94 'device_type': device_type,
95 'browser': 'chrome',
96 }, fatal=False)
97
98 if not dinfo:
8bdd16b4 99 continue
8bdd16b4 100
28fe35b4
F
101 video = dinfo.get('video')
102 if video:
103 videos.append(video)
104 if duration is None:
105 duration = video.get('duration')
106 if is_live is None:
107 is_live = video.get('is_live')
108 if spritesheets is None:
109 spritesheets = video.get('spritesheets')
110
111 meta = dinfo.get('meta')
112 if meta:
113 if title is None:
114 title = meta.get('title')
115 # XXX: what is meta['pre_title']?
116 if subtitle is None:
117 subtitle = meta.get('additional_title')
118 if image is None:
119 image = meta.get('image_url')
120 if timestamp is None:
121 timestamp = parse_iso8601(meta.get('broadcasted_at'))
8bdd16b4 122
123 formats = []
b2cd5da4 124 subtitles = {}
8bdd16b4 125 for video in videos:
8bdd16b4 126 format_id = video.get('format')
28fe35b4
F
127
128 video_url = None
129 if video.get('workflow') == 'token-akamai':
130 token_url = video.get('token')
131 if token_url:
132 token_json = self._download_json(
133 token_url, video_id,
134 'Downloading signed %s manifest URL' % format_id)
135 if token_json:
136 video_url = token_json.get('url')
137 if not video_url:
138 video_url = video.get('url')
139
bc03228a
S
140 ext = determine_ext(video_url)
141 if ext == 'f4m':
8faa338f 142 formats.extend(self._extract_f4m_formats(
28fe35b4 143 video_url, video_id, f4m_id=format_id, fatal=False))
bc03228a 144 elif ext == 'm3u8':
28fe35b4
F
145 fmts, subs = self._extract_m3u8_formats_and_subtitles(
146 video_url, video_id, 'mp4',
8faa338f 147 entry_protocol='m3u8_native', m3u8_id=format_id,
b2cd5da4 148 fatal=False)
28fe35b4
F
149 formats.extend(fmts)
150 self._merge_subtitles(subs, target=subtitles)
8bdd16b4 151 elif ext == 'mpd':
28fe35b4
F
152 fmts, subs = self._extract_mpd_formats_and_subtitles(
153 video_url, video_id, mpd_id=format_id, fatal=False)
154 formats.extend(fmts)
155 self._merge_subtitles(subs, target=subtitles)
64892c0b
S
156 elif video_url.startswith('rtmp'):
157 formats.append({
158 'url': video_url,
159 'format_id': 'rtmp-%s' % format_id,
160 'ext': 'flv',
64892c0b
S
161 })
162 else:
3c20208e
S
163 if self._is_valid_url(video_url, video_id, format_id):
164 formats.append({
165 'url': video_url,
166 'format_id': format_id,
167 })
8bdd16b4 168
28fe35b4
F
169 # XXX: what is video['captions']?
170
171 for f in formats:
172 if f.get('acodec') != 'none' and f.get('language') in ('qtz', 'qad'):
173 f['language_preference'] = -10
174 f['format_note'] = 'audio description%s' % format_field(f, 'format_note', ', %s')
175
176 if spritesheets:
177 formats.append({
178 'format_id': 'spritesheets',
179 'format_note': 'storyboard',
180 'acodec': 'none',
181 'vcodec': 'none',
182 'ext': 'mhtml',
183 'protocol': 'mhtml',
9222c381 184 'url': 'about:invalid',
28fe35b4 185 'fragments': [{
b3edc806 186 'url': sheet,
28fe35b4
F
187 # XXX: not entirely accurate; each spritesheet seems to be
188 # a 10×10 grid of thumbnails corresponding to approximately
189 # 2 seconds of the video; the last spritesheet may be shorter
190 'duration': 200,
191 } for sheet in spritesheets]
192 })
193
64892c0b 194 self._sort_formats(formats)
648d25d4 195
36c15522
S
196 if subtitle:
197 title += ' - %s' % subtitle
db264e3c 198 title = title.strip()
36c15522 199
7e8d73c1
JMF
200 return {
201 'id': video_id,
39ca3b5c 202 'title': title,
28fe35b4
F
203 'thumbnail': image,
204 'duration': duration,
205 'timestamp': timestamp,
760f8121 206 'is_live': is_live,
7e8d73c1 207 'formats': formats,
5dadae07 208 'subtitles': subtitles,
7e8d73c1 209 }
648d25d4 210
99892e99 211 def _real_extract(self, url):
5ad28e7f 212 mobj = self._match_valid_url(url)
99892e99
S
213 video_id = mobj.group('id')
214 catalog = mobj.group('catalog')
215
216 if not video_id:
4dfbf869 217 qs = parse_qs(url)
99892e99
S
218 video_id = qs.get('idDiffusion', [None])[0]
219 catalog = qs.get('catalogue', [None])[0]
220 if not video_id:
221 raise ExtractorError('Invalid URL', expected=True)
222
223 return self._extract_video(video_id, catalog)
224
648d25d4 225
99892e99 226class FranceTVSiteIE(FranceTVBaseInfoExtractor):
4489d418 227 _VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
5d8afe69 228
6d1ded75
S
229 _TESTS = [{
230 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
231 'info_dict': {
9d74ea6d 232 'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1',
6d1ded75
S
233 'ext': 'mp4',
234 'title': '13h15, le dimanche... - Les mystères de Jésus',
235 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
99892e99
S
236 'timestamp': 1502623500,
237 'upload_date': '20170813',
6d1ded75
S
238 },
239 'params': {
6d1ded75
S
240 'skip_download': True,
241 },
99892e99 242 'add_ie': [FranceTVIE.ie_key()],
6d1ded75
S
243 }, {
244 # france3
245 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
246 'only_matching': True,
247 }, {
248 # france4
249 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
250 'only_matching': True,
251 }, {
252 # france5
253 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
254 'only_matching': True,
255 }, {
256 # franceo
257 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
258 'only_matching': True,
259 }, {
260 # france2 live
261 'url': 'https://www.france.tv/france-2/direct.html',
262 'only_matching': True,
263 }, {
264 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
265 'only_matching': True,
266 }, {
267 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
268 'only_matching': True,
12f01118
S
269 }, {
270 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
271 'only_matching': True,
4489d418
S
272 }, {
273 'url': 'https://www.france.tv/142749-rouge-sang.html',
274 'only_matching': True,
49702e36
S
275 }, {
276 # france-3 live
277 'url': 'https://www.france.tv/france-3/direct.html',
278 'only_matching': True,
6d1ded75 279 }]
5d8afe69
PR
280
281 def _real_extract(self, url):
0a192fbe
S
282 display_id = self._match_id(url)
283
284 webpage = self._download_webpage(url, display_id)
285
6d1ded75
S
286 catalogue = None
287 video_id = self._search_regex(
9d74ea6d 288 r'(?:data-main-video\s*=|videoId["\']?\s*[:=])\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
6d1ded75
S
289 webpage, 'video id', default=None, group='id')
290
0a192fbe 291 if not video_id:
6d1ded75
S
292 video_id, catalogue = self._html_search_regex(
293 r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
294 webpage, 'video ID').split('@')
99892e99
S
295
296 return self._make_url_result(video_id, catalogue)
6d1ded75
S
297
298
6d1ded75 299class FranceTVInfoIE(FranceTVBaseInfoExtractor):
3c1b4669 300 IE_NAME = 'francetvinfo.fr'
99892e99 301 _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&.]+)'
5d8afe69 302
5c30b268 303 _TESTS = [{
13c30d1d 304 'url': 'https://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-jeudi-22-aout-2019_3561461.html',
3c1b4669 305 'info_dict': {
13c30d1d 306 'id': 'd12458ee-5062-48fe-bfdd-a30d6a01b793',
3c20208e 307 'ext': 'mp4',
3c1b4669 308 'title': 'Soir 3',
13c30d1d
S
309 'upload_date': '20190822',
310 'timestamp': 1566510900,
311 'description': 'md5:72d167097237701d6e8452ff03b83c00',
c137cc0d
S
312 'subtitles': {
313 'fr': 'mincount:2',
314 },
648d25d4 315 },
3c20208e 316 'params': {
3c20208e
S
317 'skip_download': True,
318 },
99892e99 319 'add_ie': [FranceTVIE.ie_key()],
bbed5763 320 }, {
321 'note': 'Only an image exists in initial webpage instead of the video',
322 'url': 'https://www.francetvinfo.fr/sante/maladie/coronavirus/covid-19-en-inde-une-situation-catastrophique-a-new-dehli_4381095.html',
323 'info_dict': {
324 'id': '7d204c9e-a2d3-11eb-9e4c-000d3a23d482',
325 'ext': 'mp4',
326 'title': 'Covid-19 : une situation catastrophique à New Dehli',
327 'thumbnail': str,
328 'duration': 76,
329 'timestamp': 1619028518,
330 'upload_date': '20210421',
331 },
332 'params': {
333 'skip_download': True,
334 },
335 'add_ie': [FranceTVIE.ie_key()],
5c30b268
PH
336 }, {
337 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
99892e99 338 'only_matching': True,
6f96e308
YCH
339 }, {
340 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
99892e99 341 'only_matching': True,
db264e3c
S
342 }, {
343 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
99892e99 344 'only_matching': True,
ad213a1d
YCH
345 }, {
346 # Dailymotion embed
347 'url': 'http://www.francetvinfo.fr/politique/notre-dame-des-landes/video-sur-france-inter-cecile-duflot-denonce-le-regard-meprisant-de-patrick-cohen_1520091.html',
348 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
349 'info_dict': {
350 'id': 'x4iiko0',
351 'ext': 'mp4',
352 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
353 'description': 'Au lendemain de la victoire du "oui" au référendum sur l\'aéroport de Notre-Dame-des-Landes, l\'ancienne ministre écologiste est l\'invitée de Patrick Cohen. Plus d\'info : https://www.franceinter.fr/emissions/le-7-9/le-7-9-27-juin-2016',
354 'timestamp': 1467011958,
355 'upload_date': '20160627',
356 'uploader': 'France Inter',
357 'uploader_id': 'x2q2ez',
358 },
359 'add_ie': ['Dailymotion'],
30b25d38
S
360 }, {
361 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
362 'only_matching': True,
41d1cca3 363 }, {
364 # "<figure id=" pattern (#28792)
365 'url': 'https://www.francetvinfo.fr/culture/patrimoine/incendie-de-notre-dame-de-paris/notre-dame-de-paris-de-l-incendie-de-la-cathedrale-a-sa-reconstruction_4372291.html',
366 'only_matching': True,
5c30b268 367 }]
648d25d4
JMF
368
369 def _real_extract(self, url):
99892e99
S
370 display_id = self._match_id(url)
371
372 webpage = self._download_webpage(url, display_id)
6f96e308 373
bfd973ec 374 dailymotion_urls = DailymotionIE._extract_embed_urls(url, webpage)
ad213a1d
YCH
375 if dailymotion_urls:
376 return self.playlist_result([
377 self.url_result(dailymotion_url, DailymotionIE.ie_key())
378 for dailymotion_url in dailymotion_urls])
6f96e308 379
876fed6b 380 video_id = self._search_regex(
381 (r'player\.load[^;]+src:\s*["\']([^"\']+)',
382 r'id-video=([^@]+@[^"]+)',
13c30d1d 383 r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"',
41d1cca3 384 r'(?:data-id|<figure[^<]+\bid)=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'),
876fed6b 385 webpage, 'video id')
99892e99 386
876fed6b 387 return self._make_url_result(video_id)