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