[ie/facebook] Support more groups URLs (#11576)
[yt-dlp3.git] / yt_dlp / extractor / seznamzpravy.py
blob6f2bfcd27f513bdea98c2e97c3c7060b0c09d093
1 import urllib.parse
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 parse_codecs,
7 parse_qs,
8 try_get,
9 urljoin,
13 def _raw_id(src_url):
14 return urllib.parse.urlparse(src_url).path.split('/')[-1]
17 class SeznamZpravyIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?seznamzpravy\.cz/iframe/player\?.*\bsrc='
19 _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?seznamzpravy\.cz/iframe/player\?.*?)\1']
20 _TESTS = [{
21 '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&sectionPrefixPreroll=%2Fzpravy',
22 'info_dict': {
23 'id': '170889',
24 'ext': 'mp4',
25 'title': 'Svět bez obalu: Čeští vojáci na misích (krátká verze)',
26 'thumbnail': r're:^https?://.*\.jpe?g',
27 'duration': 241,
28 'series': 'Svět bez obalu',
30 'params': {
31 'skip_download': True,
33 }, {
34 # with Location key
35 '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&sectionPrefixPreroll=%2Fzpravy%2Fvyzva&zoneIdPostroll=seznam.pack.videospot&skipOffsetPostroll=5&sectionPrefixPostroll=%2Fzpravy%2Fvyzva&regression=false',
36 'info_dict': {
37 'id': '185688',
38 'ext': 'mp4',
39 'title': 'Předseda KDU-ČSL Pavel Bělobrádek ve volební Výzvě Seznamu',
40 'thumbnail': r're:^https?://.*\.jpe?g',
41 'series': 'Výzva',
43 'params': {
44 'skip_download': True,
48 def _extract_sdn_formats(self, sdn_url, video_id):
49 sdn_data = self._download_json(sdn_url, video_id)
51 if sdn_data.get('Location'):
52 sdn_url = sdn_data['Location']
53 sdn_data = self._download_json(sdn_url, video_id)
55 formats = []
56 mp4_formats = try_get(sdn_data, lambda x: x['data']['mp4'], dict) or {}
57 for format_id, format_data in mp4_formats.items():
58 relative_url = format_data.get('url')
59 if not relative_url:
60 continue
62 try:
63 width, height = format_data.get('resolution')
64 except (TypeError, ValueError):
65 width, height = None, None
67 f = {
68 'url': urljoin(sdn_url, relative_url),
69 'format_id': f'http-{format_id}',
70 'tbr': int_or_none(format_data.get('bandwidth'), scale=1000),
71 'width': int_or_none(width),
72 'height': int_or_none(height),
74 f.update(parse_codecs(format_data.get('codec')))
75 formats.append(f)
77 pls = sdn_data.get('pls', {})
79 def get_url(format_id):
80 return try_get(pls, lambda x: x[format_id]['url'], str)
82 dash_rel_url = get_url('dash')
83 if dash_rel_url:
84 formats.extend(self._extract_mpd_formats(
85 urljoin(sdn_url, dash_rel_url), video_id, mpd_id='dash',
86 fatal=False))
88 hls_rel_url = get_url('hls')
89 if hls_rel_url:
90 formats.extend(self._extract_m3u8_formats(
91 urljoin(sdn_url, hls_rel_url), video_id, ext='mp4',
92 m3u8_id='hls', fatal=False))
94 return formats
96 def _real_extract(self, url):
97 params = parse_qs(url)
99 src = params['src'][0]
100 title = params['title'][0]
101 video_id = params.get('contentId', [_raw_id(src)])[0]
102 formats = self._extract_sdn_formats(src + 'spl2,2,VOD', video_id)
104 duration = int_or_none(params.get('duration', [None])[0])
105 series = params.get('series', [None])[0]
106 thumbnail = params.get('poster', [None])[0]
108 return {
109 'id': video_id,
110 'title': title,
111 'thumbnail': thumbnail,
112 'duration': duration,
113 'series': series,
114 'formats': formats,
118 class SeznamZpravyArticleIE(InfoExtractor):
119 _VALID_URL = r'https?://(?:www\.)?(?:seznam\.cz/zpravy|seznamzpravy\.cz)/clanek/(?:[^/?#&]+)-(?P<id>\d+)'
120 _API_URL = 'https://apizpravy.seznam.cz/'
122 _TESTS = [{
123 # two videos on one page, with SDN URL
124 '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',
125 'info_dict': {
126 'id': '35990',
127 'title': 'md5:6011c877a36905f28f271fcd8dcdb0f2',
128 'description': 'md5:933f7b06fa337a814ba199d3596d27ba',
130 'playlist_count': 2,
131 }, {
132 # video with live stream URL
133 'url': 'https://www.seznam.cz/zpravy/clanek/znovu-do-vlady-s-ano-pavel-belobradek-ve-volebnim-specialu-seznamu-38489',
134 'info_dict': {
135 'id': '38489',
136 'title': 'md5:8fa1afdc36fd378cf0eba2b74c5aca60',
137 'description': 'md5:428e7926a1a81986ec7eb23078004fb4',
139 'playlist_count': 1,
142 def _real_extract(self, url):
143 article_id = self._match_id(url)
145 webpage = self._download_webpage(url, article_id)
147 info = self._search_json_ld(webpage, article_id, default={})
149 title = info.get('title') or self._og_search_title(webpage, fatal=False)
150 description = info.get('description') or self._og_search_description(webpage)
152 return self.playlist_result([
153 self.url_result(entry_url, ie=SeznamZpravyIE.ie_key())
154 for entry_url in SeznamZpravyIE._extract_embed_urls(url, webpage)],
155 article_id, title, description)