2016-10-02 20:39:18 +09:00
|
|
|
# coding: utf-8
|
2022-02-12 23:27:10 +09:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2022-01-12 01:56:18 +09:00
|
|
|
import json
|
2022-02-12 19:55:13 +09:00
|
|
|
import re
|
2015-02-15 00:48:04 +09:00
|
|
|
|
2014-02-10 02:37:12 +09:00
|
|
|
from .common import InfoExtractor
|
2014-05-25 07:30:15 +09:00
|
|
|
from ..utils import (
|
2022-01-12 01:56:18 +09:00
|
|
|
float_or_none,
|
2014-05-25 07:30:15 +09:00
|
|
|
int_or_none,
|
2022-02-12 23:02:08 +09:00
|
|
|
merge_dicts,
|
2022-01-12 01:56:18 +09:00
|
|
|
parse_codecs,
|
|
|
|
urljoin,
|
2014-05-25 07:30:15 +09:00
|
|
|
)
|
2014-02-10 02:37:12 +09:00
|
|
|
|
|
|
|
|
|
|
|
class StreamCZIE(InfoExtractor):
|
2022-01-12 01:56:18 +09:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?(?:stream|televizeseznam)\.cz/[^?#]+/(?P<display_id>[^?#]+)-(?P<id>[0-9]+)'
|
2014-05-24 23:01:37 +09:00
|
|
|
_TESTS = [{
|
2022-01-12 01:56:18 +09:00
|
|
|
'url': 'https://www.televizeseznam.cz/video/lajna/buh-57953890',
|
|
|
|
'md5': '40c41ade1464a390a0b447e333df4239',
|
2014-02-10 02:37:12 +09:00
|
|
|
'info_dict': {
|
2022-01-12 01:56:18 +09:00
|
|
|
'id': '57953890',
|
2014-02-10 02:37:12 +09:00
|
|
|
'ext': 'mp4',
|
2022-01-12 01:56:18 +09:00
|
|
|
'title': 'Bůh',
|
|
|
|
'display_id': 'buh',
|
|
|
|
'description': 'md5:8f5f09b9b7bc67df910486cdd88f7165',
|
2022-02-12 21:13:20 +09:00
|
|
|
'duration': 1369.6,
|
|
|
|
'view_count': int,
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.stream.cz/kdo-to-mluvi/kdo-to-mluvi-velke-odhaleni-prinasi-novy-porad-uz-od-25-srpna-64087937',
|
|
|
|
'md5': '41fd358000086a1ccdb068c77809b158',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '64087937',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Kdo to mluví? Velké odhalení přináší nový pořad už od 25. srpna',
|
|
|
|
'display_id': 'kdo-to-mluvi-velke-odhaleni-prinasi-novy-porad-uz-od-25-srpna',
|
|
|
|
'description': 'md5:97a811000a6460266029d6c1c2ebcd59',
|
|
|
|
'duration': 50.2,
|
|
|
|
'view_count': int,
|
2022-01-12 01:56:18 +09:00
|
|
|
}
|
2014-05-24 23:01:37 +09:00
|
|
|
}, {
|
2022-01-12 01:56:18 +09:00
|
|
|
'url': 'https://www.stream.cz/tajemno/znicehonic-jim-skrz-strechu-prolitnul-zahadny-predmet-badatele-vse-objasnili-64147267',
|
|
|
|
'md5': '3ee4d0be040e8f4a543e67e509d55e3f',
|
2014-05-24 23:01:37 +09:00
|
|
|
'info_dict': {
|
2022-01-12 01:56:18 +09:00
|
|
|
'id': '64147267',
|
2014-05-24 23:01:37 +09:00
|
|
|
'ext': 'mp4',
|
2022-01-12 01:56:18 +09:00
|
|
|
'title': 'Zničehonic jim skrz střechu prolítnul záhadný předmět. Badatelé vše objasnili',
|
|
|
|
'display_id': 'znicehonic-jim-skrz-strechu-prolitnul-zahadny-predmet-badatele-vse-objasnili',
|
2022-02-12 21:13:20 +09:00
|
|
|
'description': 'md5:4b8ada6718d34bb011c4e04ca4bc19bf',
|
|
|
|
'duration': 442.84,
|
|
|
|
'view_count': int,
|
2022-01-12 01:56:18 +09:00
|
|
|
}
|
2014-05-24 23:01:37 +09:00
|
|
|
}]
|
2014-02-10 02:37:12 +09:00
|
|
|
|
2022-01-12 01:56:18 +09:00
|
|
|
def _extract_formats(self, spl_url, video):
|
|
|
|
for ext, pref, streams in (
|
2022-02-12 20:28:30 +09:00
|
|
|
('ts', -1, video.get('http_stream', {}).get('qualities', {})),
|
2022-01-12 01:56:18 +09:00
|
|
|
('mp4', 1, video.get('mp4'))):
|
|
|
|
for format_id, stream in streams.items():
|
|
|
|
if not stream.get('url'):
|
|
|
|
continue
|
2022-02-12 23:02:08 +09:00
|
|
|
yield merge_dicts({
|
2022-04-29 21:36:02 +09:00
|
|
|
'format_id': '-'.join((format_id, ext)),
|
2022-01-12 01:56:18 +09:00
|
|
|
'ext': ext,
|
|
|
|
'source_preference': pref,
|
|
|
|
'url': urljoin(spl_url, stream['url']),
|
|
|
|
'tbr': float_or_none(stream.get('bandwidth'), scale=1000),
|
|
|
|
'duration': float_or_none(stream.get('duration'), scale=1000),
|
2022-02-12 20:28:30 +09:00
|
|
|
'width': stream.get('resolution', 2 * [0])[0] or None,
|
|
|
|
'height': stream.get('resolution', 2 * [0])[1] or int_or_none(format_id.replace('p', '')),
|
2022-02-12 23:02:08 +09:00
|
|
|
}, parse_codecs(stream.get('codec')))
|
2014-02-10 02:37:12 +09:00
|
|
|
|
2022-01-12 01:56:18 +09:00
|
|
|
def _real_extract(self, url):
|
2022-02-12 19:55:13 +09:00
|
|
|
display_id, video_id = re.match(self._VALID_URL, url).groups()
|
2014-02-10 02:37:12 +09:00
|
|
|
|
2022-01-12 01:56:18 +09:00
|
|
|
data = self._download_json(
|
|
|
|
'https://www.televizeseznam.cz/api/graphql', video_id, 'Downloading GraphQL result',
|
|
|
|
data=json.dumps({
|
|
|
|
'variables': {'urlName': video_id},
|
|
|
|
'query': '''
|
|
|
|
query LoadEpisode($urlName : String){ episode(urlName: $urlName){ ...VideoDetailFragmentOnEpisode } }
|
|
|
|
fragment VideoDetailFragmentOnEpisode on Episode {
|
|
|
|
id
|
|
|
|
spl
|
|
|
|
urlName
|
|
|
|
name
|
|
|
|
perex
|
|
|
|
duration
|
|
|
|
views
|
|
|
|
}'''
|
|
|
|
}).encode('utf-8'),
|
|
|
|
headers={'Content-Type': 'application/json;charset=UTF-8'}
|
|
|
|
)['data']['episode']
|
2014-12-13 20:14:44 +09:00
|
|
|
|
2022-01-12 01:56:18 +09:00
|
|
|
spl_url = data['spl'] + 'spl2,3'
|
|
|
|
metadata = self._download_json(spl_url, video_id, 'Downloading playlist')
|
|
|
|
if 'Location' in metadata and 'data' not in metadata:
|
|
|
|
spl_url = metadata['Location']
|
|
|
|
metadata = self._download_json(spl_url, video_id, 'Downloading redirected playlist')
|
|
|
|
video = metadata['data']
|
2014-12-13 20:14:44 +09:00
|
|
|
|
2017-05-21 17:41:52 +09:00
|
|
|
subtitles = {}
|
2022-01-12 01:56:18 +09:00
|
|
|
for subs in video.get('subtitles', {}).values():
|
|
|
|
if not subs.get('language'):
|
|
|
|
continue
|
|
|
|
for ext, sub_url in subs.get('urls').items():
|
|
|
|
subtitles.setdefault(subs['language'], []).append({
|
|
|
|
'ext': ext,
|
|
|
|
'url': urljoin(spl_url, sub_url)
|
|
|
|
})
|
|
|
|
|
|
|
|
formats = list(self._extract_formats(spl_url, video))
|
|
|
|
self._sort_formats(formats)
|
2017-05-21 17:41:52 +09:00
|
|
|
|
2014-02-10 02:37:12 +09:00
|
|
|
return {
|
2014-12-13 20:14:44 +09:00
|
|
|
'id': video_id,
|
2022-01-12 01:56:18 +09:00
|
|
|
'display_id': display_id,
|
|
|
|
'title': data.get('name'),
|
|
|
|
'description': data.get('perex'),
|
|
|
|
'duration': float_or_none(data.get('duration')),
|
2014-12-13 20:14:44 +09:00
|
|
|
'view_count': int_or_none(data.get('views')),
|
2022-01-12 01:56:18 +09:00
|
|
|
'formats': formats,
|
2017-05-21 17:41:52 +09:00
|
|
|
'subtitles': subtitles,
|
2014-02-10 02:37:12 +09:00
|
|
|
}
|