1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-13 03:27:15 +08:00

[seznamzpravy] Parse HLS and DASH

Includes extension of generic MPD extractor and few more
fixes per dstftw.
This commit is contained in:
Petr Novak 2017-10-29 21:40:06 +01:00
parent 4d8729978f
commit defcd753ef
2 changed files with 26 additions and 4 deletions

View File

@ -1979,6 +1979,15 @@ class InfoExtractor(object):
}) })
segment_index += 1 segment_index += 1
representation_ms_info['fragments'] = fragments representation_ms_info['fragments'] = fragments
elif 'segment_urls' in representation_ms_info:
# Segment URLs with no SegmentTimeline
# Example: https://www.seznam.cz/zpravy/clanek/cesko-zasahne-vitr-o-sile-vichrice-muze-byt-i-zivotu-nebezpecny-39091
fragments = []
for segment_url in representation_ms_info['segment_urls']:
fragments.append({
location_key(segment_url): segment_url,
})
representation_ms_info['fragments'] = fragments
# NB: MPD manifest may contain direct URLs to unfragmented media. # NB: MPD manifest may contain direct URLs to unfragmented media.
# No fragments key is present in this case. # No fragments key is present in this case.
if 'fragments' in representation_ms_info: if 'fragments' in representation_ms_info:

View File

@ -16,7 +16,9 @@ class SeznamZpravyIE(InfoExtractor):
_TESTS = [{ _TESTS = [{
# video with SDN URL # video 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',
'md5': '855f9fed87bd93e48775d59671a3a3e3', 'params': {'skip_download': True},
# ^ this is here instead of 'file_minsize': 1586, which does not work because
# test_download.py forces expected_minsize to at least 10k when test is running
'info_dict': { 'info_dict': {
'id': '35990', 'id': '35990',
'ext': 'mp4', 'ext': 'mp4',
@ -37,21 +39,23 @@ class SeznamZpravyIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
data = self._download_json(self._API_URL + 'v1/documents/' + video_id, video_id) data = self._download_json(self._API_URL + 'v1/documents/' + video_id, video_id)
title = data['captionTitle']
if 'video' in data['caption']: if 'video' in data['caption']:
sdn_url = data['caption']['video']['sdn'] + self._MAGIC_SUFFIX sdn_url = data['caption']['video']['sdn'] + self._MAGIC_SUFFIX
else: else:
sdn_url = self._download_json(data['caption']['liveStreamUrl'] + self._MAGIC_SUFFIX, video_id)['Location'] sdn_url = self._download_json(data['caption']['liveStreamUrl'] + self._MAGIC_SUFFIX, video_id)['Location']
sdn_data = self._download_json(sdn_url, video_id)
formats = [] formats = []
for fmt, fmtdata in self._download_json(sdn_url, video_id)['data']['mp4'].items(): for fmt, fmtdata in sdn_data.get('data', {}).get('mp4', {}).items():
relative_url = fmtdata.get('url') relative_url = fmtdata.get('url')
if not relative_url: if not relative_url:
continue continue
try: try:
width, height = fmtdata.get('resolution') width, height = fmtdata.get('resolution')
except TypeError: except (TypeError, ValueError):
width, height = None, None width, height = None, None
formats.append({ formats.append({
@ -61,11 +65,20 @@ class SeznamZpravyIE(InfoExtractor):
'url': urljoin(sdn_url, relative_url), 'url': urljoin(sdn_url, relative_url),
}) })
playlists = sdn_data.get('pls', {})
dash_rel_url = playlists.get('dash', {}).get('url')
if dash_rel_url:
formats.extend(self._extract_mpd_formats(urljoin(sdn_url, dash_rel_url), video_id, mpd_id='dash', fatal=False))
hls_rel_url = playlists.get('hls', {}).get('url')
if hls_rel_url:
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 { return {
'id': video_id, 'id': video_id,
'title': data['captionTitle'], 'title': title,
'description': data.get('perex'), 'description': data.get('perex'),
'formats': formats, 'formats': formats,
} }