Compare commits

...

7 Commits

Author SHA1 Message Date
N/Ame
8bf65ed2d3
Update yt_dlp/extractor/bilibili.py 2024-12-02 10:41:26 +13:00
N/Ame
63a3011150
Update yt_dlp/extractor/bilibili.py 2024-12-02 10:36:40 +13:00
N/Ame
06a5a3768f
Update yt_dlp/extractor/bilibili.py 2024-12-02 10:34:22 +13:00
N/Ame
9944c0c7aa
revert changes to _download_playinfo 2024-12-02 10:32:37 +13:00
grqx_termux
1442658d9a make play info extraction always fatal 2024-12-02 10:20:50 +13:00
grqx_termux
76400685fd Move error handling up 2024-12-02 10:06:52 +13:00
N/Ame
4f28e9a93b
Apply suggestions from code review
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
2024-12-02 09:48:26 +13:00

View File

@ -164,18 +164,14 @@ class BilibiliBaseIE(InfoExtractor):
params['w_rid'] = hashlib.md5(f'{query}{self._get_wbi_key(video_id)}'.encode()).hexdigest()
return params
def _download_playinfo(self, bvid, cid, headers=None, fatal=True, qn=None):
def _download_playinfo(self, bvid, cid, headers=None, qn=None):
params = {'bvid': bvid, 'cid': cid, 'fnval': 4048}
if qn:
params['qn'] = qn
play_info_obj = self._download_json(
return self._download_json(
'https://api.bilibili.com/x/player/wbi/playurl', bvid,
query=self._sign_wbi(params, bvid), headers=headers, fatal=fatal,
note=f'Downloading video formats for cid {cid} {qn or ""}')
if fatal:
return play_info_obj['data']
else:
return play_info_obj.get('data')
query=self._sign_wbi(params, bvid), headers=headers,
note=f'Downloading video formats for cid {cid} {qn or ""}')['data']
def json2srt(self, json_data):
srt_data = ''
@ -642,11 +638,6 @@ class BiliBiliIE(BilibiliBaseIE):
headers['Referer'] = url
initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id)
is_festival = 'videoData' not in initial_state
if is_festival:
video_data = initial_state['videoInfo']
else:
video_data = initial_state['videoData']
if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
self.raise_login_required()
@ -655,6 +646,19 @@ class BiliBiliIE(BilibiliBaseIE):
'This video may be deleted or geo-restricted. '
'You might want to try a VPN or a proxy server (with --proxy)', expected=True)
is_festival = 'videoData' not in initial_state
if is_festival:
video_data = initial_state['videoInfo']
else:
video_data = initial_state['videoData']
if video_data.get('is_upower_exclusive'):
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level'))
raise ExtractorError(
'This is a supporter-only video: '
f'{join_nonempty("title", "sub_title", from_dict=high_level, delim="")}. '
f'{self._login_hint()}', expected=True)
video_id, title = video_data['bvid'], video_data.get('title')
# Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
@ -682,24 +686,9 @@ class BiliBiliIE(BilibiliBaseIE):
play_info = (
traverse_obj(
self._search_json(
r'window\.__playinfo__\s*=', webpage, 'play info', video_id, default=None),
self._search_json(r'window\.__playinfo__\s*=', webpage, 'play info', video_id, default=None),
('data', {dict}))
or self._download_playinfo(video_id, cid, headers=headers, fatal=False))
if not play_info:
raise ExtractorError('Failed to extract play info')
if video_data.get('is_upower_exclusive'):
# Supporter-only, also indicated by
# `not traverse_obj(play_info, ('support_formats', ..., 'codecs'))`
# Ref: https://github.com/ytdl-org/youtube-dl/issues/32722#issuecomment-1950045012
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level'))
# Should we inline the title and the subtitle?
support_title = traverse_obj(high_level, 'title', default='')
support_subtitle = traverse_obj(high_level, 'sub_title', default='')
raise ExtractorError(
f'This is a supporter-only video: {support_title}{support_subtitle}. '
f'{self._login_hint()}', expected=True)
or self._download_playinfo(video_id, cid, headers=headers))
festival_info = {}
if is_festival: