[ie/RadioRadicale] Add extractor (#5607)
[yt-dlp3.git] / yt_dlp / extractor / radioradicale.py
blob472e25c45f7c60cedcbf08df2256e8914ac46ece
1 from .common import InfoExtractor
2 from ..utils import url_or_none
3 from ..utils.traversal import traverse_obj
6 class RadioRadicaleIE(InfoExtractor):
7 _VALID_URL = r'https?://(?:www\.)?radioradicale\.it/scheda/(?P<id>[0-9]+)'
8 _TESTS = [{
9 'url': 'https://www.radioradicale.it/scheda/471591',
10 'md5': 'eb0fbe43a601f1a361cbd00f3c45af4a',
11 'info_dict': {
12 'id': '471591',
13 'ext': 'mp4',
14 'title': 'md5:e8fbb8de57011a3255db0beca69af73d',
15 'description': 'md5:5e15a789a2fe4d67da8d1366996e89ef',
16 'location': 'Napoli',
17 'duration': 2852.0,
18 'timestamp': 1459987200,
19 'upload_date': '20160407',
20 'thumbnail': 'https://www.radioradicale.it/photo400/0/0/9/0/1/00901768.jpg',
22 }, {
23 'url': 'https://www.radioradicale.it/scheda/742783/parlamento-riunito-in-seduta-comune-11a-della-xix-legislatura',
24 'info_dict': {
25 'id': '742783',
26 'title': 'Parlamento riunito in seduta comune (11ª della XIX legislatura)',
27 'description': '-) Votazione per l\'elezione di un giudice della Corte Costituzionale (nono scrutinio)',
28 'location': 'CAMERA',
29 'duration': 5868.0,
30 'timestamp': 1730246400,
31 'upload_date': '20241030',
33 'playlist': [{
34 'md5': 'aa48de55dcc45478e4cd200f299aab7d',
35 'info_dict': {
36 'id': '742783-0',
37 'ext': 'mp4',
38 'title': 'Parlamento riunito in seduta comune (11ª della XIX legislatura)',
40 }, {
41 'md5': 'be915c189c70ad2920e5810f32260ff5',
42 'info_dict': {
43 'id': '742783-1',
44 'ext': 'mp4',
45 'title': 'Parlamento riunito in seduta comune (11ª della XIX legislatura)',
47 }, {
48 'md5': 'f0ee4047342baf8ed3128a8417ac5e0a',
49 'info_dict': {
50 'id': '742783-2',
51 'ext': 'mp4',
52 'title': 'Parlamento riunito in seduta comune (11ª della XIX legislatura)',
54 }],
57 def _entries(self, videos_info, page_id):
58 for idx, video in enumerate(traverse_obj(
59 videos_info, ('playlist', lambda _, v: v['sources']))):
60 video_id = f'{page_id}-{idx}'
61 formats = []
62 subtitles = {}
64 for m3u8_url in traverse_obj(video, ('sources', ..., 'src', {url_or_none})):
65 fmts, subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
66 formats.extend(fmts)
67 self._merge_subtitles(subs, target=subtitles)
68 for sub in traverse_obj(video, ('subtitles', ..., lambda _, v: url_or_none(v['src']))):
69 self._merge_subtitles({sub.get('srclang') or 'und': [{
70 'url': sub['src'],
71 'name': sub.get('label'),
72 }]}, target=subtitles)
74 yield {
75 'id': video_id,
76 'title': video.get('title'),
77 'formats': formats,
78 'subtitles': subtitles,
81 def _real_extract(self, url):
82 page_id = self._match_id(url)
83 webpage = self._download_webpage(url, page_id)
85 videos_info = self._search_json(
86 r'jQuery\.extend\(Drupal\.settings\s*,',
87 webpage, 'videos_info', page_id)['RRscheda']
89 entries = list(self._entries(videos_info, page_id))
91 common_info = {
92 'id': page_id,
93 'title': self._og_search_title(webpage),
94 'description': self._og_search_description(webpage),
95 'location': videos_info.get('luogo'),
96 **self._search_json_ld(webpage, page_id),
99 if len(entries) == 1:
100 return {
101 **entries[0],
102 **common_info,
105 return self.playlist_result(entries, multi_video=True, **common_info)