mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-10 00:58:17 +02:00
Merge pull request #149 from RobinD42/fix-subtitle-fallback
fall-back to the old way to fetch subtitles, if needed
This commit is contained in:
commit
7ee5015a34
@ -308,17 +308,26 @@ def _real_extract(self, url):
|
|||||||
'url': thumbnail.get('url'),
|
'url': thumbnail.get('url'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
subtitles = {}
|
||||||
|
try:
|
||||||
|
# New way to fetch subtitles
|
||||||
new_video = self._download_json(
|
new_video = self._download_json(
|
||||||
'https://www.viki.com/api/videos/%s' % video_id, video_id,
|
'https://www.viki.com/api/videos/%s' % video_id, video_id,
|
||||||
'Downloading new video JSON to get subtitles', headers={'x-viki-app-ver': '2.2.5.1428709186'}, expected_status=[200, 400, 404])
|
'Downloading new video JSON to get subtitles', headers={'x-viki-app-ver': '2.2.5.1428709186'}, expected_status=[200, 400, 404])
|
||||||
|
|
||||||
subtitles = {}
|
|
||||||
for sub in new_video.get('streamSubtitles').get('dash'):
|
for sub in new_video.get('streamSubtitles').get('dash'):
|
||||||
subtitles[sub.get('srclang')] = [{
|
subtitles[sub.get('srclang')] = [{
|
||||||
'ext': 'vtt',
|
'ext': 'vtt',
|
||||||
'url': sub.get('src'),
|
'url': sub.get('src'),
|
||||||
'completion': sub.get('percentage'),
|
'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', {}).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,
|
||||||
|
Loading…
Reference in New Issue
Block a user