]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rai.py
[cleanup,youtube] Reorganize Tab and Search extractor inheritances
[yt-dlp.git] / yt_dlp / extractor / rai.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_str,
9 compat_urlparse,
10 )
11 from ..utils import (
12 determine_ext,
13 ExtractorError,
14 find_xpath_attr,
15 fix_xml_ampersands,
16 GeoRestrictedError,
17 get_element_by_class,
18 HEADRequest,
19 int_or_none,
20 parse_duration,
21 parse_list,
22 remove_start,
23 strip_or_none,
24 try_get,
25 unescapeHTML,
26 unified_strdate,
27 unified_timestamp,
28 update_url_query,
29 urljoin,
30 xpath_text,
31 )
32
33
34 class RaiBaseIE(InfoExtractor):
35 _UUID_RE = r'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
36 _GEO_COUNTRIES = ['IT']
37 _GEO_BYPASS = False
38
39 def _extract_relinker_info(self, relinker_url, video_id):
40 if not re.match(r'https?://', relinker_url):
41 return {'formats': [{'url': relinker_url}]}
42
43 formats = []
44 geoprotection = None
45 is_live = None
46 duration = None
47
48 for platform in ('mon', 'flash', 'native'):
49 relinker = self._download_xml(
50 relinker_url, video_id,
51 note='Downloading XML metadata for platform %s' % platform,
52 transform_source=fix_xml_ampersands,
53 query={'output': 45, 'pl': platform},
54 headers=self.geo_verification_headers())
55
56 if not geoprotection:
57 geoprotection = xpath_text(
58 relinker, './geoprotection', default=None) == 'Y'
59
60 if not is_live:
61 is_live = xpath_text(
62 relinker, './is_live', default=None) == 'Y'
63 if not duration:
64 duration = parse_duration(xpath_text(
65 relinker, './duration', default=None))
66
67 url_elem = find_xpath_attr(relinker, './url', 'type', 'content')
68 if url_elem is None:
69 continue
70
71 media_url = url_elem.text
72
73 # This does not imply geo restriction (e.g.
74 # http://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html)
75 if '/video_no_available.mp4' in media_url:
76 continue
77
78 ext = determine_ext(media_url)
79 if (ext == 'm3u8' and platform != 'mon') or (ext == 'f4m' and platform != 'flash'):
80 continue
81
82 if ext == 'm3u8' or 'format=m3u8' in media_url or platform == 'mon':
83 formats.extend(self._extract_m3u8_formats(
84 media_url, video_id, 'mp4', 'm3u8_native',
85 m3u8_id='hls', fatal=False))
86 elif ext == 'f4m' or platform == 'flash':
87 manifest_url = update_url_query(
88 media_url.replace('manifest#live_hds.f4m', 'manifest.f4m'),
89 {'hdcore': '3.7.0', 'plugin': 'aasp-3.7.0.39.44'})
90 formats.extend(self._extract_f4m_formats(
91 manifest_url, video_id, f4m_id='hds', fatal=False))
92 else:
93 bitrate = int_or_none(xpath_text(relinker, 'bitrate'))
94 formats.append({
95 'url': media_url,
96 'tbr': bitrate if bitrate > 0 else None,
97 'format_id': 'http-%d' % bitrate if bitrate > 0 else 'http',
98 })
99
100 if not formats and geoprotection is True:
101 self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True)
102
103 formats.extend(self._create_http_urls(relinker_url, formats))
104
105 return dict((k, v) for k, v in {
106 'is_live': is_live,
107 'duration': duration,
108 'formats': formats,
109 }.items() if v is not None)
110
111 def _create_http_urls(self, relinker_url, fmts):
112 _RELINKER_REG = r'https?://(?P<host>[^/]+?)/(?:i/)?(?P<extra>[^/]+?)/(?P<path>.+?)/(?P<id>\d+)(?:_(?P<quality>[\d\,]+))?(?:\.mp4|/playlist\.m3u8).+?'
113 _MP4_TMPL = '%s&overrideUserAgentRule=mp4-%s'
114 _QUALITY = {
115 # tbr: w, h
116 '250': [352, 198],
117 '400': [512, 288],
118 '700': [512, 288],
119 '800': [700, 394],
120 '1200': [736, 414],
121 '1800': [1024, 576],
122 '2400': [1280, 720],
123 '3200': [1440, 810],
124 '3600': [1440, 810],
125 '5000': [1920, 1080],
126 '10000': [1920, 1080],
127 }
128
129 def test_url(url):
130 resp = self._request_webpage(
131 HEADRequest(url), None, headers={'User-Agent': 'Rai'},
132 fatal=False, errnote=False, note=False)
133
134 if resp is False:
135 return False
136
137 if resp.code == 200:
138 return False if resp.url == url else resp.url
139 return None
140
141 def get_format_info(tbr):
142 import math
143 br = int_or_none(tbr)
144 if len(fmts) == 1 and not br:
145 br = fmts[0].get('tbr')
146 if br > 300:
147 tbr = compat_str(math.floor(br / 100) * 100)
148 else:
149 tbr = '250'
150
151 # try extracting info from available m3u8 formats
152 format_copy = None
153 for f in fmts:
154 if f.get('tbr'):
155 br_limit = math.floor(br / 100)
156 if br_limit - 1 <= math.floor(f['tbr'] / 100) <= br_limit + 1:
157 format_copy = f.copy()
158 return {
159 'width': format_copy.get('width'),
160 'height': format_copy.get('height'),
161 'tbr': format_copy.get('tbr'),
162 'vcodec': format_copy.get('vcodec'),
163 'acodec': format_copy.get('acodec'),
164 'fps': format_copy.get('fps'),
165 'format_id': 'https-%s' % tbr,
166 } if format_copy else {
167 'width': _QUALITY[tbr][0],
168 'height': _QUALITY[tbr][1],
169 'format_id': 'https-%s' % tbr,
170 'tbr': int(tbr),
171 }
172
173 loc = test_url(_MP4_TMPL % (relinker_url, '*'))
174 if not isinstance(loc, compat_str):
175 return []
176
177 mobj = re.match(
178 _RELINKER_REG,
179 test_url(relinker_url) or '')
180 if not mobj:
181 return []
182
183 available_qualities = mobj.group('quality').split(',') if mobj.group('quality') else ['*']
184 available_qualities = [i for i in available_qualities if i]
185
186 formats = []
187 for q in available_qualities:
188 fmt = {
189 'url': _MP4_TMPL % (relinker_url, q),
190 'protocol': 'https',
191 'ext': 'mp4',
192 }
193 fmt.update(get_format_info(q))
194 formats.append(fmt)
195 return formats
196
197 @staticmethod
198 def _extract_subtitles(url, video_data):
199 STL_EXT = 'stl'
200 SRT_EXT = 'srt'
201 subtitles = {}
202 subtitles_array = video_data.get('subtitlesArray') or []
203 for k in ('subtitles', 'subtitlesUrl'):
204 subtitles_array.append({'url': video_data.get(k)})
205 for subtitle in subtitles_array:
206 sub_url = subtitle.get('url')
207 if sub_url and isinstance(sub_url, compat_str):
208 sub_lang = subtitle.get('language') or 'it'
209 sub_url = urljoin(url, sub_url)
210 sub_ext = determine_ext(sub_url, SRT_EXT)
211 subtitles.setdefault(sub_lang, []).append({
212 'ext': sub_ext,
213 'url': sub_url,
214 })
215 if STL_EXT == sub_ext:
216 subtitles[sub_lang].append({
217 'ext': SRT_EXT,
218 'url': sub_url[:-len(STL_EXT)] + SRT_EXT,
219 })
220 return subtitles
221
222
223 class RaiPlayIE(RaiBaseIE):
224 _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>%s))\.(?:html|json)' % RaiBaseIE._UUID_RE
225 _TESTS = [{
226 'url': 'http://www.raiplay.it/video/2014/04/Report-del-07042014-cb27157f-9dd0-4aee-b788-b1f67643a391.html',
227 'md5': '8970abf8caf8aef4696e7b1f2adfc696',
228 'info_dict': {
229 'id': 'cb27157f-9dd0-4aee-b788-b1f67643a391',
230 'ext': 'mp4',
231 'title': 'Report del 07/04/2014',
232 'alt_title': 'St 2013/14 - Espresso nel caffè - 07/04/2014',
233 'description': 'md5:d730c168a58f4bb35600fc2f881ec04e',
234 'thumbnail': r're:^https?://.*\.jpg$',
235 'uploader': 'Rai Gulp',
236 'duration': 6160,
237 'series': 'Report',
238 'season': '2013/14',
239 'subtitles': {
240 'it': 'count:2',
241 },
242 },
243 'params': {
244 'skip_download': True,
245 },
246 }, {
247 # 1080p direct mp4 url
248 'url': 'https://www.raiplay.it/video/2021/03/Leonardo-S1E1-b5703b02-82ee-475a-85b6-c9e4a8adf642.html',
249 'md5': '2e501e8651d72f05ffe8f5d286ad560b',
250 'info_dict': {
251 'id': 'b5703b02-82ee-475a-85b6-c9e4a8adf642',
252 'ext': 'mp4',
253 'title': 'Leonardo - S1E1',
254 'alt_title': 'St 1 Ep 1 - Episodio 1',
255 'description': 'md5:f5360cd267d2de146e4e3879a5a47d31',
256 'thumbnail': r're:^https?://.*\.jpg$',
257 'uploader': 'Rai 1',
258 'duration': 3229,
259 'series': 'Leonardo',
260 'season': 'Season 1',
261 },
262 }, {
263 'url': 'http://www.raiplay.it/video/2016/11/gazebotraindesi-efebe701-969c-4593-92f3-285f0d1ce750.html?',
264 'only_matching': True,
265 }, {
266 # subtitles at 'subtitlesArray' key (see #27698)
267 'url': 'https://www.raiplay.it/video/2020/12/Report---04-01-2021-2e90f1de-8eee-4de4-ac0e-78d21db5b600.html',
268 'only_matching': True,
269 }, {
270 # DRM protected
271 'url': 'https://www.raiplay.it/video/2020/09/Lo-straordinario-mondo-di-Zoey-S1E1-Lo-straordinario-potere-di-Zoey-ed493918-1d32-44b7-8454-862e473d00ff.html',
272 'only_matching': True,
273 }]
274
275 def _real_extract(self, url):
276 base, video_id = self._match_valid_url(url).groups()
277
278 media = self._download_json(
279 base + '.json', video_id, 'Downloading video JSON')
280
281 if not self.get_param('allow_unplayable_formats'):
282 if try_get(
283 media,
284 (lambda x: x['rights_management']['rights']['drm'],
285 lambda x: x['program_info']['rights_management']['rights']['drm']),
286 dict):
287 self.report_drm(video_id)
288
289 title = media['name']
290 video = media['video']
291
292 relinker_info = self._extract_relinker_info(video['content_url'], video_id)
293 self._sort_formats(relinker_info['formats'])
294
295 thumbnails = []
296 for _, value in media.get('images', {}).items():
297 if value:
298 thumbnails.append({
299 'url': urljoin(url, value),
300 })
301
302 date_published = media.get('date_published')
303 time_published = media.get('time_published')
304 if date_published and time_published:
305 date_published += ' ' + time_published
306
307 subtitles = self._extract_subtitles(url, video)
308
309 program_info = media.get('program_info') or {}
310 season = media.get('season')
311
312 info = {
313 'id': remove_start(media.get('id'), 'ContentItem-') or video_id,
314 'display_id': video_id,
315 'title': self._live_title(title) if relinker_info.get(
316 'is_live') else title,
317 'alt_title': strip_or_none(media.get('subtitle')),
318 'description': media.get('description'),
319 'uploader': strip_or_none(media.get('channel')),
320 'creator': strip_or_none(media.get('editor') or None),
321 'duration': parse_duration(video.get('duration')),
322 'timestamp': unified_timestamp(date_published),
323 'thumbnails': thumbnails,
324 'series': program_info.get('name'),
325 'season_number': int_or_none(season),
326 'season': season if (season and not season.isdigit()) else None,
327 'episode': media.get('episode_title'),
328 'episode_number': int_or_none(media.get('episode')),
329 'subtitles': subtitles,
330 }
331
332 info.update(relinker_info)
333 return info
334
335
336 class RaiPlayLiveIE(RaiPlayIE):
337 _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/dirette/(?P<id>[^/?#&]+))'
338 _TESTS = [{
339 'url': 'http://www.raiplay.it/dirette/rainews24',
340 'info_dict': {
341 'id': 'd784ad40-e0ae-4a69-aa76-37519d238a9c',
342 'display_id': 'rainews24',
343 'ext': 'mp4',
344 'title': 're:^Diretta di Rai News 24 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
345 'description': 'md5:4d00bcf6dc98b27c6ec480de329d1497',
346 'uploader': 'Rai News 24',
347 'creator': 'Rai News 24',
348 'is_live': True,
349 },
350 'params': {
351 'skip_download': True,
352 },
353 }]
354
355
356 class RaiPlayPlaylistIE(InfoExtractor):
357 _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/programmi/(?P<id>[^/?#&]+))'
358 _TESTS = [{
359 'url': 'http://www.raiplay.it/programmi/nondirloalmiocapo/',
360 'info_dict': {
361 'id': 'nondirloalmiocapo',
362 'title': 'Non dirlo al mio capo',
363 'description': 'md5:98ab6b98f7f44c2843fd7d6f045f153b',
364 },
365 'playlist_mincount': 12,
366 }]
367
368 def _real_extract(self, url):
369 base, playlist_id = self._match_valid_url(url).groups()
370
371 program = self._download_json(
372 base + '.json', playlist_id, 'Downloading program JSON')
373
374 entries = []
375 for b in (program.get('blocks') or []):
376 for s in (b.get('sets') or []):
377 s_id = s.get('id')
378 if not s_id:
379 continue
380 medias = self._download_json(
381 '%s/%s.json' % (base, s_id), s_id,
382 'Downloading content set JSON', fatal=False)
383 if not medias:
384 continue
385 for m in (medias.get('items') or []):
386 path_id = m.get('path_id')
387 if not path_id:
388 continue
389 video_url = urljoin(url, path_id)
390 entries.append(self.url_result(
391 video_url, ie=RaiPlayIE.ie_key(),
392 video_id=RaiPlayIE._match_id(video_url)))
393
394 return self.playlist_result(
395 entries, playlist_id, program.get('name'),
396 try_get(program, lambda x: x['program_info']['description']))
397
398
399 class RaiIE(RaiBaseIE):
400 _VALID_URL = r'https?://[^/]+\.(?:rai\.(?:it|tv)|rainews\.it)/.+?-(?P<id>%s)(?:-.+?)?\.html' % RaiBaseIE._UUID_RE
401 _TESTS = [{
402 # var uniquename = "ContentItem-..."
403 # data-id="ContentItem-..."
404 'url': 'http://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html',
405 'info_dict': {
406 'id': '04a9f4bd-b563-40cf-82a6-aad3529cb4a9',
407 'ext': 'mp4',
408 'title': 'TG PRIMO TEMPO',
409 'thumbnail': r're:^https?://.*\.jpg$',
410 'duration': 1758,
411 'upload_date': '20140612',
412 },
413 'skip': 'This content is available only in Italy',
414 }, {
415 # with ContentItem in many metas
416 'url': 'http://www.rainews.it/dl/rainews/media/Weekend-al-cinema-da-Hollywood-arriva-il-thriller-di-Tate-Taylor-La-ragazza-del-treno-1632c009-c843-4836-bb65-80c33084a64b.html',
417 'info_dict': {
418 'id': '1632c009-c843-4836-bb65-80c33084a64b',
419 'ext': 'mp4',
420 'title': 'Weekend al cinema, da Hollywood arriva il thriller di Tate Taylor "La ragazza del treno"',
421 'description': 'I film in uscita questa settimana.',
422 'thumbnail': r're:^https?://.*\.png$',
423 'duration': 833,
424 'upload_date': '20161103',
425 }
426 }, {
427 # with ContentItem in og:url
428 'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-efb17665-691c-45d5-a60c-5301333cbb0c.html',
429 'md5': '06345bd97c932f19ffb129973d07a020',
430 'info_dict': {
431 'id': 'efb17665-691c-45d5-a60c-5301333cbb0c',
432 'ext': 'mp4',
433 'title': 'TG1 ore 20:00 del 03/11/2016',
434 'description': 'TG1 edizione integrale ore 20:00 del giorno 03/11/2016',
435 'thumbnail': r're:^https?://.*\.jpg$',
436 'duration': 2214,
437 'upload_date': '20161103',
438 }
439 }, {
440 # initEdizione('ContentItem-...'
441 'url': 'http://www.tg1.rai.it/dl/tg1/2010/edizioni/ContentSet-9b6e0cba-4bef-4aef-8cf0-9f7f665b7dfb-tg1.html?item=undefined',
442 'info_dict': {
443 'id': 'c2187016-8484-4e3a-8ac8-35e475b07303',
444 'ext': 'mp4',
445 'title': r're:TG1 ore \d{2}:\d{2} del \d{2}/\d{2}/\d{4}',
446 'duration': 2274,
447 'upload_date': '20170401',
448 },
449 'skip': 'Changes daily',
450 }, {
451 # HLS live stream with ContentItem in og:url
452 'url': 'http://www.rainews.it/dl/rainews/live/ContentItem-3156f2f2-dc70-4953-8e2f-70d7489d4ce9.html',
453 'info_dict': {
454 'id': '3156f2f2-dc70-4953-8e2f-70d7489d4ce9',
455 'ext': 'mp4',
456 'title': 'La diretta di Rainews24',
457 },
458 'params': {
459 'skip_download': True,
460 },
461 }, {
462 # Direct MMS URL
463 'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-b63a4089-ac28-48cf-bca5-9f5b5bc46df5.html',
464 'only_matching': True,
465 }, {
466 'url': 'https://www.rainews.it/tgr/marche/notiziari/video/2019/02/ContentItem-6ba945a2-889c-4a80-bdeb-8489c70a8db9.html',
467 'only_matching': True,
468 }]
469
470 def _extract_from_content_id(self, content_id, url):
471 media = self._download_json(
472 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-%s.html?json' % content_id,
473 content_id, 'Downloading video JSON')
474
475 title = media['name'].strip()
476
477 media_type = media['type']
478 if 'Audio' in media_type:
479 relinker_info = {
480 'formats': [{
481 'format_id': media.get('formatoAudio'),
482 'url': media['audioUrl'],
483 'ext': media.get('formatoAudio'),
484 }]
485 }
486 elif 'Video' in media_type:
487 relinker_info = self._extract_relinker_info(media['mediaUri'], content_id)
488 else:
489 raise ExtractorError('not a media file')
490
491 self._sort_formats(relinker_info['formats'])
492
493 thumbnails = []
494 for image_type in ('image', 'image_medium', 'image_300'):
495 thumbnail_url = media.get(image_type)
496 if thumbnail_url:
497 thumbnails.append({
498 'url': compat_urlparse.urljoin(url, thumbnail_url),
499 })
500
501 subtitles = self._extract_subtitles(url, media)
502
503 info = {
504 'id': content_id,
505 'title': title,
506 'description': strip_or_none(media.get('desc')),
507 'thumbnails': thumbnails,
508 'uploader': media.get('author'),
509 'upload_date': unified_strdate(media.get('date')),
510 'duration': parse_duration(media.get('length')),
511 'subtitles': subtitles,
512 }
513
514 info.update(relinker_info)
515
516 return info
517
518 def _real_extract(self, url):
519 video_id = self._match_id(url)
520
521 webpage = self._download_webpage(url, video_id)
522
523 content_item_id = None
524
525 content_item_url = self._html_search_meta(
526 ('og:url', 'og:video', 'og:video:secure_url', 'twitter:url',
527 'twitter:player', 'jsonlink'), webpage, default=None)
528 if content_item_url:
529 content_item_id = self._search_regex(
530 r'ContentItem-(%s)' % self._UUID_RE, content_item_url,
531 'content item id', default=None)
532
533 if not content_item_id:
534 content_item_id = self._search_regex(
535 r'''(?x)
536 (?:
537 (?:initEdizione|drawMediaRaiTV)\(|
538 <(?:[^>]+\bdata-id|var\s+uniquename)=|
539 <iframe[^>]+\bsrc=
540 )
541 (["\'])
542 (?:(?!\1).)*\bContentItem-(?P<id>%s)
543 ''' % self._UUID_RE,
544 webpage, 'content item id', default=None, group='id')
545
546 content_item_ids = set()
547 if content_item_id:
548 content_item_ids.add(content_item_id)
549 if video_id not in content_item_ids:
550 content_item_ids.add(video_id)
551
552 for content_item_id in content_item_ids:
553 try:
554 return self._extract_from_content_id(content_item_id, url)
555 except GeoRestrictedError:
556 raise
557 except ExtractorError:
558 pass
559
560 relinker_url = self._proto_relative_url(self._search_regex(
561 r'''(?x)
562 (?:
563 var\s+videoURL|
564 mediaInfo\.mediaUri
565 )\s*=\s*
566 ([\'"])
567 (?P<url>
568 (?:https?:)?
569 //mediapolis(?:vod)?\.rai\.it/relinker/relinkerServlet\.htm\?
570 (?:(?!\1).)*\bcont=(?:(?!\1).)+)\1
571 ''',
572 webpage, 'relinker URL', group='url'))
573
574 relinker_info = self._extract_relinker_info(
575 urljoin(url, relinker_url), video_id)
576 self._sort_formats(relinker_info['formats'])
577
578 title = self._search_regex(
579 r'var\s+videoTitolo\s*=\s*([\'"])(?P<title>[^\'"]+)\1',
580 webpage, 'title', group='title',
581 default=None) or self._og_search_title(webpage)
582
583 info = {
584 'id': video_id,
585 'title': title,
586 }
587
588 info.update(relinker_info)
589
590 return info
591
592
593 class RaiPlayRadioBaseIE(InfoExtractor):
594 _BASE = 'https://www.raiplayradio.it'
595
596 def get_playlist_iter(self, url, uid):
597 webpage = self._download_webpage(url, uid)
598 for attrs in parse_list(webpage):
599 title = attrs['data-title'].strip()
600 audio_url = urljoin(url, attrs['data-mediapolis'])
601 entry = {
602 'url': audio_url,
603 'id': attrs['data-uniquename'].lstrip('ContentItem-'),
604 'title': title,
605 'ext': 'mp3',
606 'language': 'it',
607 }
608 if 'data-image' in attrs:
609 entry['thumbnail'] = urljoin(url, attrs['data-image'])
610 yield entry
611
612
613 class RaiPlayRadioIE(RaiPlayRadioBaseIE):
614 _VALID_URL = r'%s/audio/.+?-(?P<id>%s)\.html' % (
615 RaiPlayRadioBaseIE._BASE, RaiBaseIE._UUID_RE)
616 _TEST = {
617 'url': 'https://www.raiplayradio.it/audio/2019/07/RADIO3---LEZIONI-DI-MUSICA-36b099ff-4123-4443-9bf9-38e43ef5e025.html',
618 'info_dict': {
619 'id': '36b099ff-4123-4443-9bf9-38e43ef5e025',
620 'ext': 'mp3',
621 'title': 'Dal "Chiaro di luna" al "Clair de lune", prima parte con Giovanni Bietti',
622 'thumbnail': r're:^https?://.*\.jpg$',
623 'language': 'it',
624 }
625 }
626
627 def _real_extract(self, url):
628 audio_id = self._match_id(url)
629 list_url = url.replace('.html', '-list.html')
630 return next(entry for entry in self.get_playlist_iter(list_url, audio_id) if entry['id'] == audio_id)
631
632
633 class RaiPlayRadioPlaylistIE(RaiPlayRadioBaseIE):
634 _VALID_URL = r'%s/playlist/.+?-(?P<id>%s)\.html' % (
635 RaiPlayRadioBaseIE._BASE, RaiBaseIE._UUID_RE)
636 _TEST = {
637 'url': 'https://www.raiplayradio.it/playlist/2017/12/Alice-nel-paese-delle-meraviglie-72371d3c-d998-49f3-8860-d168cfdf4966.html',
638 'info_dict': {
639 'id': '72371d3c-d998-49f3-8860-d168cfdf4966',
640 'title': "Alice nel paese delle meraviglie",
641 'description': "di Lewis Carrol letto da Aldo Busi",
642 },
643 'playlist_count': 11,
644 }
645
646 def _real_extract(self, url):
647 playlist_id = self._match_id(url)
648 playlist_webpage = self._download_webpage(url, playlist_id)
649 playlist_title = unescapeHTML(self._html_search_regex(
650 r'data-playlist-title="(.+?)"', playlist_webpage, 'title'))
651 playlist_creator = self._html_search_meta(
652 'nomeProgramma', playlist_webpage)
653 playlist_description = get_element_by_class(
654 'textDescriptionProgramma', playlist_webpage)
655
656 player_href = self._html_search_regex(
657 r'data-player-href="(.+?)"', playlist_webpage, 'href')
658 list_url = urljoin(url, player_href)
659
660 entries = list(self.get_playlist_iter(list_url, playlist_id))
661 for index, entry in enumerate(entries, start=1):
662 entry.update({
663 'track': entry['title'],
664 'track_number': index,
665 'artist': playlist_creator,
666 'album': playlist_title
667 })
668
669 return self.playlist_result(
670 entries, playlist_id, playlist_title, playlist_description,
671 creator=playlist_creator)