mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-25 18:12:08 +00:00
Compare commits
No commits in common. "bf23bc0489cf304b2a8ab756f2f63b2cfa5586fe" and "74f8cc48afa59e1a125f939c060b21654d29789c" have entirely different histories.
bf23bc0489
...
74f8cc48af
@ -1,126 +1,105 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import hashlib
|
||||||
import re
|
import time
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
float_or_none,
|
|
||||||
int_or_none,
|
int_or_none,
|
||||||
merge_dicts,
|
sanitized_Request,
|
||||||
parse_codecs,
|
|
||||||
urljoin,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_api_key(api_path):
|
||||||
|
if api_path.endswith('?'):
|
||||||
|
api_path = api_path[:-1]
|
||||||
|
|
||||||
|
api_key = 'fb5f58a820353bd7095de526253c14fd'
|
||||||
|
a = '{0:}{1:}{2:}'.format(api_key, api_path, int(round(time.time() / 24 / 3600)))
|
||||||
|
return hashlib.md5(a.encode('ascii')).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
class StreamCZIE(InfoExtractor):
|
class StreamCZIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?(?:stream|televizeseznam)\.cz/[^?#]+/(?P<display_id>[^?#]+)-(?P<id>[0-9]+)'
|
_VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<id>[0-9]+)'
|
||||||
|
_API_URL = 'http://www.stream.cz/API'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.televizeseznam.cz/video/lajna/buh-57953890',
|
'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti',
|
||||||
'md5': '40c41ade1464a390a0b447e333df4239',
|
'md5': '934bb6a6d220d99c010783c9719960d5',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '57953890',
|
'id': '765767',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Bůh',
|
'title': 'Peklo na talíři: Éčka pro děti',
|
||||||
'display_id': 'buh',
|
'description': 'Taška s grónskou pomazánkou a další pekelnosti ZDE',
|
||||||
'description': 'md5:8f5f09b9b7bc67df910486cdd88f7165',
|
'thumbnail': 're:^http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
|
||||||
'duration': 1369.6,
|
'duration': 256,
|
||||||
'view_count': int,
|
},
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.stream.cz/kdo-to-mluvi/kdo-to-mluvi-velke-odhaleni-prinasi-novy-porad-uz-od-25-srpna-64087937',
|
'url': 'http://www.stream.cz/blanik/10002447-tri-roky-pro-mazanka',
|
||||||
'md5': '41fd358000086a1ccdb068c77809b158',
|
'md5': '849a88c1e1ca47d41403c2ba5e59e261',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '64087937',
|
'id': '10002447',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Kdo to mluví? Velké odhalení přináší nový pořad už od 25. srpna',
|
'title': 'Kancelář Blaník: Tři roky pro Mazánka',
|
||||||
'display_id': 'kdo-to-mluvi-velke-odhaleni-prinasi-novy-porad-uz-od-25-srpna',
|
'description': 'md5:3862a00ba7bf0b3e44806b544032c859',
|
||||||
'description': 'md5:97a811000a6460266029d6c1c2ebcd59',
|
'thumbnail': 're:^http://im.stream.cz/episode/537f838c50c11f8d21320000',
|
||||||
'duration': 50.2,
|
'duration': 368,
|
||||||
'view_count': int,
|
},
|
||||||
}
|
|
||||||
}, {
|
|
||||||
'url': 'https://www.stream.cz/tajemno/znicehonic-jim-skrz-strechu-prolitnul-zahadny-predmet-badatele-vse-objasnili-64147267',
|
|
||||||
'md5': '3ee4d0be040e8f4a543e67e509d55e3f',
|
|
||||||
'info_dict': {
|
|
||||||
'id': '64147267',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'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',
|
|
||||||
'description': 'md5:4b8ada6718d34bb011c4e04ca4bc19bf',
|
|
||||||
'duration': 442.84,
|
|
||||||
'view_count': int,
|
|
||||||
}
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _extract_formats(self, spl_url, video):
|
|
||||||
for ext, pref, streams in (
|
|
||||||
('ts', -1, video.get('http_stream', {}).get('qualities', {})),
|
|
||||||
('mp4', 1, video.get('mp4'))):
|
|
||||||
for format_id, stream in streams.items():
|
|
||||||
if not stream.get('url'):
|
|
||||||
continue
|
|
||||||
yield merge_dicts({
|
|
||||||
'format_id': '{}-{}'.format(format_id, ext),
|
|
||||||
'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),
|
|
||||||
'width': stream.get('resolution', 2 * [0])[0] or None,
|
|
||||||
'height': stream.get('resolution', 2 * [0])[1] or int_or_none(format_id.replace('p', '')),
|
|
||||||
}, parse_codecs(stream.get('codec')))
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id, video_id = re.match(self._VALID_URL, url).groups()
|
video_id = self._match_id(url)
|
||||||
|
api_path = '/episode/%s' % video_id
|
||||||
|
|
||||||
data = self._download_json(
|
req = sanitized_Request(self._API_URL + api_path)
|
||||||
'https://www.televizeseznam.cz/api/graphql', video_id, 'Downloading GraphQL result',
|
req.add_header('Api-Password', _get_api_key(api_path))
|
||||||
data=json.dumps({
|
data = self._download_json(req, video_id)
|
||||||
'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']
|
|
||||||
|
|
||||||
spl_url = data['spl'] + 'spl2,3'
|
formats = []
|
||||||
metadata = self._download_json(spl_url, video_id, 'Downloading playlist')
|
for quality, video in enumerate(data['video_qualities']):
|
||||||
if 'Location' in metadata and 'data' not in metadata:
|
for f in video['formats']:
|
||||||
spl_url = metadata['Location']
|
typ = f['type'].partition('/')[2]
|
||||||
metadata = self._download_json(spl_url, video_id, 'Downloading redirected playlist')
|
qlabel = video.get('quality_label')
|
||||||
video = metadata['data']
|
formats.append({
|
||||||
|
'format_note': '%s-%s' % (qlabel, typ) if qlabel else typ,
|
||||||
|
'format_id': '%s-%s' % (typ, f['quality']),
|
||||||
|
'url': f['source'],
|
||||||
|
'height': int_or_none(f['quality'].rstrip('p')),
|
||||||
|
'quality': quality,
|
||||||
|
})
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
image = data.get('image')
|
||||||
|
if image:
|
||||||
|
thumbnail = self._proto_relative_url(
|
||||||
|
image.replace('{width}', '1240').replace('{height}', '697'),
|
||||||
|
scheme='http:',
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
thumbnail = None
|
||||||
|
|
||||||
|
stream = data.get('_embedded', {}).get('stream:show', {}).get('name')
|
||||||
|
if stream:
|
||||||
|
title = '%s: %s' % (stream, data['name'])
|
||||||
|
else:
|
||||||
|
title = data['name']
|
||||||
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for subs in video.get('subtitles', {}).values():
|
srt_url = data.get('subtitles_srt')
|
||||||
if not subs.get('language'):
|
if srt_url:
|
||||||
continue
|
subtitles['cs'] = [{
|
||||||
for ext, sub_url in subs.get('urls').items():
|
'ext': 'srt',
|
||||||
subtitles.setdefault(subs['language'], []).append({
|
'url': srt_url,
|
||||||
'ext': ext,
|
}]
|
||||||
'url': urljoin(spl_url, sub_url)
|
|
||||||
})
|
|
||||||
|
|
||||||
formats = list(self._extract_formats(spl_url, video))
|
|
||||||
self._sort_formats(formats)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'title': title,
|
||||||
'title': data.get('name'),
|
'thumbnail': thumbnail,
|
||||||
'description': data.get('perex'),
|
|
||||||
'duration': float_or_none(data.get('duration')),
|
|
||||||
'view_count': int_or_none(data.get('views')),
|
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
|
'description': data.get('web_site_text'),
|
||||||
|
'duration': int_or_none(data.get('duration')),
|
||||||
|
'view_count': int_or_none(data.get('views')),
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user