Skip to content

Commit

Permalink
[ie/bilibili] Fix extractor
Browse files Browse the repository at this point in the history
- fix playinfo extraction
- update API URL
  • Loading branch information
kclauhk committed Nov 28, 2024
1 parent a09fe19 commit ce912d7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions yt_dlp/extractor/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _get_subtitles(self, video_id, cid, aid=None):
}

video_info = self._download_json(
'https://api.bilibili.com/x/player/v2', video_id,
'https://api.bilibili.com/x/player/wbi/v2', video_id,
query={'aid': aid, 'cid': cid} if aid else {'bvid': video_id, 'cid': cid},
note=f'Extracting subtitle info {cid}', headers=self._HEADERS)
if traverse_obj(video_info, ('data', 'need_login_subtitle')):
Expand All @@ -207,7 +207,7 @@ def _get_subtitles(self, video_id, cid, aid=None):

def _get_chapters(self, aid, cid):
chapters = aid and cid and self._download_json(
'https://api.bilibili.com/x/player/v2', aid, query={'aid': aid, 'cid': cid},
'https://api.bilibili.com/x/player/wbi/v2', aid, query={'aid': aid, 'cid': cid},
note='Extracting chapters', fatal=False, headers=self._HEADERS)
return traverse_obj(chapters, ('data', 'view_points', ..., {
'title': 'content',
Expand Down Expand Up @@ -643,16 +643,19 @@ def _real_extract(self, url):
if is_festival:
video_data = initial_state['videoInfo']
else:
play_info_obj = self._search_json(
r'window\.__playinfo__\s*=', webpage, 'play info', video_id, fatal=False)
if not play_info_obj:
play_info = None
if play_info_obj := self._search_json(
r'window\.__playinfo__\s*=', webpage, 'play info', video_id, default=None):
play_info = traverse_obj(play_info_obj, ('data', {dict}))
else:
if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
self.raise_login_required()
if traverse_obj(initial_state, ('error', 'trueCode')) == -404:
raise ExtractorError(
'This video may be deleted or geo-restricted. '
'You might want to try a VPN or a proxy server (with --proxy)', expected=True)
play_info = traverse_obj(play_info_obj, ('data', {dict}))
play_info = self._download_playinfo(initial_state['videoData']['bvid'],
initial_state['cid'], headers=headers)
if not play_info:
if traverse_obj(play_info_obj, 'code') == 87007:
toast = get_element_by_class('tips-toast', webpage) or ''
Expand Down

0 comments on commit ce912d7

Please sign in to comment.