[viki] Fix viki play pass authentication (#111)

Authored by: RobinD42
This commit is contained in:
Robin Dunn 2021-02-25 14:03:00 -08:00 committed by GitHub
parent 3638226215
commit 31a5e037a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -255,15 +255,8 @@ class VikiIE(VikiBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
resp = self._download_json( video = self._call_api(
'https://www.viki.com/api/videos/' + video_id, 'videos/%s.json' % video_id, video_id, 'Downloading video JSON')
video_id, 'Downloading video JSON', headers={
'x-client-user-agent': std_headers['User-Agent'],
'x-viki-as-id': self._APP,
'x-viki-app-ver': self._APP_VERSION,
})
video = resp['video']
self._check_errors(video) self._check_errors(video)
title = self.dict_selection(video.get('titles', {}), 'en', allow_fallback=False) title = self.dict_selection(video.get('titles', {}), 'en', allow_fallback=False)
@ -286,30 +279,12 @@ def _real_extract(self, url):
}) })
subtitles = {} subtitles = {}
try: for subtitle_lang, _ in (video.get('subtitle_completions') or {}).items():
# New way to fetch subtitles subtitles[subtitle_lang] = [{
new_video = self._download_json( 'ext': subtitles_format,
'https://www.viki.com/api/videos/%s' % video_id, video_id, 'url': self._prepare_call(
'Downloading new video JSON to get subtitles', fatal=False, 'videos/%s/subtitles/%s.%s' % (video_id, subtitle_lang, subtitles_format)),
headers={ } for subtitles_format in ('srt', 'vtt')]
'x-client-user-agent': std_headers['User-Agent'],
'x-viki-as-id': self._APP,
'x-viki-app-ver': self._APP_VERSION,
})
for sub in new_video.get('streamSubtitles').get('dash'):
subtitles[sub.get('srclang')] = [{
'ext': 'vtt',
'url': sub.get('src'),
'completion': sub.get('percentage'),
}]
except AttributeError:
# fall-back to the old way if there isn't a streamSubtitles attribute
for subtitle_lang, _ in (video.get('subtitle_completions') or {}).items():
subtitles[subtitle_lang] = [{
'ext': subtitles_format,
'url': self._prepare_call(
'videos/%s/subtitles/%s.%s' % (video_id, subtitle_lang, subtitles_format)),
} for subtitles_format in ('srt', 'vtt')]
result = { result = {
'id': video_id, 'id': video_id,
@ -386,23 +361,20 @@ def add_format(format_id, format_dict, protocol='http'):
'filesize': int_or_none(urlh.headers.get('Content-Length')), 'filesize': int_or_none(urlh.headers.get('Content-Length')),
}) })
for format_id, format_dict in (resp.get('streams') or {}).items(): streams = self._call_api(
add_format(format_id, format_dict) 'videos/%s/streams.json' % video_id, video_id,
if not formats: 'Downloading video streams JSON')
streams = self._call_api(
'videos/%s/streams.json' % video_id, video_id,
'Downloading video streams JSON')
if 'external' in streams: if 'external' in streams:
result.update({ result.update({
'_type': 'url_transparent', '_type': 'url_transparent',
'url': streams['external']['url'], 'url': streams['external']['url'],
}) })
return result return result
for format_id, stream_dict in streams.items(): for format_id, stream_dict in streams.items():
for protocol, format_dict in stream_dict.items(): for protocol, format_dict in stream_dict.items():
add_format(format_id, format_dict, protocol) add_format(format_id, format_dict, protocol)
self._sort_formats(formats) self._sort_formats(formats)
result['formats'] = formats result['formats'] = formats