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