]>
Commit | Line | Data |
---|---|---|
27940ca0 PN |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
3c3a07ee S |
4 | import re |
5 | ||
27940ca0 PN |
6 | from .common import InfoExtractor |
7 | from ..compat import ( | |
8 | compat_parse_qs, | |
9 | compat_str, | |
10 | compat_urllib_parse_urlparse, | |
11 | ) | |
12 | from ..utils import ( | |
13 | urljoin, | |
14 | int_or_none, | |
3c3a07ee | 15 | parse_codecs, |
27940ca0 | 16 | try_get, |
27940ca0 PN |
17 | ) |
18 | ||
19 | ||
20 | def _raw_id(src_url): | |
21 | return compat_urllib_parse_urlparse(src_url).path.split('/')[-1] | |
22 | ||
23 | ||
24 | class SeznamZpravyIE(InfoExtractor): | |
3c3a07ee | 25 | _VALID_URL = r'https?://(?:www\.)?seznamzpravy\.cz/iframe/player\?.*\bsrc=' |
27940ca0 | 26 | _TESTS = [{ |
3c3a07ee | 27 | 'url': 'https://www.seznamzpravy.cz/iframe/player?duration=241&serviceSlug=zpravy&src=https%3A%2F%2Fv39-a.sdn.szn.cz%2Fv_39%2Fvmd%2F5999c902ea707c67d8e267a9%3Ffl%3Dmdk%2C432f65a0%7C&itemType=video&autoPlay=false&title=Sv%C4%9Bt%20bez%20obalu%3A%20%C4%8Ce%C5%A1t%C3%AD%20voj%C3%A1ci%20na%20mis%C3%ADch%20(kr%C3%A1tk%C3%A1%20verze)&series=Sv%C4%9Bt%20bez%20obalu&serviceName=Seznam%20Zpr%C3%A1vy&poster=%2F%2Fd39-a.sdn.szn.cz%2Fd_39%2Fc_img_F_I%2FR5puJ.jpeg%3Ffl%3Dcro%2C0%2C0%2C1920%2C1080%7Cres%2C1200%2C%2C1%7Cjpg%2C80%2C%2C1&width=1920&height=1080&cutFrom=0&cutTo=0&splVersion=VOD&contentId=170889&contextId=35990&showAdvert=true&collocation=&autoplayPossible=true&embed=&isVideoTooShortForPreroll=false&isVideoTooLongForPostroll=true&videoCommentOpKey=&videoCommentId=&version=4.0.76&dotService=zpravy&gemiusPrismIdentifier=bVc1ZIb_Qax4W2v5xOPGpMeCP31kFfrTzj0SqPTLh_b.Z7&zoneIdPreroll=seznam.pack.videospot&skipOffsetPreroll=5§ionPrefixPreroll=%2Fzpravy', |
27940ca0 PN |
28 | 'info_dict': { |
29 | 'id': '170889', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'Svět bez obalu: Čeští vojáci na misích (krátká verze)', | |
3c3a07ee S |
32 | 'thumbnail': r're:^https?://.*\.jpe?g', |
33 | 'duration': 241, | |
34 | 'series': 'Svět bez obalu', | |
35 | }, | |
36 | 'params': { | |
37 | 'skip_download': True, | |
38 | }, | |
39 | }, { | |
40 | # with Location key | |
41 | 'url': 'https://www.seznamzpravy.cz/iframe/player?duration=null&serviceSlug=zpravy&src=https%3A%2F%2Flive-a.sdn.szn.cz%2Fv_39%2F59e468fe454f8472a96af9fa%3Ffl%3Dmdk%2C5c1e2840%7C&itemType=livevod&autoPlay=false&title=P%C5%99edseda%20KDU-%C4%8CSL%20Pavel%20B%C4%9Blobr%C3%A1dek%20ve%20volebn%C3%AD%20V%C3%BDzv%C4%9B%20Seznamu&series=V%C3%BDzva&serviceName=Seznam%20Zpr%C3%A1vy&poster=%2F%2Fd39-a.sdn.szn.cz%2Fd_39%2Fc_img_G_J%2FjTBCs.jpeg%3Ffl%3Dcro%2C0%2C0%2C1280%2C720%7Cres%2C1200%2C%2C1%7Cjpg%2C80%2C%2C1&width=16&height=9&cutFrom=0&cutTo=0&splVersion=VOD&contentId=185688&contextId=38489&showAdvert=true&collocation=&hideFullScreen=false&hideSubtitles=false&embed=&isVideoTooShortForPreroll=false&isVideoTooShortForPreroll2=false&isVideoTooLongForPostroll=false&fakePostrollZoneID=seznam.clanky.zpravy.preroll&fakePrerollZoneID=seznam.clanky.zpravy.preroll&videoCommentId=&trim=default_16x9&noPrerollVideoLength=30&noPreroll2VideoLength=undefined&noMidrollVideoLength=0&noPostrollVideoLength=999999&autoplayPossible=true&version=5.0.41&dotService=zpravy&gemiusPrismIdentifier=zD3g7byfW5ekpXmxTVLaq5Srjw5i4hsYo0HY1aBwIe..27&zoneIdPreroll=seznam.pack.videospot&skipOffsetPreroll=5§ionPrefixPreroll=%2Fzpravy%2Fvyzva&zoneIdPostroll=seznam.pack.videospot&skipOffsetPostroll=5§ionPrefixPostroll=%2Fzpravy%2Fvyzva®ression=false', | |
42 | 'info_dict': { | |
43 | 'id': '185688', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Předseda KDU-ČSL Pavel Bělobrádek ve volební Výzvě Seznamu', | |
46 | 'thumbnail': r're:^https?://.*\.jpe?g', | |
47 | 'series': 'Výzva', | |
48 | }, | |
49 | 'params': { | |
50 | 'skip_download': True, | |
51 | }, | |
27940ca0 PN |
52 | }] |
53 | ||
3c3a07ee S |
54 | @staticmethod |
55 | def _extract_urls(webpage): | |
56 | return [ | |
57 | mobj.group('url') for mobj in re.finditer( | |
58 | r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?seznamzpravy\.cz/iframe/player\?.*?)\1', | |
59 | webpage)] | |
60 | ||
27940ca0 PN |
61 | def _extract_sdn_formats(self, sdn_url, video_id): |
62 | sdn_data = self._download_json(sdn_url, video_id) | |
3c3a07ee S |
63 | |
64 | if sdn_data.get('Location'): | |
65 | sdn_url = sdn_data['Location'] | |
66 | sdn_data = self._download_json(sdn_url, video_id) | |
67 | ||
27940ca0 PN |
68 | formats = [] |
69 | mp4_formats = try_get(sdn_data, lambda x: x['data']['mp4'], dict) or {} | |
3c3a07ee S |
70 | for format_id, format_data in mp4_formats.items(): |
71 | relative_url = format_data.get('url') | |
27940ca0 PN |
72 | if not relative_url: |
73 | continue | |
74 | ||
75 | try: | |
3c3a07ee | 76 | width, height = format_data.get('resolution') |
27940ca0 PN |
77 | except (TypeError, ValueError): |
78 | width, height = None, None | |
79 | ||
3c3a07ee S |
80 | f = { |
81 | 'url': urljoin(sdn_url, relative_url), | |
82 | 'format_id': 'http-%s' % format_id, | |
83 | 'tbr': int_or_none(format_data.get('bandwidth'), scale=1000), | |
27940ca0 PN |
84 | 'width': int_or_none(width), |
85 | 'height': int_or_none(height), | |
3c3a07ee S |
86 | } |
87 | f.update(parse_codecs(format_data.get('codec'))) | |
88 | formats.append(f) | |
89 | ||
90 | pls = sdn_data.get('pls', {}) | |
27940ca0 | 91 | |
3c3a07ee S |
92 | def get_url(format_id): |
93 | return try_get(pls, lambda x: x[format_id]['url'], compat_str) | |
94 | ||
95 | dash_rel_url = get_url('dash') | |
27940ca0 | 96 | if dash_rel_url: |
3c3a07ee S |
97 | formats.extend(self._extract_mpd_formats( |
98 | urljoin(sdn_url, dash_rel_url), video_id, mpd_id='dash', | |
99 | fatal=False)) | |
27940ca0 | 100 | |
3c3a07ee | 101 | hls_rel_url = get_url('hls') |
27940ca0 | 102 | if hls_rel_url: |
3c3a07ee S |
103 | formats.extend(self._extract_m3u8_formats( |
104 | urljoin(sdn_url, hls_rel_url), video_id, ext='mp4', | |
105 | m3u8_id='hls', fatal=False)) | |
27940ca0 PN |
106 | |
107 | self._sort_formats(formats) | |
108 | return formats | |
109 | ||
110 | def _real_extract(self, url): | |
111 | params = compat_parse_qs(compat_urllib_parse_urlparse(url).query) | |
3c3a07ee | 112 | |
27940ca0 | 113 | src = params['src'][0] |
3c3a07ee | 114 | title = params['title'][0] |
27940ca0 | 115 | video_id = params.get('contentId', [_raw_id(src)])[0] |
3c3a07ee S |
116 | formats = self._extract_sdn_formats(src + 'spl2,2,VOD', video_id) |
117 | ||
118 | duration = int_or_none(params.get('duration', [None])[0]) | |
119 | series = params.get('series', [None])[0] | |
120 | thumbnail = params.get('poster', [None])[0] | |
27940ca0 PN |
121 | |
122 | return { | |
123 | 'id': video_id, | |
3c3a07ee S |
124 | 'title': title, |
125 | 'thumbnail': thumbnail, | |
126 | 'duration': duration, | |
127 | 'series': series, | |
128 | 'formats': formats, | |
27940ca0 PN |
129 | } |
130 | ||
131 | ||
132 | class SeznamZpravyArticleIE(InfoExtractor): | |
3c3a07ee | 133 | _VALID_URL = r'https?://(?:www\.)?(?:seznam\.cz/zpravy|seznamzpravy\.cz)/clanek/(?:[^/?#&]+)-(?P<id>\d+)' |
27940ca0 PN |
134 | _API_URL = 'https://apizpravy.seznam.cz/' |
135 | ||
136 | _TESTS = [{ | |
137 | # two videos on one page, with SDN URL | |
138 | 'url': 'https://www.seznamzpravy.cz/clanek/jejich-svet-na-nas-utoci-je-lepsi-branit-se-na-jejich-pisecku-rika-reziser-a-major-v-zaloze-marhoul-35990', | |
27940ca0 | 139 | 'info_dict': { |
3c3a07ee S |
140 | 'id': '35990', |
141 | 'title': 'md5:6011c877a36905f28f271fcd8dcdb0f2', | |
142 | 'description': 'md5:933f7b06fa337a814ba199d3596d27ba', | |
143 | }, | |
144 | 'playlist_count': 2, | |
27940ca0 PN |
145 | }, { |
146 | # video with live stream URL | |
147 | 'url': 'https://www.seznam.cz/zpravy/clanek/znovu-do-vlady-s-ano-pavel-belobradek-ve-volebnim-specialu-seznamu-38489', | |
148 | 'info_dict': { | |
3c3a07ee S |
149 | 'id': '38489', |
150 | 'title': 'md5:8fa1afdc36fd378cf0eba2b74c5aca60', | |
151 | 'description': 'md5:428e7926a1a81986ec7eb23078004fb4', | |
152 | }, | |
153 | 'playlist_count': 1, | |
27940ca0 PN |
154 | }] |
155 | ||
3c3a07ee S |
156 | def _real_extract(self, url): |
157 | article_id = self._match_id(url) | |
27940ca0 | 158 | |
3c3a07ee | 159 | webpage = self._download_webpage(url, article_id) |
27940ca0 | 160 | |
3c3a07ee | 161 | info = self._search_json_ld(webpage, article_id, default={}) |
27940ca0 | 162 | |
3c3a07ee S |
163 | title = info.get('title') or self._og_search_title(webpage, fatal=False) |
164 | description = info.get('description') or self._og_search_description(webpage) | |
27940ca0 | 165 | |
3c3a07ee | 166 | return self.playlist_result([ |
2c9d3b99 S |
167 | self.url_result(entry_url, ie=SeznamZpravyIE.ie_key()) |
168 | for entry_url in SeznamZpravyIE._extract_urls(webpage)], | |
3c3a07ee | 169 | article_id, title, description) |