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