diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 1cab440f4..d7d1bc7ea 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -1110,6 +1110,7 @@ from .telequebec import ( TeleQuebecLiveIE, ) from .teletask import TeleTaskIE +from .televizeseznam import TelevizeSeznamIE from .telewebion import TelewebionIE from .tennistv import TennisTVIE from .tenplay import TenPlayIE diff --git a/youtube_dl/extractor/televizeseznam.py b/youtube_dl/extractor/televizeseznam.py new file mode 100644 index 000000000..21aef878f --- /dev/null +++ b/youtube_dl/extractor/televizeseznam.py @@ -0,0 +1,85 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import json + +from .common import InfoExtractor +from ..compat import compat_urlparse + + +class TelevizeSeznamIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?televizeseznam\.cz/video/.+/(?P.+)' + + _API_BASE = 'https://www.televizeseznam.cz' + _GRAPHQL_URL = '%s/api/graphql' % _API_BASE + _GRAPHQL_QUERY = '''query LoadEpisode($urlName : String){ episode(urlName: $urlName){ ...VideoDetailFragmentOnEpisode } } + fragment VideoDetailFragmentOnEpisode on Episode { + id + spl + urlName + name + perex + } +''' + + _TEST = { + 'url': 'https://www.televizeseznam.cz/video/lajna/buh-57953890', + 'md5': '40c41ade1464a390a0b447e333df4239', + 'info_dict': { + 'id': 'buh-57953890', + 'title': 'Bůh', + 'ext': 'mp4', + } + } + + def extract_subtitles(self, spl_url, play_list): + + if not play_list: + return None + + subtitles = {} + for k, v in play_list.items(): + subtitles.update({ + v['language']: { + 'ext': 'srt', + 'url': compat_urlparse.urljoin(spl_url, v['urls']['srt']) + } + }) + return subtitles + + def extract_formats(self, spl_url, play_list, subtitles): + formats = [] + for r, v in play_list.items(): + formats.append({ + 'url': compat_urlparse.urljoin(spl_url, v['url']), + 'width': v['resolution'][0], + 'height': v['resolution'][1], + 'resolution': '%sx%s' % (v['resolution'][0], v['resolution'][1]), + 'protocol': 'https', + 'ext': 'mp4', + 'subtitles': subtitles, + }) + return formats + + def _real_extract(self, url): + video_id = self._match_id(url) + + data = self._download_json( + self._GRAPHQL_URL, video_id, 'Downloading GraphQL result', + data=json.dumps({ + 'query': self._GRAPHQL_QUERY, + 'variables': {'urlName': video_id} + }).encode('utf-8'), + headers={'Content-Type': 'application/json;charset=UTF-8'} + )['data'] + + spl_url = data['episode']['spl'] + play_list = self._download_json(spl_url + 'spl2,3', video_id, 'Downloading playlist')['data'] + subtitles = self.extract_subtitles(spl_url, play_list.get('subtitles')) + formats = self.extract_formats(spl_url, play_list['mp4'], subtitles) + + return { + 'id': video_id, + 'title': data['episode'].get('name'), + 'formats': formats + }