]>
Commit | Line | Data |
---|---|---|
2d185706 JAW |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
0463b77a | 4 | import re |
2d185706 | 5 | |
0463b77a S |
6 | from .common import InfoExtractor |
7 | from ..compat import ( | |
8 | compat_str, | |
9 | compat_urllib_parse_unquote, | |
10 | ) | |
11 | from ..utils import ( | |
12 | int_or_none, | |
13 | strip_or_none, | |
14 | unified_timestamp, | |
15 | ) | |
2d185706 JAW |
16 | |
17 | ||
18 | class PolskieRadioIE(InfoExtractor): | |
0463b77a | 19 | _VALID_URL = r'https?://(?:www\.)?polskieradio\.pl/\d+/\d+/Artykul/(?P<id>[0-9]+)' |
2d185706 JAW |
20 | _TESTS = [{ |
21 | 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943,Prof-Andrzej-Nowak-o-historii-nie-da-sie-myslec-beznamietnie', | |
2d185706 JAW |
22 | 'info_dict': { |
23 | 'id': '1587943', | |
2d185706 JAW |
24 | 'title': 'Prof. Andrzej Nowak: o historii nie da się myśleć beznamiętnie', |
25 | 'description': 'md5:12f954edbf3120c5e7075e17bf9fc5c5', | |
0463b77a S |
26 | }, |
27 | 'playlist': [{ | |
28 | 'md5': '2984ee6ce9046d91fc233bc1a864a09a', | |
29 | 'info_dict': { | |
30 | 'id': '1540576', | |
31 | 'ext': 'mp3', | |
32 | 'title': 'md5:d4623290d4ac983bf924061c75c23a0d', | |
33 | 'timestamp': 1456594200, | |
34 | 'upload_date': '20160227', | |
35 | 'duration': 2364, | |
2e32ac0b | 36 | 'thumbnail': 're:^https?://static\.prsa\.pl/images/.*\.jpg$' |
0463b77a S |
37 | }, |
38 | }], | |
2d185706 | 39 | }, { |
0463b77a | 40 | 'url': 'http://www.polskieradio.pl/265/5217/Artykul/1635803,Euro-2016-nie-ma-miejsca-na-blad-Polacy-graja-ze-Szwajcaria-o-cwiercfinal', |
2d185706 | 41 | 'info_dict': { |
0463b77a S |
42 | 'id': '1635803', |
43 | 'title': 'Euro 2016: nie ma miejsca na błąd. Polacy grają ze Szwajcarią o ćwierćfinał', | |
44 | 'description': 'md5:01cb7d0cad58664095d72b51a1ebada2', | |
45 | }, | |
46 | 'playlist_mincount': 12, | |
47 | }, { | |
48 | 'url': 'http://polskieradio.pl/9/305/Artykul/1632955,Bardzo-popularne-slowo-remis', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'http://www.polskieradio.pl/7/5102/Artykul/1587943', | |
52 | 'only_matching': True, | |
ce96ed05 S |
53 | }, { |
54 | # with mp4 video | |
55 | 'url': 'http://www.polskieradio.pl/9/299/Artykul/1634903,Brexit-Leszek-Miller-swiat-sie-nie-zawali-Europa-bedzie-trwac-dalej', | |
56 | 'only_matching': True, | |
2d185706 JAW |
57 | }] |
58 | ||
59 | def _real_extract(self, url): | |
0463b77a S |
60 | playlist_id = self._match_id(url) |
61 | ||
62 | webpage = self._download_webpage(url, playlist_id) | |
63 | ||
64 | content = self._search_regex( | |
65 | r'(?s)<div[^>]+class="audio atarticle"[^>]*>(.+?)<script>', | |
66 | webpage, 'content') | |
67 | ||
68 | timestamp = unified_timestamp(self._html_search_regex( | |
69 | r'(?s)<span[^>]+id="datetime2"[^>]*>(.+?)</span>', | |
70 | webpage, 'timestamp', fatal=False)) | |
2d185706 | 71 | |
e2d616dd JAW |
72 | thumbnail_url = self._og_search_thumbnail(webpage) |
73 | ||
0463b77a | 74 | entries = [] |
2d185706 | 75 | |
0463b77a | 76 | media_urls = set() |
2d185706 | 77 | |
0463b77a S |
78 | for data_media in re.findall(r'<[^>]+data-media=({[^>]+})', content): |
79 | media = self._parse_json(data_media, playlist_id, fatal=False) | |
80 | if not media.get('file') or not media.get('desc'): | |
81 | continue | |
82 | media_url = self._proto_relative_url(media['file'], 'http:') | |
83 | if media_url in media_urls: | |
84 | continue | |
85 | media_urls.add(media_url) | |
86 | entries.append({ | |
87 | 'id': compat_str(media['id']), | |
88 | 'url': media_url, | |
89 | 'title': compat_urllib_parse_unquote(media['desc']), | |
90 | 'duration': int_or_none(media.get('length')), | |
91 | 'vcodec': 'none' if media.get('provider') == 'audio' else None, | |
92 | 'timestamp': timestamp, | |
e2d616dd | 93 | 'thumbnail': thumbnail_url |
0463b77a | 94 | }) |
2d185706 | 95 | |
0463b77a S |
96 | title = self._og_search_title(webpage).strip() |
97 | description = strip_or_none(self._og_search_description(webpage)) | |
2d185706 | 98 | |
0463b77a | 99 | return self.playlist_result(entries, playlist_id, title, description) |