]>
Commit | Line | Data |
---|---|---|
c2b801fe | 1 | import itertools |
c2b801fe | 2 | |
e1f93a0a | 3 | from .common import InfoExtractor |
3d2623a8 | 4 | from ..networking.exceptions import HTTPError |
e4cf7741 | 5 | from ..utils import ( |
c2b801fe | 6 | ExtractorError, |
e4cf7741 | 7 | extract_attributes, |
8 | int_or_none, | |
9 | remove_start, | |
10 | str_or_none, | |
11 | traverse_obj, | |
c2b801fe | 12 | unified_timestamp, |
e4cf7741 | 13 | url_or_none, |
14 | ) | |
e1f93a0a PZ |
15 | |
16 | ||
17 | class RozhlasIE(InfoExtractor): | |
18 | _VALID_URL = r'https?://(?:www\.)?prehravac\.rozhlas\.cz/audio/(?P<id>[0-9]+)' | |
de02d1f4 | 19 | _TESTS = [{ |
e1f93a0a PZ |
20 | 'url': 'http://prehravac.rozhlas.cz/audio/3421320', |
21 | 'md5': '504c902dbc9e9a1fd50326eccf02a7e2', | |
22 | 'info_dict': { | |
23 | 'id': '3421320', | |
24 | 'ext': 'mp3', | |
25 | 'title': 'Echo Pavla Klusáka (30.06.2015 21:00)', | |
26 | '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' | |
27 | } | |
de02d1f4 S |
28 | }, { |
29 | 'url': 'http://prehravac.rozhlas.cz/audio/3421320/embed', | |
7512aa98 | 30 | 'only_matching': True, |
de02d1f4 | 31 | }] |
e1f93a0a PZ |
32 | |
33 | def _real_extract(self, url): | |
34 | audio_id = self._match_id(url) | |
e1f93a0a | 35 | |
de02d1f4 S |
36 | webpage = self._download_webpage( |
37 | 'http://prehravac.rozhlas.cz/audio/%s' % audio_id, audio_id) | |
e1f93a0a | 38 | |
de02d1f4 S |
39 | title = self._html_search_regex( |
40 | r'<h3>(.+?)</h3>\s*<p[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track', | |
41 | webpage, 'title', default=None) or remove_start( | |
42 | self._og_search_title(webpage), 'Radio Wave - ') | |
43 | description = self._html_search_regex( | |
44 | r'<p[^>]+title=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>.*?</p>\s*<div[^>]+id=["\']player-track', | |
45 | webpage, 'description', fatal=False, group='url') | |
46 | duration = int_or_none(self._search_regex( | |
47 | r'data-duration=["\'](\d+)', webpage, 'duration', default=None)) | |
e1f93a0a PZ |
48 | |
49 | return { | |
50 | 'id': audio_id, | |
de02d1f4 | 51 | 'url': 'http://media.rozhlas.cz/_audio/%s.mp3' % audio_id, |
e1f93a0a PZ |
52 | 'title': title, |
53 | 'description': description, | |
de02d1f4 S |
54 | 'duration': duration, |
55 | 'vcodec': 'none', | |
e1f93a0a | 56 | } |
355d781b MH |
57 | |
58 | ||
c2b801fe | 59 | class RozhlasBaseIE(InfoExtractor): |
60 | def _extract_formats(self, entry, audio_id): | |
61 | formats = [] | |
62 | for audio in traverse_obj(entry, ('audioLinks', lambda _, v: url_or_none(v['url']))): | |
63 | ext = audio.get('variant') | |
64 | for retry in self.RetryManager(): | |
65 | if retry.attempt > 1: | |
66 | self._sleep(1, audio_id) | |
67 | try: | |
68 | if ext == 'dash': | |
69 | formats.extend(self._extract_mpd_formats( | |
70 | audio['url'], audio_id, mpd_id=ext)) | |
71 | elif ext == 'hls': | |
72 | formats.extend(self._extract_m3u8_formats( | |
73 | audio['url'], audio_id, 'm4a', m3u8_id=ext)) | |
74 | else: | |
75 | formats.append({ | |
76 | 'url': audio['url'], | |
77 | 'ext': ext, | |
78 | 'format_id': ext, | |
79 | 'abr': int_or_none(audio.get('bitrate')), | |
80 | 'acodec': ext, | |
81 | 'vcodec': 'none', | |
82 | }) | |
83 | except ExtractorError as e: | |
3d2623a8 | 84 | if isinstance(e.cause, HTTPError) and e.cause.status == 429: |
c2b801fe | 85 | retry.error = e.cause |
86 | else: | |
87 | self.report_warning(e.msg) | |
88 | ||
89 | return formats | |
90 | ||
91 | ||
92 | class RozhlasVltavaIE(RozhlasBaseIE): | |
355d781b MH |
93 | _VALID_URL = r'https?://(?:\w+\.rozhlas|english\.radio)\.cz/[\w-]+-(?P<id>\d+)' |
94 | _TESTS = [{ | |
95 | 'url': 'https://wave.rozhlas.cz/papej-masicko-porcujeme-a-bilancujeme-filmy-a-serialy-ktere-letos-zabily-8891337', | |
96 | 'md5': 'ba2fdbc1242fc16771c7695d271ec355', | |
97 | 'info_dict': { | |
e4cf7741 | 98 | 'id': '8891337', |
355d781b MH |
99 | 'title': 'md5:21f99739d04ab49d8c189ec711eef4ec', |
100 | }, | |
101 | 'playlist_count': 1, | |
102 | 'playlist': [{ | |
103 | 'md5': 'ba2fdbc1242fc16771c7695d271ec355', | |
104 | 'info_dict': { | |
105 | 'id': '10520988', | |
106 | 'ext': 'mp3', | |
107 | 'title': 'Papej masíčko! Porcujeme a bilancujeme filmy a seriály, které to letos zabily', | |
108 | 'description': 'md5:1c6d29fb9564e1f17fc1bb83ae7da0bc', | |
109 | 'duration': 1574, | |
110 | 'artist': 'Aleš Stuchlý', | |
111 | 'channel_id': 'radio-wave', | |
112 | }, | |
113 | }] | |
114 | }, { | |
115 | 'url': 'https://wave.rozhlas.cz/poslechnete-si-neklid-podcastovy-thriller-o-vine-strachu-a-vztahu-ktery-zasel-8554744', | |
116 | 'info_dict': { | |
e4cf7741 | 117 | 'id': '8554744', |
355d781b MH |
118 | 'title': 'Poslechněte si Neklid. Podcastový thriller o vině, strachu a vztahu, který zašel příliš daleko', |
119 | }, | |
120 | 'playlist_count': 5, | |
121 | 'playlist': [{ | |
122 | 'md5': '93d4109cf8f40523699ae9c1d4600bdd', | |
123 | 'info_dict': { | |
124 | 'id': '9890713', | |
125 | 'ext': 'mp3', | |
126 | 'title': 'Neklid #1', | |
127 | 'description': '1. díl: Neklid: 1. díl', | |
128 | 'duration': 1025, | |
129 | 'artist': 'Josef Kokta', | |
130 | 'channel_id': 'radio-wave', | |
131 | 'chapter': 'Neklid #1', | |
132 | 'chapter_number': 1, | |
133 | }, | |
134 | }, { | |
135 | 'md5': 'e9763235be4a6dcf94bc8a5bac1ca126', | |
136 | 'info_dict': { | |
137 | 'id': '9890716', | |
138 | 'ext': 'mp3', | |
139 | 'title': 'Neklid #2', | |
140 | 'description': '2. díl: Neklid: 2. díl', | |
141 | 'duration': 768, | |
142 | 'artist': 'Josef Kokta', | |
143 | 'channel_id': 'radio-wave', | |
144 | 'chapter': 'Neklid #2', | |
145 | 'chapter_number': 2, | |
146 | }, | |
147 | }, { | |
148 | 'md5': '00b642ea94b78cc949ac84da09f87895', | |
149 | 'info_dict': { | |
150 | 'id': '9890722', | |
151 | 'ext': 'mp3', | |
152 | 'title': 'Neklid #3', | |
153 | 'description': '3. díl: Neklid: 3. díl', | |
154 | 'duration': 607, | |
155 | 'artist': 'Josef Kokta', | |
156 | 'channel_id': 'radio-wave', | |
157 | 'chapter': 'Neklid #3', | |
158 | 'chapter_number': 3, | |
159 | }, | |
160 | }, { | |
161 | 'md5': 'faef97b1b49da7df874740f118c19dea', | |
162 | 'info_dict': { | |
163 | 'id': '9890728', | |
164 | 'ext': 'mp3', | |
165 | 'title': 'Neklid #4', | |
166 | 'description': '4. díl: Neklid: 4. díl', | |
167 | 'duration': 621, | |
168 | 'artist': 'Josef Kokta', | |
169 | 'channel_id': 'radio-wave', | |
170 | 'chapter': 'Neklid #4', | |
171 | 'chapter_number': 4, | |
172 | }, | |
173 | }, { | |
174 | 'md5': '6e729fa39b647325b868d419c76f3efa', | |
175 | 'info_dict': { | |
176 | 'id': '9890734', | |
177 | 'ext': 'mp3', | |
178 | 'title': 'Neklid #5', | |
179 | 'description': '5. díl: Neklid: 5. díl', | |
180 | 'duration': 908, | |
181 | 'artist': 'Josef Kokta', | |
182 | 'channel_id': 'radio-wave', | |
183 | 'chapter': 'Neklid #5', | |
184 | 'chapter_number': 5, | |
185 | }, | |
186 | }] | |
e4cf7741 | 187 | }, { |
188 | 'url': 'https://dvojka.rozhlas.cz/karel-siktanc-cerny-jezdec-bily-kun-napinava-pohadka-o-tajemnem-prizraku-8946969', | |
189 | 'info_dict': { | |
190 | 'id': '8946969', | |
191 | 'title': 'Karel Šiktanc: Černý jezdec, bílý kůň. Napínavá pohádka o tajemném přízraku', | |
192 | }, | |
193 | 'playlist_count': 1, | |
194 | 'playlist': [{ | |
195 | 'info_dict': { | |
196 | 'id': '10631121', | |
197 | 'ext': 'm4a', | |
198 | 'title': 'Karel Šiktanc: Černý jezdec, bílý kůň. Napínavá pohádka o tajemném přízraku', | |
199 | 'description': 'Karel Šiktanc: Černý jezdec, bílý kůň', | |
200 | 'duration': 2656, | |
201 | 'artist': 'Tvůrčí skupina Drama a literatura', | |
202 | 'channel_id': 'dvojka', | |
203 | }, | |
204 | }], | |
205 | 'params': {'skip_download': 'dash'}, | |
355d781b MH |
206 | }] |
207 | ||
208 | def _extract_video(self, entry): | |
e4cf7741 | 209 | audio_id = entry['meta']['ga']['contentId'] |
e4cf7741 | 210 | chapter_number = traverse_obj(entry, ('meta', 'ga', 'contentSerialPart', {int_or_none})) |
211 | ||
355d781b | 212 | return { |
e4cf7741 | 213 | 'id': audio_id, |
355d781b MH |
214 | 'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')) if chapter_number else None, |
215 | 'chapter_number': chapter_number, | |
c2b801fe | 216 | 'formats': self._extract_formats(entry, audio_id), |
e4cf7741 | 217 | **traverse_obj(entry, { |
218 | 'title': ('meta', 'ga', 'contentName'), | |
219 | 'description': 'title', | |
220 | 'duration': ('duration', {int_or_none}), | |
221 | 'artist': ('meta', 'ga', 'contentAuthor'), | |
222 | 'channel_id': ('meta', 'ga', 'contentCreator'), | |
223 | }) | |
355d781b MH |
224 | } |
225 | ||
226 | def _real_extract(self, url): | |
227 | video_id = self._match_id(url) | |
228 | webpage = self._download_webpage(url, video_id) | |
229 | ||
230 | # FIXME: Use get_element_text_and_html_by_tag when it accepts less strict html | |
231 | data = self._parse_json(extract_attributes(self._search_regex( | |
232 | r'(<div class="mujRozhlasPlayer" data-player=\'[^\']+\'>)', | |
233 | webpage, 'player'))['data-player'], video_id)['data'] | |
234 | ||
235 | return { | |
236 | '_type': 'playlist', | |
e4cf7741 | 237 | 'id': str_or_none(data.get('embedId')) or video_id, |
355d781b MH |
238 | 'title': traverse_obj(data, ('series', 'title')), |
239 | 'entries': map(self._extract_video, data['playlist']), | |
240 | } | |
c2b801fe | 241 | |
242 | ||
243 | class MujRozhlasIE(RozhlasBaseIE): | |
244 | _VALID_URL = r'https?://(?:www\.)?mujrozhlas\.cz/(?:[^/]+/)*(?P<id>[^/?#&]+)' | |
245 | _TESTS = [{ | |
246 | # single episode extraction | |
247 | 'url': 'https://www.mujrozhlas.cz/vykopavky/ach-jo-zase-teleci-rizek-je-mnohem-min-cesky-nez-jsme-si-mysleli', | |
248 | 'md5': '6f8fd68663e64936623e67c152a669e0', | |
249 | 'info_dict': { | |
250 | 'id': '10739193', | |
251 | 'ext': 'mp3', | |
252 | 'title': 'Ach jo, zase to telecí! Řízek je mnohem míň český, než jsme si mysleli', | |
253 | 'description': 'md5:db7141e9caaedc9041ec7cefb9a62908', | |
254 | 'timestamp': 1684915200, | |
255 | 'modified_timestamp': 1684922446, | |
256 | 'series': 'Vykopávky', | |
257 | 'thumbnail': 'https://portal.rozhlas.cz/sites/default/files/images/84377046610af6ddc54d910b1dd7a22b.jpg', | |
258 | 'channel_id': 'radio-wave', | |
259 | 'upload_date': '20230524', | |
260 | 'modified_date': '20230524', | |
261 | }, | |
262 | }, { | |
263 | # serial extraction | |
264 | 'url': 'https://www.mujrozhlas.cz/radiokniha/jaroslava-janackova-pribeh-tajemneho-psani-o-pramenech-genezi-babicky', | |
265 | 'playlist_mincount': 7, | |
266 | 'info_dict': { | |
267 | 'id': 'bb2b5f4e-ffb4-35a6-a34a-046aa62d6f6b', | |
268 | 'title': 'Jaroslava Janáčková: Příběh tajemného psaní. O pramenech a genezi Babičky', | |
269 | 'description': 'md5:7434d8fac39ac9fee6df098e11dfb1be', | |
270 | }, | |
271 | }, { | |
272 | # show extraction | |
273 | 'url': 'https://www.mujrozhlas.cz/nespavci', | |
274 | 'playlist_mincount': 14, | |
275 | 'info_dict': { | |
276 | 'id': '09db9b37-d0f4-368c-986a-d3439f741f08', | |
277 | 'title': 'Nespavci', | |
278 | 'description': 'md5:c430adcbf9e2b9eac88b745881e814dc', | |
279 | }, | |
280 | }] | |
281 | ||
282 | def _call_api(self, path, item_id, msg='API JSON'): | |
283 | return self._download_json( | |
284 | f'https://api.mujrozhlas.cz/{path}/{item_id}', item_id, | |
285 | note=f'Downloading {msg}', errnote=f'Failed to download {msg}')['data'] | |
286 | ||
287 | def _extract_audio_entry(self, entry): | |
288 | audio_id = entry['meta']['ga']['contentId'] | |
289 | ||
290 | return { | |
291 | 'id': audio_id, | |
292 | 'formats': self._extract_formats(entry['attributes'], audio_id), | |
293 | **traverse_obj(entry, { | |
294 | 'title': ('attributes', 'title'), | |
295 | 'description': ('attributes', 'description'), | |
296 | 'episode_number': ('attributes', 'part'), | |
297 | 'series': ('attributes', 'mirroredShow', 'title'), | |
298 | 'chapter': ('attributes', 'mirroredSerial', 'title'), | |
299 | 'artist': ('meta', 'ga', 'contentAuthor'), | |
300 | 'channel_id': ('meta', 'ga', 'contentCreator'), | |
301 | 'timestamp': ('attributes', 'since', {unified_timestamp}), | |
302 | 'modified_timestamp': ('attributes', 'updated', {unified_timestamp}), | |
303 | 'thumbnail': ('attributes', 'asset', 'url', {url_or_none}), | |
304 | }) | |
305 | } | |
306 | ||
307 | def _entries(self, api_url, playlist_id): | |
308 | for page in itertools.count(1): | |
309 | episodes = self._download_json( | |
310 | api_url, playlist_id, note=f'Downloading episodes page {page}', | |
311 | errnote=f'Failed to download episodes page {page}', fatal=False) | |
312 | for episode in traverse_obj(episodes, ('data', lambda _, v: v['meta']['ga']['contentId'])): | |
313 | yield self._extract_audio_entry(episode) | |
314 | api_url = traverse_obj(episodes, ('links', 'next', {url_or_none})) | |
315 | if not api_url: | |
316 | break | |
317 | ||
318 | def _real_extract(self, url): | |
319 | display_id = self._match_id(url) | |
320 | webpage = self._download_webpage(url, display_id) | |
321 | info = self._search_json(r'\bvar\s+dl\s*=', webpage, 'info json', display_id) | |
322 | ||
323 | entity = info['siteEntityBundle'] | |
324 | ||
325 | if entity == 'episode': | |
326 | return self._extract_audio_entry(self._call_api( | |
327 | 'episodes', info['contentId'], 'episode info API JSON')) | |
328 | ||
329 | elif entity in ('show', 'serial'): | |
330 | playlist_id = info['contentShow'].split(':')[0] if entity == 'show' else info['contentId'] | |
331 | data = self._call_api(f'{entity}s', playlist_id, f'{entity} playlist JSON') | |
332 | api_url = data['relationships']['episodes']['links']['related'] | |
333 | return self.playlist_result( | |
334 | self._entries(api_url, playlist_id), playlist_id, | |
335 | **traverse_obj(data, ('attributes', { | |
336 | 'title': 'title', | |
337 | 'description': 'description', | |
338 | }))) | |
339 | ||
340 | else: | |
341 | # `entity == 'person'` not implemented yet by API, ref: | |
342 | # https://api.mujrozhlas.cz/persons/8367e456-2a57-379a-91bb-e699619bea49/participation | |
343 | raise ExtractorError(f'Unsupported entity type "{entity}"') |