2 from __future__ import unicode_literals
4 from .common import InfoExtractor
8 compat_urllib_parse_urlparse,
19 return compat_urllib_parse_urlparse(src_url).path.split('/')[-1]
22 class SeznamZpravyIE(InfoExtractor):
23 _VALID_URL = r'https?://(?:www\.)?(?:seznam\.cz/zpravy|seznamzpravy\.cz)/iframe/player\?.*\bsrc='
25 'url': r'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',
26 'params': {'skip_download': True}, # 'file_minsize': 1586 seems to get killed in test_download.py
30 'title': 'Svět bez obalu: Čeští vojáci na misích (krátká verze)',
34 def _extract_sdn_formats(self, sdn_url, video_id):
35 sdn_data = self._download_json(sdn_url, video_id)
37 mp4_formats = try_get(sdn_data, lambda x: x['data']['mp4'], dict) or {}
38 for fmt, fmtdata in mp4_formats.items():
39 relative_url = fmtdata.get('url')
44 width, height = fmtdata.get('resolution')
45 except (TypeError, ValueError):
46 width, height = None, None
50 'width': int_or_none(width),
51 'height': int_or_none(height),
52 'url': urljoin(sdn_url, relative_url),
53 'vcodec': fmtdata.get('codec'),
54 'tbr': int_or_none(fmtdata.get('bandwidth'), scale=1000),
55 'duration': int_or_none(fmtdata.get('duration'), scale=1000),
58 playlists = sdn_data.get('pls', {})
59 dash_rel_url = try_get(playlists, lambda x: x['dash']['url'], compat_str)
61 formats.extend(self._extract_mpd_formats(urljoin(sdn_url, dash_rel_url), video_id, mpd_id='dash', fatal=False))
63 hls_rel_url = try_get(playlists, lambda x: x['hls']['url'], compat_str)
65 formats.extend(self._extract_m3u8_formats(urljoin(sdn_url, hls_rel_url), video_id, ext='mp4', m3u8_id='hls', fatal=False))
67 self._sort_formats(formats)
70 def _real_extract(self, url):
71 params = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
72 src = params['src'][0]
73 video_id = params.get('contentId', [_raw_id(src)])[0]
77 'title': params['title'][0],
78 'formats': self._extract_sdn_formats(src + 'spl2,2,VOD', video_id),
82 class SeznamZpravyArticleIE(InfoExtractor):
83 _VALID_URL = r'https?://(?:www\.)?(?:seznam\.cz/zpravy|seznamzpravy\.cz)/clanek/(?:[-a-z0-9]+)-(?P<id>[0-9]+)'
84 _API_URL = 'https://apizpravy.seznam.cz/'
87 # two videos on one page, with SDN URL
88 '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',
89 'params': {'skip_download': True},
90 # ^ this is here instead of 'file_minsize': 1586, which does not work because
91 # test_download.py forces expected_minsize to at least 10k when test is running
95 'title': 'Svět bez obalu: Čeští vojáci na misích (krátká verze)',
98 # video with live stream URL
99 'url': 'https://www.seznam.cz/zpravy/clanek/znovu-do-vlady-s-ano-pavel-belobradek-ve-volebnim-specialu-seznamu-38489',
103 'title': 'Předseda KDU-ČSL Pavel Bělobrádek ve volební Výzvě Seznamu',
107 def _extract_caption(self, api_data, article_id):
108 title = api_data.get('title') or api_data.get('captionTitle')
109 caption = api_data.get('caption')
110 if not title or not caption:
113 if 'sdn' in caption.get('video', {}):
114 src_url = caption['video']['sdn']
115 elif 'liveStreamUrl' in caption:
116 src_url = self._download_json(caption['liveStreamUrl'], article_id)['Location']
121 'id': caption.get('uid'),
122 'title': caption.get('title'),
126 def _extract_content(self, api_data):
128 for item in api_data.get('content', []):
129 media = item.get('properties', {}).get('media', {})
130 src_url = media.get('video', {}).get('sdn')
131 title = media.get('title')
132 if not src_url or not title:
136 'id': media.get('uid'),
143 def _iframe_result(self, info_dict):
144 video_id = info_dict['id'] or _raw_id(info_dict['src'])
145 url = update_url_query('https://www.seznam.cz/zpravy/iframe/player', {
146 'src': info_dict['src'],
147 'title': info_dict['title'],
148 'contentId': video_id,
149 'serviceName': 'Seznam Zprávy',
151 return self.url_result(url, ie='SeznamZpravy', video_id=video_id, video_title=info_dict['title'])
153 def _real_extract(self, url):
154 article_id = self._match_id(url)
155 api_data = self._download_json(self._API_URL + 'v1/documents/' + article_id, article_id)
157 caption = self._extract_caption(api_data, article_id)
158 content = self._extract_content(api_data)
160 if caption and not content:
161 return self._iframe_result(caption)
164 content.insert(0, caption)
165 return self.playlist_result(
166 [self._iframe_result(x) for x in content],
167 playlist_id=article_id,
168 playlist_title=api_data.get('title') or caption.get('title')