aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/extractor/bilibili.py
diff options
context:
space:
mode:
authorLXYan2333 <z00823823@126.com>2023-03-04 22:44:48 +0800
committerGitHub <noreply@github.com>2023-03-04 20:14:48 +0530
commit8a83baaf218ab89e6e7faa76b7c7be3a2ec19e3a (patch)
treec7f4a19f74267454e6d50d94f7acd4e8213541a9 /yt_dlp/extractor/bilibili.py
parent7accdd9845fe7ce9d0aa5a9d16faaa489c1294eb (diff)
downloadhypervideo-pre-8a83baaf218ab89e6e7faa76b7c7be3a2ec19e3a.tar.lz
hypervideo-pre-8a83baaf218ab89e6e7faa76b7c7be3a2ec19e3a.tar.xz
hypervideo-pre-8a83baaf218ab89e6e7faa76b7c7be3a2ec19e3a.zip
[extractor/bilibili] Fix for downloading wrong subtitles (#6358)
Closes #6357 Authored by: LXYan2333
Diffstat (limited to 'yt_dlp/extractor/bilibili.py')
-rw-r--r--yt_dlp/extractor/bilibili.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py
index 2252840b3..c34439779 100644
--- a/yt_dlp/extractor/bilibili.py
+++ b/yt_dlp/extractor/bilibili.py
@@ -81,7 +81,7 @@ class BilibiliBaseIE(InfoExtractor):
f'{line["content"]}\n\n')
return srt_data
- def _get_subtitles(self, video_id, initial_state, cid):
+ def _get_subtitles(self, video_id, aid, cid):
subtitles = {
'danmaku': [{
'ext': 'xml',
@@ -89,7 +89,8 @@ class BilibiliBaseIE(InfoExtractor):
}]
}
- for s in traverse_obj(initial_state, ('videoData', 'subtitle', 'list')) or []:
+ video_info_json = self._download_json(f'https://api.bilibili.com/x/player/v2?aid={aid}&cid={cid}', video_id)
+ for s in traverse_obj(video_info_json, ('data', 'subtitle', 'subtitles', ...)):
subtitles.setdefault(s['lan'], []).append({
'ext': 'srt',
'data': self.json2srt(self._download_json(s['subtitle_url'], video_id))
@@ -331,7 +332,7 @@ class BiliBiliIE(BilibiliBaseIE):
'timestamp': traverse_obj(initial_state, ('videoData', 'pubdate')),
'duration': float_or_none(play_info.get('timelength'), scale=1000),
'chapters': self._get_chapters(aid, cid),
- 'subtitles': self.extract_subtitles(video_id, initial_state, cid),
+ 'subtitles': self.extract_subtitles(video_id, aid, cid),
'__post_extractor': self.extract_comments(aid),
'http_headers': {'Referer': url},
}