]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rozhlas.py
3 from . common
import InfoExtractor
4 from .. networking
. exceptions
import HTTPError
17 class RozhlasIE ( InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?prehravac\.rozhlas\.cz/audio/(?P<id>[0-9]+)'
20 'url' : 'http://prehravac.rozhlas.cz/audio/3421320' ,
21 'md5' : '504c902dbc9e9a1fd50326eccf02a7e2' ,
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'
29 'url' : 'http://prehravac.rozhlas.cz/audio/3421320/embed' ,
30 'only_matching' : True ,
33 def _real_extract ( self
, url
):
34 audio_id
= self
._ match
_ id
( url
)
36 webpage
= self
._ download
_ webpage
(
37 'http://prehravac.rozhlas.cz/audio/ %s ' % audio_id
, audio_id
)
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))
51 'url': 'http://media.rozhlas.cz/_audio/ %s .mp3' % audio_id,
53 'description': description,
59 class RozhlasBaseIE(InfoExtractor):
60 def _extract_formats(self, entry, audio_id):
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():
66 self._sleep(1, audio_id)
69 formats.extend(self._extract_mpd_formats(
70 audio['url'], audio_id, mpd_id=ext))
72 formats.extend(self._extract_m3u8_formats(
73 audio['url'], audio_id, 'm4a', m3u8_id=ext))
79 'abr': int_or_none(audio.get('bitrate')),
83 except ExtractorError as e:
84 if isinstance(e.cause, HTTPError) and e.cause.status == 429:
87 self.report_warning(e.msg)
92 class RozhlasVltavaIE(RozhlasBaseIE):
93 _VALID_URL = r'https?://(?:\w+\.rozhlas|english\.radio)\.cz/[\w-]+-(?P<id>\d+)'
95 'url': 'https://wave.rozhlas.cz/papej-masicko-porcujeme-a-bilancujeme-filmy-a-serialy-ktere-letos-zabily-8891337',
96 'md5': 'ba2fdbc1242fc16771c7695d271ec355',
99 'title': 'md5:21f99739d04ab49d8c189ec711eef4ec',
103 'md5': 'ba2fdbc1242fc16771c7695d271ec355',
107 'title': 'Papej masíčko! Porcujeme a bilancujeme filmy a seriály, které to letos zabily',
108 'description': 'md5:1c6d29fb9564e1f17fc1bb83ae7da0bc',
110 'artist': 'Aleš Stuchlý',
111 'channel_id': 'radio-wave',
115 'url': 'https://wave.rozhlas.cz/poslechnete-si-neklid-podcastovy-thriller-o-vine-strachu-a-vztahu-ktery-zasel-8554744',
118 'title': 'Poslechněte si Neklid. Podcastový thriller o vině, strachu a vztahu, který zašel příliš daleko',
122 'md5': '93d4109cf8f40523699ae9c1d4600bdd',
126 'title': 'Neklid #1',
127 'description': '1. díl: Neklid: 1. díl',
129 'artist': 'Josef Kokta',
130 'channel_id': 'radio-wave',
131 'chapter': 'Neklid #1',
135 'md5': 'e9763235be4a6dcf94bc8a5bac1ca126',
139 'title': 'Neklid #2',
140 'description': '2. díl: Neklid: 2. díl',
142 'artist': 'Josef Kokta',
143 'channel_id': 'radio-wave',
144 'chapter': 'Neklid #2',
148 'md5': '00b642ea94b78cc949ac84da09f87895',
152 'title': 'Neklid #3',
153 'description': '3. díl: Neklid: 3. díl',
155 'artist': 'Josef Kokta',
156 'channel_id': 'radio-wave',
157 'chapter': 'Neklid #3',
161 'md5': 'faef97b1b49da7df874740f118c19dea',
165 'title': 'Neklid #4',
166 'description': '4. díl: Neklid: 4. díl',
168 'artist': 'Josef Kokta',
169 'channel_id': 'radio-wave',
170 'chapter': 'Neklid #4',
174 'md5': '6e729fa39b647325b868d419c76f3efa',
178 'title': 'Neklid #5',
179 'description': '5. díl: Neklid: 5. díl',
181 'artist': 'Josef Kokta',
182 'channel_id': 'radio-wave',
183 'chapter': 'Neklid #5',
188 'url': 'https://dvojka.rozhlas.cz/karel-siktanc-cerny-jezdec-bily-kun-napinava-pohadka-o-tajemnem-prizraku-8946969',
191 'title': 'Karel Šiktanc: Černý jezdec, bílý kůň. Napínavá pohádka o tajemném přízraku',
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ůň',
201 'artist': 'Tvůrčí skupina Drama a literatura',
202 'channel_id': 'dvojka',
205 'params': {'skip_download': 'dash'} ,
208 def _extract_video(self, entry):
209 audio_id = entry['meta']['ga']['contentId']
210 chapter_number = traverse_obj(entry, ('meta', 'ga', 'contentSerialPart', {int_or_none} ))
214 'chapter': traverse_obj(entry, ('meta', 'ga', 'contentNameShort')) if chapter_number else None,
215 'chapter_number': chapter_number,
216 'formats': self._extract_formats(entry, audio_id),
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'),
226 def _real_extract(self, url):
227 video_id = self._match_id(url)
228 webpage = self._download_webpage(url, video_id)
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']
237 'id': str_or_none(data.get('embedId')) or video_id,
238 'title': traverse_obj(data, ('series', 'title')),
239 'entries': map(self._extract_video, data['playlist']),
243 class MujRozhlasIE(RozhlasBaseIE):
244 _VALID_URL = r'https?://(?:www\.)?mujrozhlas\.cz/(?:[^/]+/)*(?P<id>[^/?#&]+)'
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',
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',
264 'url': 'https://www.mujrozhlas.cz/radiokniha/jaroslava-janackova-pribeh-tajemneho-psani-o-pramenech-genezi-babicky',
265 'playlist_mincount': 7,
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',
273 'url': 'https://www.mujrozhlas.cz/nespavci',
274 'playlist_mincount': 14,
276 'id': '09db9b37-d0f4-368c-986a-d3439f741f08',
278 'description': 'md5:c430adcbf9e2b9eac88b745881e814dc',
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']
287 def _extract_audio_entry(self, entry):
288 audio_id = entry['meta']['ga']['contentId']
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} ),
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} ))
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)
323 entity = info['siteEntityBundle']
325 if entity == 'episode':
326 return self._extract_audio_entry(self._call_api(
327 'episodes', info['contentId'], 'episode info API JSON'))
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', {
337 'description': 'description',
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}
"')