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