mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-29 18:51:24 +01:00
Compare commits
No commits in common. "ca29e999b013d8e508759ec38e6770628a89e106" and "2e124ee0a9a1b9c8275d61736882ea0adf93ac58" have entirely different histories.
ca29e999b0
...
2e124ee0a9
|
@ -1649,6 +1649,7 @@ class BiliIntlBaseIE(InfoExtractor):
|
|||
return data
|
||||
|
||||
def _get_subtitles(self, *, ep_id=None, aid=None):
|
||||
subtitles = {}
|
||||
sub_json = self._call_api(
|
||||
'/web/v2/subtitle', ep_id or aid, fatal=False,
|
||||
note='Downloading subtitles list', errnote='Unable to download subtitles list',
|
||||
|
@ -1658,34 +1659,43 @@ class BiliIntlBaseIE(InfoExtractor):
|
|||
'episode_id': ep_id,
|
||||
'aid': aid,
|
||||
})) or {}
|
||||
subtitles = {}
|
||||
fetched_urls = set()
|
||||
for sub in traverse_obj(sub_json, (('subtitles', 'video_subtitle'), ..., {dict})):
|
||||
for url in traverse_obj(sub, ((None, 'ass', 'srt'), 'url', {url_or_none})):
|
||||
if url in fetched_urls:
|
||||
continue
|
||||
fetched_urls.add(url)
|
||||
sub_ext = determine_ext(url)
|
||||
sub_lang = sub.get('lang_key') or 'en'
|
||||
|
||||
if sub_ext == 'ass':
|
||||
for sub in traverse_obj(sub_json, ('subtitles', lambda _, v: v['url'])):
|
||||
sub_ext = determine_ext(sub['url'])
|
||||
sub_lang = sub.get('lang_key') or 'en'
|
||||
|
||||
sub_data = self._download_webpage(
|
||||
sub['url'], ep_id or aid, fatal=False,
|
||||
encoding='utf-8-sig' if sub_ext == 'ass' else None,
|
||||
note=f'Downloading subtitles{format_field(sub, "lang", " for %s")} ({sub_lang})',
|
||||
errnote='Unable to download subtitles')
|
||||
if sub_ext != 'ass':
|
||||
sub_ext, sub_data = 'srt', self.json2srt(sub_data)
|
||||
|
||||
if sub_data:
|
||||
subtitles.setdefault(sub_lang, []).append({
|
||||
'ext': sub_ext,
|
||||
'data': sub_data
|
||||
})
|
||||
|
||||
for sub in traverse_obj(sub_json, ('video_subtitle', ..., {dict})):
|
||||
sub_lang = sub.get('lang_key') or 'en'
|
||||
if sub.get('ass'):
|
||||
subtitles.setdefault(sub_lang, []).append({
|
||||
'ext': 'ass',
|
||||
'url': traverse_obj(sub, ('ass', 'url'))
|
||||
})
|
||||
|
||||
if sub.get('srt'):
|
||||
sub_data = self._download_json(
|
||||
traverse_obj(sub, ('srt', 'url')), ep_id or aid, fatal=False,
|
||||
note=f'Downloading subtitles{format_field(sub, "lang", " for %s")} ({sub_lang})',
|
||||
errnote='Unable to download subtitles')
|
||||
if sub_data:
|
||||
subtitles.setdefault(sub_lang, []).append({
|
||||
'ext': 'ass',
|
||||
'url': url,
|
||||
'ext': 'srt',
|
||||
'data': self.json2srt(sub_data)
|
||||
})
|
||||
elif sub_ext == 'json':
|
||||
sub_data = self._download_json(
|
||||
url, ep_id or aid, fatal=False,
|
||||
note=f'Downloading subtitles{format_field(sub, "lang", " for %s")} ({sub_lang})',
|
||||
errnote='Unable to download subtitles')
|
||||
|
||||
if sub_data:
|
||||
subtitles.setdefault(sub_lang, []).append({
|
||||
'ext': 'srt',
|
||||
'data': self.json2srt(sub_data),
|
||||
})
|
||||
else:
|
||||
self.report_warning('Unexpected subtitle extension', ep_id or aid)
|
||||
|
||||
return subtitles
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user