[seznamzpravy] Parse multiple videos
Also use primarily title instead of captionTitle
This commit is contained in:
parent
defcd753ef
commit
255491dda7
@ -14,7 +14,7 @@ class SeznamZpravyIE(InfoExtractor):
|
|||||||
_MAGIC_SUFFIX = 'spl2,2,VOD'
|
_MAGIC_SUFFIX = 'spl2,2,VOD'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# video with SDN URL
|
# two videos on one page, with SDN URL
|
||||||
'url': 'https://www.seznam.cz/zpravy/clanek/jejich-svet-na-nas-utoci-je-lepsi-branit-se-na-jejich-pisecku-rika-reziser-a-major-v-zaloze-marhoul-35990',
|
'url': 'https://www.seznam.cz/zpravy/clanek/jejich-svet-na-nas-utoci-je-lepsi-branit-se-na-jejich-pisecku-rika-reziser-a-major-v-zaloze-marhoul-35990',
|
||||||
'params': {'skip_download': True},
|
'params': {'skip_download': True},
|
||||||
# ^ this is here instead of 'file_minsize': 1586, which does not work because
|
# ^ this is here instead of 'file_minsize': 1586, which does not work because
|
||||||
@ -22,7 +22,7 @@ class SeznamZpravyIE(InfoExtractor):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '35990',
|
'id': '35990',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Svět bez obalu: Rozhovor s Václavem Marhoulem o zahraničních vojenských misích a aktivních zálohách.',
|
'title': 'Jejich svět na nás útočí. Je lepší bránit se na jejich písečku, říká režisér a major v záloze Marhoul',
|
||||||
'description': 'O nasazení českých vojáků v zahraničí. Marhoul by na mise posílal i zálohy. „Nejdříve se ale musí vycvičit,“ říká.',
|
'description': 'O nasazení českých vojáků v zahraničí. Marhoul by na mise posílal i zálohy. „Nejdříve se ale musí vycvičit,“ říká.',
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@ -31,21 +31,12 @@ class SeznamZpravyIE(InfoExtractor):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '38489',
|
'id': '38489',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Předseda KDU-ČSL Pavel Bělobrádek ve volební Výzvě Seznamu.',
|
'title': 'ČSSD a ANO nás s elektronickou evidencí podrazily, říká šéf lidovců',
|
||||||
'description': 'Předvolební rozhovory s lídry deseti hlavních stran pokračují. Ve Výzvě Jindřicha Šídla odpovídal předseda lidovců Pavel Bělobrádek.',
|
'description': 'Předvolební rozhovory s lídry deseti hlavních stran pokračují. Ve Výzvě Jindřicha Šídla odpovídal předseda lidovců Pavel Bělobrádek.',
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _extract_sdn_formats(self, sdn_url, video_id):
|
||||||
video_id = self._match_id(url)
|
|
||||||
data = self._download_json(self._API_URL + 'v1/documents/' + video_id, video_id)
|
|
||||||
title = data['captionTitle']
|
|
||||||
|
|
||||||
if 'video' in data['caption']:
|
|
||||||
sdn_url = data['caption']['video']['sdn'] + self._MAGIC_SUFFIX
|
|
||||||
else:
|
|
||||||
sdn_url = self._download_json(data['caption']['liveStreamUrl'] + self._MAGIC_SUFFIX, video_id)['Location']
|
|
||||||
|
|
||||||
sdn_data = self._download_json(sdn_url, video_id)
|
sdn_data = self._download_json(sdn_url, video_id)
|
||||||
formats = []
|
formats = []
|
||||||
for fmt, fmtdata in sdn_data.get('data', {}).get('mp4', {}).items():
|
for fmt, fmtdata in sdn_data.get('data', {}).get('mp4', {}).items():
|
||||||
@ -75,10 +66,65 @@ class SeznamZpravyIE(InfoExtractor):
|
|||||||
formats.extend(self._extract_m3u8_formats(urljoin(sdn_url, hls_rel_url), video_id, ext='mp4', m3u8_id='hls', fatal=False))
|
formats.extend(self._extract_m3u8_formats(urljoin(sdn_url, hls_rel_url), video_id, ext='mp4', m3u8_id='hls', fatal=False))
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
return formats
|
||||||
|
|
||||||
return {
|
def _extract_caption(self, api_data, video_id):
|
||||||
'id': video_id,
|
title = api_data.get('title') or api_data.get('captionTitle')
|
||||||
'title': title,
|
caption = api_data.get('caption')
|
||||||
'description': data.get('perex'),
|
if not title or not caption:
|
||||||
'formats': formats,
|
return {}
|
||||||
}
|
|
||||||
|
if 'sdn' in caption.get('video', {}):
|
||||||
|
sdn_url = caption['video']['sdn'] + self._MAGIC_SUFFIX
|
||||||
|
elif 'liveStreamUrl' in caption:
|
||||||
|
sdn_url = self._download_json(caption['liveStreamUrl'] + self._MAGIC_SUFFIX, video_id)['Location']
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
formats = self._extract_sdn_formats(sdn_url, video_id)
|
||||||
|
if formats:
|
||||||
|
return {
|
||||||
|
'id': video_id,
|
||||||
|
'title': title,
|
||||||
|
'description': api_data.get('perex'),
|
||||||
|
'display_id': api_data.get('slug'),
|
||||||
|
'formats': formats,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _extract_content(self, api_data, video_id):
|
||||||
|
entries = []
|
||||||
|
for num, item in enumerate(api_data.get('content', [])):
|
||||||
|
media = item.get('properties', {}).get('media', {})
|
||||||
|
sdn_url_part = media.get('video', {}).get('sdn')
|
||||||
|
title = media.get('title')
|
||||||
|
if not sdn_url_part or not title:
|
||||||
|
continue
|
||||||
|
|
||||||
|
entry_id = '%s-%s' % (video_id, num)
|
||||||
|
formats = self._extract_sdn_formats(sdn_url_part + self._MAGIC_SUFFIX, entry_id)
|
||||||
|
if formats:
|
||||||
|
entries.append({
|
||||||
|
'id': entry_id,
|
||||||
|
'title': title,
|
||||||
|
'formats': formats,
|
||||||
|
})
|
||||||
|
|
||||||
|
return entries
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
video_id = self._match_id(url)
|
||||||
|
api_data = self._download_json(self._API_URL + 'v1/documents/' + video_id, video_id)
|
||||||
|
|
||||||
|
caption = self._extract_caption(api_data, video_id)
|
||||||
|
content = self._extract_content(api_data, video_id)
|
||||||
|
|
||||||
|
if caption and not content:
|
||||||
|
return caption
|
||||||
|
else:
|
||||||
|
if caption:
|
||||||
|
content.insert(0, caption)
|
||||||
|
return {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'entries': content,
|
||||||
|
'title': caption.get('title'),
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user