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