]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/francetv.py
Update to ytdl-commit-a726009
[yt-dlp.git] / yt_dlp / extractor / francetv.py
CommitLineData
dcdb292f 1# coding: utf-8
3c1b4669
PH
2
3from __future__ import unicode_literals
4
5d8afe69 5import re
5d8afe69
PR
6
7from .common import InfoExtractor
8faa338f
S
8from ..compat import (
9 compat_str,
10 compat_urlparse,
11)
1cc79574 12from ..utils import (
64892c0b 13 clean_html,
760f8121 14 determine_ext,
1cc79574 15 ExtractorError,
64892c0b 16 int_or_none,
1cc79574 17 parse_duration,
760f8121 18 try_get,
3052a30d 19 url_or_none,
8bdd16b4 20 urljoin,
5d8afe69 21)
3c4fbfec 22from .dailymotion import DailymotionIE
5d8afe69
PR
23
24
648d25d4 25class FranceTVBaseInfoExtractor(InfoExtractor):
79080573
S
26 def _make_url_result(self, video_or_full_id, catalog=None):
27 full_id = 'francetv:%s' % video_or_full_id
28 if '@' not in video_or_full_id and catalog:
99892e99
S
29 full_id += '@%s' % catalog
30 return self.url_result(
79080573
S
31 full_id, ie=FranceTVIE.ie_key(),
32 video_id=video_or_full_id.split('@')[0])
99892e99
S
33
34
35class FranceTVIE(InfoExtractor):
36 _VALID_URL = r'''(?x)
37 (?:
38 https?://
39 sivideo\.webservices\.francetelevisions\.fr/tools/getInfosOeuvre/v2/\?
40 .*?\bidDiffusion=[^&]+|
41 (?:
42 https?://videos\.francetv\.fr/video/|
43 francetv:
44 )
45 (?P<id>[^@]+)(?:@(?P<catalog>.+))?
46 )
47 '''
48
49 _TESTS = [{
50 # without catalog
51 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=162311093&callback=_jsonp_loader_callback_request_0',
52 'md5': 'c2248a8de38c4e65ea8fae7b5df2d84f',
53 'info_dict': {
54 'id': '162311093',
55 'ext': 'mp4',
56 'title': '13h15, le dimanche... - Les mystères de Jésus',
57 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
58 'timestamp': 1502623500,
59 'upload_date': '20170813',
60 },
61 }, {
62 # with catalog
63 'url': 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=NI_1004933&catalogue=Zouzous&callback=_jsonp_loader_callback_request_4',
64 'only_matching': True,
65 }, {
66 'url': 'http://videos.francetv.fr/video/NI_657393@Regions',
67 'only_matching': True,
68 }, {
69 'url': 'francetv:162311093',
70 'only_matching': True,
71 }, {
72 'url': 'francetv:NI_1004933@Zouzous',
73 'only_matching': True,
74 }, {
75 'url': 'francetv:NI_983319@Info-web',
76 'only_matching': True,
77 }, {
78 'url': 'francetv:NI_983319',
79 'only_matching': True,
80 }, {
81 'url': 'francetv:NI_657393@Regions',
82 'only_matching': True,
760f8121
S
83 }, {
84 # france-3 live
85 'url': 'francetv:SIM_France3',
86 'only_matching': True,
99892e99
S
87 }]
88
6d1ded75 89 def _extract_video(self, video_id, catalogue=None):
99892e99
S
90 # Videos are identified by idDiffusion so catalogue part is optional.
91 # However when provided, some extra formats may be returned so we pass
92 # it if available.
64892c0b 93 info = self._download_json(
6d1ded75
S
94 'https://sivideo.webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/',
95 video_id, 'Downloading video JSON', query={
96 'idDiffusion': video_id,
97 'catalogue': catalogue or '',
98 })
64892c0b
S
99
100 if info.get('status') == 'NOK':
101 raise ExtractorError(
8faa338f
S
102 '%s returned error: %s' % (self.IE_NAME, info['message']),
103 expected=True)
00e9d396
JMF
104 allowed_countries = info['videos'][0].get('geoblocage')
105 if allowed_countries:
106 georestricted = True
107 geo_info = self._download_json(
108 'http://geo.francetv.fr/ws/edgescape.json', video_id,
109 'Downloading geo restriction info')
110 country = geo_info['reponse']['geo_info']['country_code']
111 if country not in allowed_countries:
112 raise ExtractorError(
113 'The video is not available from your location',
114 expected=True)
115 else:
116 georestricted = False
117
8faa338f
S
118 def sign(manifest_url, manifest_id):
119 for host in ('hdfauthftv-a.akamaihd.net', 'hdfauth.francetv.fr'):
3052a30d 120 signed_url = url_or_none(self._download_webpage(
8faa338f
S
121 'https://%s/esi/TA' % host, video_id,
122 'Downloading signed %s manifest URL' % manifest_id,
123 fatal=False, query={
124 'url': manifest_url,
3052a30d
S
125 }))
126 if signed_url:
8faa338f
S
127 return signed_url
128 return manifest_url
129
760f8121
S
130 is_live = None
131
8bdd16b4 132 videos = []
133
134 for video in (info.get('videos') or []):
135 if video.get('statut') != 'ONLINE':
64892c0b 136 continue
8bdd16b4 137 if not video.get('url'):
138 continue
139 videos.append(video)
140
141 if not videos:
142 for device_type in ['desktop', 'mobile']:
143 fallback_info = self._download_json(
144 'https://player.webservices.francetelevisions.fr/v1/videos/%s' % video_id,
145 video_id, 'Downloading fallback %s video JSON' % device_type, query={
146 'device_type': device_type,
147 'browser': 'chrome',
148 }, fatal=False)
149
150 if fallback_info and fallback_info.get('video'):
151 videos.append(fallback_info['video'])
152
153 formats = []
b2cd5da4 154 subtitles = {}
8bdd16b4 155 for video in videos:
156 video_url = video.get('url')
64892c0b
S
157 if not video_url:
158 continue
760f8121
S
159 if is_live is None:
160 is_live = (try_get(
8bdd16b4 161 video, lambda x: x['plages_ouverture'][0]['direct'], bool) is True
162 or video.get('is_live') is True
163 or '/live.francetv.fr/' in video_url)
164 format_id = video.get('format')
bc03228a
S
165 ext = determine_ext(video_url)
166 if ext == 'f4m':
00e9d396 167 if georestricted:
067aa17e 168 # See https://github.com/ytdl-org/youtube-dl/issues/3963
00e9d396
JMF
169 # m3u8 urls work fine
170 continue
8faa338f
S
171 formats.extend(self._extract_f4m_formats(
172 sign(video_url, format_id) + '&hdcore=3.7.0&plugin=aasp-3.7.0.39.44',
173 video_id, f4m_id=format_id, fatal=False))
bc03228a 174 elif ext == 'm3u8':
b2cd5da4 175 m3u8_fmts, m3u8_subs = self._extract_m3u8_formats_and_subtitles(
8faa338f
S
176 sign(video_url, format_id), video_id, 'mp4',
177 entry_protocol='m3u8_native', m3u8_id=format_id,
b2cd5da4
F
178 fatal=False)
179 formats.extend(m3u8_fmts)
180 subtitles = self._merge_subtitles(subtitles, m3u8_subs)
8bdd16b4 181 elif ext == 'mpd':
182 formats.extend(self._extract_mpd_formats(
183 sign(video_url, format_id), video_id, mpd_id=format_id, fatal=False))
64892c0b
S
184 elif video_url.startswith('rtmp'):
185 formats.append({
186 'url': video_url,
187 'format_id': 'rtmp-%s' % format_id,
188 'ext': 'flv',
64892c0b
S
189 })
190 else:
3c20208e
S
191 if self._is_valid_url(video_url, video_id, format_id):
192 formats.append({
193 'url': video_url,
194 'format_id': format_id,
195 })
8bdd16b4 196
64892c0b 197 self._sort_formats(formats)
648d25d4 198
36c15522
S
199 title = info['titre']
200 subtitle = info.get('sous_titre')
201 if subtitle:
202 title += ' - %s' % subtitle
db264e3c 203 title = title.strip()
36c15522 204
b2cd5da4
F
205 subtitles.setdefault('fr', []).extend(
206 [{
207 'url': subformat['url'],
208 'ext': subformat.get('format'),
209 } for subformat in info.get('subtitles', []) if subformat.get('url')]
210 )
5dadae07 211
7e8d73c1
JMF
212 return {
213 'id': video_id,
760f8121 214 'title': self._live_title(title) if is_live else title,
8bdd16b4 215 'description': clean_html(info.get('synopsis')),
a0566bbf 216 'thumbnail': urljoin('https://sivideo.webservices.francetelevisions.fr', info.get('image')),
8bdd16b4 217 'duration': int_or_none(info.get('real_duration')) or parse_duration(info.get('duree')),
218 'timestamp': int_or_none(try_get(info, lambda x: x['diffusion']['timestamp'])),
760f8121 219 'is_live': is_live,
7e8d73c1 220 'formats': formats,
5dadae07 221 'subtitles': subtitles,
7e8d73c1 222 }
648d25d4 223
99892e99
S
224 def _real_extract(self, url):
225 mobj = re.match(self._VALID_URL, url)
226 video_id = mobj.group('id')
227 catalog = mobj.group('catalog')
228
229 if not video_id:
230 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
231 video_id = qs.get('idDiffusion', [None])[0]
232 catalog = qs.get('catalogue', [None])[0]
233 if not video_id:
234 raise ExtractorError('Invalid URL', expected=True)
235
236 return self._extract_video(video_id, catalog)
237
648d25d4 238
99892e99 239class FranceTVSiteIE(FranceTVBaseInfoExtractor):
4489d418 240 _VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
5d8afe69 241
6d1ded75
S
242 _TESTS = [{
243 'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
244 'info_dict': {
9d74ea6d 245 'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1',
6d1ded75
S
246 'ext': 'mp4',
247 'title': '13h15, le dimanche... - Les mystères de Jésus',
248 'description': 'md5:75efe8d4c0a8205e5904498ffe1e1a42',
99892e99
S
249 'timestamp': 1502623500,
250 'upload_date': '20170813',
6d1ded75
S
251 },
252 'params': {
6d1ded75
S
253 'skip_download': True,
254 },
99892e99 255 'add_ie': [FranceTVIE.ie_key()],
6d1ded75
S
256 }, {
257 # france3
258 'url': 'https://www.france.tv/france-3/des-chiffres-et-des-lettres/139063-emission-du-mardi-9-mai-2017.html',
259 'only_matching': True,
260 }, {
261 # france4
262 'url': 'https://www.france.tv/france-4/hero-corp/saison-1/134151-apres-le-calme.html',
263 'only_matching': True,
264 }, {
265 # france5
266 'url': 'https://www.france.tv/france-5/c-a-dire/saison-10/137013-c-a-dire.html',
267 'only_matching': True,
268 }, {
269 # franceo
270 'url': 'https://www.france.tv/france-o/archipels/132249-mon-ancetre-l-esclave.html',
271 'only_matching': True,
272 }, {
273 # france2 live
274 'url': 'https://www.france.tv/france-2/direct.html',
275 'only_matching': True,
276 }, {
277 'url': 'https://www.france.tv/documentaires/histoire/136517-argentine-les-500-bebes-voles-de-la-dictature.html',
278 'only_matching': True,
279 }, {
280 'url': 'https://www.france.tv/jeux-et-divertissements/divertissements/133965-le-web-contre-attaque.html',
281 'only_matching': True,
12f01118
S
282 }, {
283 'url': 'https://mobile.france.tv/france-5/c-dans-l-air/137347-emission-du-vendredi-12-mai-2017.html',
284 'only_matching': True,
4489d418
S
285 }, {
286 'url': 'https://www.france.tv/142749-rouge-sang.html',
287 'only_matching': True,
49702e36
S
288 }, {
289 # france-3 live
290 'url': 'https://www.france.tv/france-3/direct.html',
291 'only_matching': True,
6d1ded75 292 }]
5d8afe69
PR
293
294 def _real_extract(self, url):
0a192fbe
S
295 display_id = self._match_id(url)
296
297 webpage = self._download_webpage(url, display_id)
298
6d1ded75
S
299 catalogue = None
300 video_id = self._search_regex(
9d74ea6d 301 r'(?:data-main-video\s*=|videoId["\']?\s*[:=])\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
6d1ded75
S
302 webpage, 'video id', default=None, group='id')
303
0a192fbe 304 if not video_id:
6d1ded75
S
305 video_id, catalogue = self._html_search_regex(
306 r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@]+@[^"]+)"',
307 webpage, 'video ID').split('@')
99892e99
S
308
309 return self._make_url_result(video_id, catalogue)
6d1ded75
S
310
311
312class FranceTVEmbedIE(FranceTVBaseInfoExtractor):
313 _VALID_URL = r'https?://embed\.francetv\.fr/*\?.*?\bue=(?P<id>[^&]+)'
314
99892e99 315 _TESTS = [{
6d1ded75
S
316 'url': 'http://embed.francetv.fr/?ue=7fd581a2ccf59d2fc5719c5c13cf6961',
317 'info_dict': {
318 'id': 'NI_983319',
319 'ext': 'mp4',
320 'title': 'Le Pen Reims',
321 'upload_date': '20170505',
322 'timestamp': 1493981780,
323 'duration': 16,
324 },
99892e99
S
325 'params': {
326 'skip_download': True,
327 },
328 'add_ie': [FranceTVIE.ie_key()],
329 }]
0a192fbe 330
6d1ded75
S
331 def _real_extract(self, url):
332 video_id = self._match_id(url)
333
334 video = self._download_json(
335 'http://api-embed.webservices.francetelevisions.fr/key/%s' % video_id,
336 video_id)
5d8afe69 337
99892e99 338 return self._make_url_result(video['video_id'], video.get('catalog'))
5d8afe69 339
6d1ded75
S
340
341class FranceTVInfoIE(FranceTVBaseInfoExtractor):
3c1b4669 342 IE_NAME = 'francetvinfo.fr'
99892e99 343 _VALID_URL = r'https?://(?:www|mobile|france3-regions)\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&.]+)'
5d8afe69 344
5c30b268 345 _TESTS = [{
13c30d1d 346 'url': 'https://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-jeudi-22-aout-2019_3561461.html',
3c1b4669 347 'info_dict': {
13c30d1d 348 'id': 'd12458ee-5062-48fe-bfdd-a30d6a01b793',
3c20208e 349 'ext': 'mp4',
3c1b4669 350 'title': 'Soir 3',
13c30d1d
S
351 'upload_date': '20190822',
352 'timestamp': 1566510900,
353 'description': 'md5:72d167097237701d6e8452ff03b83c00',
c137cc0d
S
354 'subtitles': {
355 'fr': 'mincount:2',
356 },
648d25d4 357 },
3c20208e 358 'params': {
3c20208e
S
359 'skip_download': True,
360 },
99892e99 361 'add_ie': [FranceTVIE.ie_key()],
bbed5763 362 }, {
363 'note': 'Only an image exists in initial webpage instead of the video',
364 'url': 'https://www.francetvinfo.fr/sante/maladie/coronavirus/covid-19-en-inde-une-situation-catastrophique-a-new-dehli_4381095.html',
365 'info_dict': {
366 'id': '7d204c9e-a2d3-11eb-9e4c-000d3a23d482',
367 'ext': 'mp4',
368 'title': 'Covid-19 : une situation catastrophique à New Dehli',
369 'thumbnail': str,
370 'duration': 76,
371 'timestamp': 1619028518,
372 'upload_date': '20210421',
373 },
374 'params': {
375 'skip_download': True,
376 },
377 'add_ie': [FranceTVIE.ie_key()],
5c30b268
PH
378 }, {
379 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
99892e99 380 'only_matching': True,
6f96e308
YCH
381 }, {
382 'url': 'http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html',
99892e99 383 'only_matching': True,
db264e3c
S
384 }, {
385 'url': 'http://france3-regions.francetvinfo.fr/bretagne/cotes-d-armor/thalassa-echappee-breizh-ce-venredi-dans-les-cotes-d-armor-954961.html',
99892e99 386 'only_matching': True,
ad213a1d
YCH
387 }, {
388 # Dailymotion embed
389 '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',
390 'md5': 'ee7f1828f25a648addc90cb2687b1f12',
391 'info_dict': {
392 'id': 'x4iiko0',
393 'ext': 'mp4',
394 'title': 'NDDL, référendum, Brexit : Cécile Duflot répond à Patrick Cohen',
395 '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',
396 'timestamp': 1467011958,
397 'upload_date': '20160627',
398 'uploader': 'France Inter',
399 'uploader_id': 'x2q2ez',
400 },
401 'add_ie': ['Dailymotion'],
30b25d38
S
402 }, {
403 'url': 'http://france3-regions.francetvinfo.fr/limousin/emissions/jt-1213-limousin',
404 'only_matching': True,
41d1cca3 405 }, {
406 # "<figure id=" pattern (#28792)
407 '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',
408 'only_matching': True,
5c30b268 409 }]
648d25d4
JMF
410
411 def _real_extract(self, url):
99892e99
S
412 display_id = self._match_id(url)
413
414 webpage = self._download_webpage(url, display_id)
6f96e308 415
ad213a1d
YCH
416 dailymotion_urls = DailymotionIE._extract_urls(webpage)
417 if dailymotion_urls:
418 return self.playlist_result([
419 self.url_result(dailymotion_url, DailymotionIE.ie_key())
420 for dailymotion_url in dailymotion_urls])
6f96e308 421
876fed6b 422 video_id = self._search_regex(
423 (r'player\.load[^;]+src:\s*["\']([^"\']+)',
424 r'id-video=([^@]+@[^"]+)',
13c30d1d 425 r'<a[^>]+href="(?:https?:)?//videos\.francetv\.fr/video/([^@]+@[^"]+)"',
41d1cca3 426 r'(?:data-id|<figure[^<]+\bid)=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'),
876fed6b 427 webpage, 'video id')
99892e99 428
876fed6b 429 return self._make_url_result(video_id)
a825f330
JMF
430
431
3a8e3730
RA
432class FranceTVInfoSportIE(FranceTVBaseInfoExtractor):
433 IE_NAME = 'sport.francetvinfo.fr'
434 _VALID_URL = r'https?://sport\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&]+)'
435 _TESTS = [{
436 'url': 'https://sport.francetvinfo.fr/les-jeux-olympiques/retour-sur-les-meilleurs-moments-de-pyeongchang-2018',
437 'info_dict': {
438 'id': '6e49080e-3f45-11e8-b459-000d3a2439ea',
439 'ext': 'mp4',
440 'title': 'Retour sur les meilleurs moments de Pyeongchang 2018',
441 'timestamp': 1523639962,
442 'upload_date': '20180413',
443 },
444 'params': {
445 'skip_download': True,
446 },
447 'add_ie': [FranceTVIE.ie_key()],
448 }]
449
450 def _real_extract(self, url):
451 display_id = self._match_id(url)
452 webpage = self._download_webpage(url, display_id)
453 video_id = self._search_regex(r'data-video="([^"]+)"', webpage, 'video_id')
454 return self._make_url_result(video_id, 'Sport-web')
455
456
6f5c598a
RA
457class GenerationWhatIE(InfoExtractor):
458 IE_NAME = 'france2.fr:generation-what'
99892e99 459 _VALID_URL = r'https?://generation-what\.francetv\.fr/[^/]+/video/(?P<id>[^/?#&]+)'
5b333c1c 460
6f5c598a
RA
461 _TESTS = [{
462 'url': 'http://generation-what.francetv.fr/portrait/video/present-arms',
3c1b4669 463 'info_dict': {
6f5c598a 464 'id': 'wtvKYUG45iw',
c4e817ce 465 'ext': 'mp4',
6f5c598a
RA
466 'title': 'Generation What - Garde à vous - FRA',
467 'uploader': 'Generation What',
468 'uploader_id': 'UCHH9p1eetWCgt4kXBYCb3_w',
469 'upload_date': '20160411',
5b333c1c 470 },
99892e99
S
471 'params': {
472 'skip_download': True,
473 },
474 'add_ie': ['Youtube'],
6f5c598a
RA
475 }, {
476 'url': 'http://generation-what.francetv.fr/europe/video/present-arms',
477 'only_matching': True,
478 }]
5b333c1c
JMF
479
480 def _real_extract(self, url):
c4e817ce 481 display_id = self._match_id(url)
99892e99 482
6f5c598a 483 webpage = self._download_webpage(url, display_id)
99892e99 484
6f5c598a
RA
485 youtube_id = self._search_regex(
486 r"window\.videoURL\s*=\s*'([0-9A-Za-z_-]{11})';",
487 webpage, 'youtube id')
99892e99
S
488
489 return self.url_result(youtube_id, ie='Youtube', video_id=youtube_id)
469ec941
JMF
490
491
492class CultureboxIE(FranceTVBaseInfoExtractor):
99892e99 493 _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?:[^/]+/)*(?P<id>[^/?#&]+)'
469ec941 494
99892e99
S
495 _TESTS = [{
496 'url': 'https://culturebox.francetvinfo.fr/opera-classique/musique-classique/c-est-baroque/concerts/cantates-bwv-4-106-et-131-de-bach-par-raphael-pichon-57-268689',
3c1b4669 497 'info_dict': {
99892e99
S
498 'id': 'EV_134885',
499 'ext': 'mp4',
500 'title': 'Cantates BWV 4, 106 et 131 de Bach par Raphaël Pichon 5/7',
501 'description': 'md5:19c44af004b88219f4daa50fa9a351d4',
502 'upload_date': '20180206',
503 'timestamp': 1517945220,
504 'duration': 5981,
aed2d4b3 505 },
99892e99
S
506 'params': {
507 'skip_download': True,
508 },
509 'add_ie': [FranceTVIE.ie_key()],
510 }]
469ec941
JMF
511
512 def _real_extract(self, url):
99892e99 513 display_id = self._match_id(url)
184a1974 514
99892e99 515 webpage = self._download_webpage(url, display_id)
184a1974
S
516
517 if ">Ce live n'est plus disponible en replay<" in webpage:
99892e99
S
518 raise ExtractorError(
519 'Video %s is not available' % display_id, expected=True)
184a1974 520
64892c0b 521 video_id, catalogue = self._search_regex(
c38970ca
S
522 r'["\'>]https?://videos\.francetv\.fr/video/([^@]+@.+?)["\'<]',
523 webpage, 'video id').split('@')
64892c0b 524
99892e99 525 return self._make_url_result(video_id, catalogue)
79080573
S
526
527
528class FranceTVJeunesseIE(FranceTVBaseInfoExtractor):
529 _VALID_URL = r'(?P<url>https?://(?:www\.)?(?:zouzous|ludo)\.fr/heros/(?P<id>[^/?#&]+))'
530
531 _TESTS = [{
532 'url': 'https://www.zouzous.fr/heros/simon',
533 'info_dict': {
534 'id': 'simon',
535 },
536 'playlist_count': 9,
537 }, {
538 'url': 'https://www.ludo.fr/heros/ninjago',
539 'info_dict': {
540 'id': 'ninjago',
541 },
542 'playlist_count': 10,
543 }, {
544 'url': 'https://www.zouzous.fr/heros/simon?abc',
545 'only_matching': True,
546 }]
547
548 def _real_extract(self, url):
549 mobj = re.match(self._VALID_URL, url)
550 playlist_id = mobj.group('id')
551
552 playlist = self._download_json(
553 '%s/%s' % (mobj.group('url'), 'playlist'), playlist_id)
554
555 if not playlist.get('count'):
556 raise ExtractorError(
557 '%s is not available' % playlist_id, expected=True)
558
559 entries = []
560 for item in playlist['items']:
561 identity = item.get('identity')
562 if identity and isinstance(identity, compat_str):
563 entries.append(self._make_url_result(identity))
564
565 return self.playlist_result(entries, playlist_id)