6 from .common
import InfoExtractor
9 compat_urllib_parse_unquote
,
26 class PolskieRadioBaseExtractor(InfoExtractor
):
27 def _extract_webpage_player_entries(self
, webpage
, playlist_id
, base_data
):
30 for data_media
in re
.findall(r
'<[^>]+data-media="?({[^>]+})"?', webpage
):
31 media
= self
._parse
_json
(data_media
, playlist_id
, transform_source
=unescapeHTML
, fatal
=False)
32 if not media
.get('file') or not media
.get('desc'):
34 media_url
= self
._proto
_relative
_url
(media
['file'])
35 if media_url
in media_urls
:
37 media_urls
.add(media_url
)
38 entry
= base_data
.copy()
40 'id': compat_str(media
['id']),
42 'duration': int_or_none(media
.get('length')),
43 'vcodec': 'none' if media
.get('provider') == 'audio' else None,
45 entry_title
= compat_urllib_parse_unquote(media
['desc'])
47 entry
['title'] = entry_title
51 class PolskieRadioIE(PolskieRadioBaseExtractor
):
52 _VALID_URL
= r
'https?://(?:www\.)?polskieradio(?:24)?\.pl/\d+/\d+/Artykul/(?P<id>[0-9]+)'
53 _TESTS
= [{ # Old-style single broadcast.
54 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943,Prof-Andrzej-Nowak-o-historii-nie-da-sie-myslec-beznamietnie',
57 'title': 'Prof. Andrzej Nowak: o historii nie da się myśleć beznamiętnie',
58 'description': 'md5:12f954edbf3120c5e7075e17bf9fc5c5',
61 'md5': '2984ee6ce9046d91fc233bc1a864a09a',
65 'title': 'md5:d4623290d4ac983bf924061c75c23a0d',
66 'timestamp': 1456594200,
67 'upload_date': '20160227',
69 'thumbnail': r
're:^https?://static\.prsa\.pl/images/.*\.jpg$'
72 }, { # New-style single broadcast.
73 'url': 'https://www.polskieradio.pl/8/2382/Artykul/2534482,Zagarysci-Poezja-jak-spoiwo',
76 'title': 'Żagaryści. Poezja jak spoiwo',
77 'description': 'md5:f18d95d5dcba747a09b635e21a4c0695',
80 'md5': 'd07559829f61d5a93a75755987ded760',
84 'title': 'md5:c6e1234e0b747ad883cb91b7ad06b98c',
85 'timestamp': 1592654400,
86 'upload_date': '20200620',
88 'thumbnail': r
're:^https?://static\.prsa\.pl/images/.*\.jpg$'
92 # PR4 audition - other frontend
93 'url': 'https://www.polskieradio.pl/10/6071/Artykul/2610977,Poglos-29-pazdziernika-godz-2301',
97 'title': 'Pogłos 29 października godz. 23:01',
100 'url': 'http://polskieradio.pl/9/305/Artykul/1632955,Bardzo-popularne-slowo-remis',
101 'only_matching': True,
103 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943',
104 'only_matching': True,
107 'url': 'http://www.polskieradio.pl/9/299/Artykul/1634903,Brexit-Leszek-Miller-swiat-sie-nie-zawali-Europa-bedzie-trwac-dalej',
108 'only_matching': True,
110 'url': 'https://polskieradio24.pl/130/4503/Artykul/2621876,Narusza-nasza-suwerennosc-Publicysci-o-uzaleznieniu-funduszy-UE-od-praworzadnosci',
111 'only_matching': True,
114 def _real_extract(self
, url
):
115 playlist_id
= self
._match
_id
(url
)
117 webpage
= self
._download
_webpage
(url
, playlist_id
)
119 content
= self
._search
_regex
(
120 r
'(?s)<div[^>]+class="\s*this-article\s*"[^>]*>(.+?)<div[^>]+class="tags"[^>]*>',
121 webpage
, 'content', default
=None)
123 timestamp
= unified_timestamp(self
._html
_search
_regex
(
124 r
'(?s)<span[^>]+id="datetime2"[^>]*>(.+?)</span>',
125 webpage
, 'timestamp', default
=None))
127 thumbnail_url
= self
._og
_search
_thumbnail
(webpage
, default
=None)
129 title
= self
._og
_search
_title
(webpage
).strip()
131 description
= strip_or_none(self
._og
_search
_description
(webpage
, default
=None))
132 description
= description
.replace('\xa0', ' ') if description
is not None else None
137 'url': self
._proto
_relative
_url
(
139 r
"source:\s*'(//static\.prsa\.pl/[^']+)'",
140 webpage
, 'audition record url')),
142 'description': description
,
143 'timestamp': timestamp
,
144 'thumbnail': thumbnail_url
,
147 entries
= self
._extract
_webpage
_player
_entries
(content
, playlist_id
, {
149 'timestamp': timestamp
,
150 'thumbnail': thumbnail_url
,
153 return self
.playlist_result(entries
, playlist_id
, title
, description
)
156 class PolskieRadioCategoryIE(InfoExtractor
):
157 _VALID_URL
= r
'https?://(?:www\.)?polskieradio\.pl/\d+(?:,[^/]+)?/(?P<id>\d+)'
159 'url': 'http://www.polskieradio.pl/7/5102,HISTORIA-ZYWA',
162 'title': 'HISTORIA ŻYWA',
164 'playlist_mincount': 38,
166 'url': 'http://www.polskieradio.pl/7/4807',
169 'title': 'Vademecum 1050. rocznicy Chrztu Polski'
171 'playlist_mincount': 5
173 'url': 'http://www.polskieradio.pl/7/129,Sygnaly-dnia?ref=source',
174 'only_matching': True
176 'url': 'http://www.polskieradio.pl/37,RedakcjaKatolicka/4143,Kierunek-Krakow',
179 'title': 'Kierunek Kraków',
181 'playlist_mincount': 61
183 'url': 'http://www.polskieradio.pl/10,czworka/214,muzyka',
188 'playlist_mincount': 61
190 'url': 'http://www.polskieradio.pl/7,Jedynka/5102,HISTORIA-ZYWA',
191 'only_matching': True,
193 'url': 'http://www.polskieradio.pl/8,Dwojka/196,Publicystyka',
194 'only_matching': True,
198 def suitable(cls
, url
):
199 return False if PolskieRadioIE
.suitable(url
) else super(PolskieRadioCategoryIE
, cls
).suitable(url
)
201 def _entries(self
, url
, page
, category_id
):
203 for page_num
in itertools
.count(2):
204 for a_entry
, entry_id
in re
.findall(
205 r
'(?s)<article[^>]+>.*?(<a[^>]+href=["\']/\d
+/\d
+/Artykul
/(\d
+)[^
>]+>).*?
</article
>',
207 entry = extract_attributes(a_entry)
208 href = entry.get('href
')
211 yield self.url_result(
212 compat_urlparse.urljoin(url, href), PolskieRadioIE.ie_key(),
213 entry_id, entry.get('title
'))
215 r'<div
[^
>]+class=["\']next["\'][^
>]*>\s
*<a
[^
>]+href
=(["\'])(?P<url>(?:(?!\1).)+)\1',
219 next_url = compat_urlparse.urljoin(url, mobj.group('url'))
220 content = self._download_webpage(
221 next_url, category_id, 'Downloading page %s' % page_num)
223 def _real_extract(self, url):
224 category_id = self._match_id(url)
225 webpage = self._download_webpage(url, category_id)
226 title = self._html_search_regex(
227 r'<title>([^<]+) - [^<]+ - [^<]+</title>',
228 webpage, 'title', fatal=False)
229 return self.playlist_result(
230 self._entries(url, webpage, category_id),
234 class PolskieRadioPlayerIE(InfoExtractor):
235 IE_NAME = 'polskieradio:player'
236 _VALID_URL = r'https?://player\.polskieradio\.pl/anteny/(?P<id>[^/]+)'
238 _BASE_URL = 'https://player.polskieradio.pl'
239 _PLAYER_URL = 'https://player.polskieradio.pl/main.bundle.js'
240 _STATIONS_API_URL = 'https://apipr.polskieradio.pl/api/stacje'
243 'url': 'https://player.polskieradio.pl/anteny/trojka',
250 'format': 'bestaudio',
251 'skip_download': 'endless stream',
255 def _get_channel_list(self, channel_url='no_channel'):
256 player_code = self._download_webpage(
257 self._PLAYER_URL, channel_url,
258 note='Downloading js player')
259 channel_list = js_to_json(self._search_regex(
260 r';var r="anteny
",a=(\[.+?\])},', player_code, 'channel list'))
261 return self._parse_json(channel_list, channel_url)
263 def _real_extract(self, url):
264 channel_url = self._match_id(url)
265 channel_list = self._get_channel_list(channel_url)
267 channel = next((c for c in channel_list if c.get('url') == channel_url), None)
270 raise ExtractorError('Channel not found')
272 station_list = self._download_json(self._STATIONS_API_URL, channel_url,
273 note='Downloading stream url list',
275 'Accept': 'application/json',
277 'Origin': self._BASE_URL,
279 station = next((s for s in station_list
280 if s.get('Name') == (channel.get('streamName') or channel.get('name'))), None)
282 raise ExtractorError('Station not found even though we extracted channel')
285 for stream_url in station['Streams']:
286 stream_url = self._proto_relative_url(stream_url)
287 if stream_url.endswith('/playlist.m3u8'):
288 formats.extend(self._extract_m3u8_formats(stream_url, channel_url, live=True))
289 elif stream_url.endswith('/manifest.f4m'):
290 formats.extend(self._extract_mpd_formats(stream_url, channel_url))
291 elif stream_url.endswith('/Manifest'):
292 formats.extend(self._extract_ism_formats(stream_url, channel_url))
298 self._sort_formats(formats)
301 'id': compat_str(channel['id']),
303 'title': channel.get('name') or channel.get('streamName'),
304 'display_id': channel_url,
305 'thumbnail': f'{self._BASE_URL}/images/{channel_url}-color-logo.png',
310 class PolskieRadioPodcastBaseExtractor(InfoExtractor):
311 _API_BASE = 'https://apipodcasts.polskieradio.pl/api'
313 def _parse_episode(self, data):
318 'filesize': int_or_none(data.get('fileSize')),
320 'title': data['title'],
321 'description': data.get('description'),
322 'duration': int_or_none(data.get('length')),
323 'timestamp': parse_iso8601(data.get('publishDate')),
324 'thumbnail': url_or_none(data.get('image')),
325 'series': data.get('podcastTitle'),
326 'episode': data['title'],
330 class PolskieRadioPodcastListIE(PolskieRadioPodcastBaseExtractor):
331 IE_NAME = 'polskieradio:podcast:list'
332 _VALID_URL = r'https?://podcasty\.polskieradio\.pl/podcast/(?P<id>\d+)'
334 'url': 'https://podcasty.polskieradio.pl/podcast/8/',
337 'title': 'Śniadanie w Trójce',
338 'description': 'md5:57abcc27bc4c6a6b25baa3061975b9ef',
339 'uploader': 'Beata Michniewicz',
341 'playlist_mincount': 714,
345 def _call_api(self, podcast_id, page):
346 return self._download_json(
347 f'{self._API_BASE}/Podcasts/{podcast_id}/?pageSize={self._PAGE_SIZE}&page={page}',
348 podcast_id, f'Downloading page {page}')
350 def _real_extract(self, url):
351 podcast_id = self._match_id(url)
352 data = self._call_api(podcast_id, 1)
354 def get_page(page_num):
355 page_data = self._call_api(podcast_id, page_num + 1) if page_num else data
356 yield from (self._parse_episode(ep) for ep in page_data['items'])
360 'entries': InAdvancePagedList(
361 get_page, math.ceil(data['itemCount'] / self._PAGE_SIZE), self._PAGE_SIZE),
362 'id': str(data['id']),
363 'title': data['title'],
364 'description': data.get('description'),
365 'uploader': data.get('announcer'),
369 class PolskieRadioPodcastIE(PolskieRadioPodcastBaseExtractor):
370 IE_NAME = 'polskieradio:podcast'
371 _VALID_URL = r'https?://podcasty\.polskieradio\.pl/track/(?P<id>[a-f\d]{8}(?:-[a-f\d]{4}){4}[a-f\d]{8})'
373 'url': 'https://podcasty.polskieradio.pl/track/6eafe403-cb8f-4756-b896-4455c3713c32',
375 'id': '6eafe403-cb8f-4756-b896-4455c3713c32',
377 'title': 'Theresa May rezygnuje. Co dalej z brexitem?',
378 'description': 'md5:e41c409a29d022b70ef0faa61dbded60',
382 def _real_extract(self, url):
383 podcast_id = self._match_id(url)
384 data = self._download_json(
385 f'{self._API_BASE}/audio',
386 podcast_id, 'Downloading podcast metadata',
388 'guids': [podcast_id],
391 'Content-Type': 'application/json',
393 return self._parse_episode(data[0])
396 class PolskieRadioRadioKierowcowIE(PolskieRadioBaseExtractor):
397 _VALID_URL = r'https?://(?:www\.)?radiokierowcow\.pl/artykul/(?P<id>[0-9]+)'
398 IE_NAME = 'polskieradio:kierowcow'
401 'url': 'https://radiokierowcow.pl/artykul/2694529',
404 'title': 'Zielona fala reliktem przeszłości?',
405 'description': 'md5:343950a8717c9818fdfd4bd2b8ca9ff2',
410 def _real_extract(self, url):
411 media_id = self._match_id(url)
412 webpage = self._download_webpage(url, media_id)
413 nextjs_build = self._search_nextjs_data(webpage, media_id)['buildId']
414 article = self._download_json(
415 f'https://radiokierowcow.pl/_next/data/{nextjs_build}/artykul/{media_id}.json?articleId={media_id}',
417 data = article['pageProps']['data']
418 title = data['title']
419 entries = self._extract_webpage_player_entries(data['content'], media_id, {
428 'description': data.get('lead'),