]>
Commit | Line | Data |
---|---|---|
e1f93a0a | 1 | from .common import InfoExtractor |
e4cf7741 | 2 | from ..utils import ( |
3 | extract_attributes, | |
4 | int_or_none, | |
5 | remove_start, | |
6 | str_or_none, | |
7 | traverse_obj, | |
8 | url_or_none, | |
9 | ) | |
e1f93a0a PZ |
10 | |
11 | ||
12 | class RozhlasIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://(?:www\.)?prehravac\.rozhlas\.cz/audio/(?P<id>[0-9]+)' | |
de02d1f4 | 14 | _TESTS = [{ |
e1f93a0a PZ |
15 | 'url': 'http://prehravac.rozhlas.cz/audio/3421320', |
16 | 'md5': '504c902dbc9e9a1fd50326eccf02a7e2', | |
17 | 'info_dict': { | |
18 | 'id': '3421320', | |
19 | 'ext': 'mp3', | |
20 | 'title': 'Echo Pavla Klusáka (30.06.2015 21:00)', | |
21 | 'description': 'Osmdesátiny Terryho Rileyho jsou skvělou příležitostí proletět se elektronickými i akustickými díly zakladatatele minimalismu, který je aktivní už přes padesát let' | |
22 | } | |
de02d1f4 S |
23 | }, { |
24 | 'url': 'http://prehravac.rozhlas.cz/audio/3421320/embed', | |
7512aa98 | 25 | 'only_matching': True, |
de02d1f4 | 26 | }] |
e1f93a0a PZ |
27 | |
28 | def _real_extract(self, url): | |
29 | audio_id = self._match_id(url) | |
e1f93a0a | 30 | |
de02d1f4 S |
31 | webpage = self._download_webpage( |
32 | 'http://prehravac.rozhlas.cz/audio/%s' % audio_id, audio_id) | |
e1f93a0a | 33 | |
de02d1f4 S |
34 | title = self._html_search_regex( |
35 | r'<h3>(.+?)</h3>\s*<p[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track', | |
36 | webpage, 'title', default=None) or remove_start( | |
37 | self._og_search_title(webpage), 'Radio Wave - ') | |
38 | description = self._html_search_regex( | |
39 | r'<p[^>]+title=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track', | |
40 | webpage, 'description', fatal=False, group='url') | |
41 | duration = int_or_none(self._search_regex( | |
42 | r'data-duration=["\'](\d+)', webpage, 'duration', default=None)) | |
e1f93a0a PZ |
43 | |
44 | return { | |
45 | 'id': audio_id, | |
de02d1f4 | 46 | 'url': 'http://media.rozhlas.cz/_audio/%s.mp3' % audio_id, |
e1f93a0a PZ |
47 | 'title': title, |
48 | 'description': description, | |
de02d1f4 S |
49 | 'duration': duration, |
50 | 'vcodec': 'none', | |
e1f93a0a | 51 | } |
355d781b MH |
52 | |
53 | ||
54 | class RozhlasVltavaIE(InfoExtractor): | |
55 | _VALID_URL = r'https?://(?:\w+\.rozhlas|english\.radio)\.cz/[\w-]+-(?P<id>\d+)' | |
56 | _TESTS = [{ | |
57 | 'url': 'https://wave.rozhlas.cz/papej-masicko-porcujeme-a-bilancujeme-filmy-a-serialy-ktere-letos-zabily-8891337', | |
58 | 'md5': 'ba2fdbc1242fc16771c7695d271ec355', | |
59 | 'info_dict': { | |
e4cf7741 | 60 | 'id': '8891337', |
355d781b MH |
61 | 'title': 'md5:21f99739d04ab49d8c189ec711eef4ec', |
62 | }, | |
63 | 'playlist_count': 1, | |
64 | 'playlist': [{ | |
65 | 'md5': 'ba2fdbc1242fc16771c7695d271ec355', | |
66 | 'info_dict': { | |
67 | 'id': '10520988', | |
68 | 'ext': 'mp3', | |
69 | 'title': 'Papej masíčko! Porcujeme a bilancujeme filmy a seriály, které to letos zabily', | |
70 | 'description': 'md5:1c6d29fb9564e1f17fc1bb83ae7da0bc', | |
71 | 'duration': 1574, | |
72 | 'artist': 'Aleš Stuchlý', | |
73 | 'channel_id': 'radio-wave', | |
74 | }, | |
75 | }] | |
76 | }, { | |
77 | 'url': 'https://wave.rozhlas.cz/poslechnete-si-neklid-podcastovy-thriller-o-vine-strachu-a-vztahu-ktery-zasel-8554744', | |
78 | 'info_dict': { | |
e4cf7741 | 79 | 'id': '8554744', |
355d781b MH |
80 | 'title': 'Poslechněte si Neklid. Podcastový thriller o vině, strachu a vztahu, který zašel příliš daleko', |
81 | }, | |
82 | 'playlist_count': 5, | |
83 | 'playlist': [{ | |
84 | 'md5': '93d4109cf8f40523699ae9c1d4600bdd', | |
85 | 'info_dict': { | |
86 | 'id': '9890713', | |
87 | 'ext': 'mp3', | |
88 | 'title': 'Neklid #1', | |
89 | 'description': '1. díl: Neklid: 1. díl', | |
90 | 'duration': 1025, | |
91 | 'artist': 'Josef Kokta', | |
92 | 'channel_id': 'radio-wave', | |
93 | 'chapter': 'Neklid #1', | |
94 | 'chapter_number': 1, | |
95 | }, | |
96 | }, { | |
97 | 'md5': 'e9763235be4a6dcf94bc8a5bac1ca126', | |
98 | 'info_dict': { | |
99 | 'id': '9890716', | |
100 | 'ext': 'mp3', | |
101 | 'title': 'Neklid #2', | |
102 | 'description': '2. díl: Neklid: 2. díl', | |
103 | 'duration': 768, | |
104 | 'artist': 'Josef Kokta', | |
105 | 'channel_id': 'radio-wave', | |
106 | 'chapter': 'Neklid #2', | |
107 | 'chapter_number': 2, | |
108 | }, | |
109 | }, { | |
110 | 'md5': '00b642ea94b78cc949ac84da09f87895', | |
111 | 'info_dict': { | |
112 | 'id': '9890722', | |
113 | 'ext': 'mp3', | |
114 | 'title': 'Neklid #3', | |
115 | 'description': '3. díl: Neklid: 3. díl', | |
116 | 'duration': 607, | |
117 | 'artist': 'Josef Kokta', | |
118 | 'channel_id': 'radio-wave', | |
119 | 'chapter': 'Neklid #3', | |
120 | 'chapter_number': 3, | |
121 | }, | |
122 | }, { | |
123 | 'md5': 'faef97b1b49da7df874740f118c19dea', | |
124 | 'info_dict': { | |
125 | 'id': '9890728', | |
126 | 'ext': 'mp3', | |
127 | 'title': 'Neklid #4', | |
128 | 'description': '4. díl: Neklid: 4. díl', | |
129 | 'duration': 621, | |
130 | 'artist': 'Josef Kokta', | |
131 | 'channel_id': 'radio-wave', | |
132 | 'chapter': 'Neklid #4', | |
133 | 'chapter_number': 4, | |
134 | }, | |
135 | }, { | |
136 | 'md5': '6e729fa39b647325b868d419c76f3efa', | |
137 | 'info_dict': { | |
138 | 'id': '9890734', | |
139 | 'ext': 'mp3', | |
140 | 'title': 'Neklid #5', | |
141 | 'description': '5. díl: Neklid: 5. díl', | |
142 | 'duration': 908, | |
143 | 'artist': 'Josef Kokta', | |
144 | 'channel_id': 'radio-wave', | |
145 | 'chapter': 'Neklid #5', | |
146 | 'chapter_number': 5, | |
147 | }, | |
148 | }] | |
e4cf7741 | 149 | }, { |
150 | 'url': 'https://dvojka.rozhlas.cz/karel-siktanc-cerny-jezdec-bily-kun-napinava-pohadka-o-tajemnem-prizraku-8946969', | |
151 | 'info_dict': { | |
152 | 'id': '8946969', | |
153 | 'title': 'Karel Šiktanc: Černý jezdec, bílý kůň. Napínavá pohádka o tajemném přízraku', | |
154 | }, | |
155 | 'playlist_count': 1, | |
156 | 'playlist': [{ | |
157 | 'info_dict': { | |
158 | 'id': '10631121', | |
159 | 'ext': 'm4a', | |
160 | 'title': 'Karel Šiktanc: Černý jezdec, bílý kůň. Napínavá pohádka o tajemném přízraku', | |
161 | 'description': 'Karel Šiktanc: Černý jezdec, bílý kůň', | |
162 | 'duration': 2656, | |
163 | 'artist': 'Tvůrčí skupina Drama a literatura', | |
164 | 'channel_id': 'dvojka', | |
165 | }, | |
166 | }], | |
167 | 'params': {'skip_download': 'dash'}, | |
355d781b MH |
168 | }] |
169 | ||
170 | def _extract_video(self, entry): | |
e4cf7741 | 171 | formats = [] |
172 | audio_id = entry['meta']['ga']['contentId'] | |
173 | for audio in traverse_obj(entry, ('audioLinks', lambda _, v: url_or_none(v['url']))): | |
174 | ext = audio.get('variant') | |
175 | if ext == 'dash': | |
176 | formats.extend(self._extract_mpd_formats( | |
177 | audio['url'], audio_id, mpd_id=ext, fatal=False)) | |
178 | elif ext == 'hls': | |
179 | formats.extend(self._extract_m3u8_formats( | |
180 | audio['url'], audio_id, 'm4a', m3u8_id=ext, fatal=False)) | |
181 | else: | |
182 | formats.append({ | |
183 | 'url': audio['url'], | |
184 | 'ext': ext, | |
185 | 'format_id': ext, | |
186 | 'abr': int_or_none(audio.get('bitrate')), | |
187 | 'acodec': ext, | |
188 | 'vcodec': 'none', | |
189 | }) | |
190 | ||
191 | chapter_number = traverse_obj(entry, ('meta', 'ga', 'contentSerialPart', {int_or_none})) | |
192 | ||
355d781b | 193 | return { |
e4cf7741 | 194 | 'id': audio_id, |
355d781b MH |
195 | 'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')) if chapter_number else None, |
196 | 'chapter_number': chapter_number, | |
e4cf7741 | 197 | 'formats': formats, |
198 | **traverse_obj(entry, { | |
199 | 'title': ('meta', 'ga', 'contentName'), | |
200 | 'description': 'title', | |
201 | 'duration': ('duration', {int_or_none}), | |
202 | 'artist': ('meta', 'ga', 'contentAuthor'), | |
203 | 'channel_id': ('meta', 'ga', 'contentCreator'), | |
204 | }) | |
355d781b MH |
205 | } |
206 | ||
207 | def _real_extract(self, url): | |
208 | video_id = self._match_id(url) | |
209 | webpage = self._download_webpage(url, video_id) | |
210 | ||
211 | # FIXME: Use get_element_text_and_html_by_tag when it accepts less strict html | |
212 | data = self._parse_json(extract_attributes(self._search_regex( | |
213 | r'(<div class="mujRozhlasPlayer" data-player=\'[^\']+\'>)', | |
214 | webpage, 'player'))['data-player'], video_id)['data'] | |
215 | ||
216 | return { | |
217 | '_type': 'playlist', | |
e4cf7741 | 218 | 'id': str_or_none(data.get('embedId')) or video_id, |
355d781b MH |
219 | 'title': traverse_obj(data, ('series', 'title')), |
220 | 'entries': map(self._extract_video, data['playlist']), | |
221 | } |