Compare commits

..

No commits in common. "8bf65ed2d341a1c1620f66f15269917c16021250" and "314145548a69df8ea8135048ad04b6c69cb40638" have entirely different histories.

View File

@ -164,14 +164,18 @@ class BilibiliBaseIE(InfoExtractor):
params['w_rid'] = hashlib.md5(f'{query}{self._get_wbi_key(video_id)}'.encode()).hexdigest() params['w_rid'] = hashlib.md5(f'{query}{self._get_wbi_key(video_id)}'.encode()).hexdigest()
return params return params
def _download_playinfo(self, bvid, cid, headers=None, qn=None): def _download_playinfo(self, bvid, cid, headers=None, fatal=True, qn=None):
params = {'bvid': bvid, 'cid': cid, 'fnval': 4048} params = {'bvid': bvid, 'cid': cid, 'fnval': 4048}
if qn: if qn:
params['qn'] = qn params['qn'] = qn
return self._download_json( play_info_obj = self._download_json(
'https://api.bilibili.com/x/player/wbi/playurl', bvid, 'https://api.bilibili.com/x/player/wbi/playurl', bvid,
query=self._sign_wbi(params, bvid), headers=headers, query=self._sign_wbi(params, bvid), headers=headers, fatal=fatal,
note=f'Downloading video formats for cid {cid} {qn or ""}')['data'] note=f'Downloading video formats for cid {cid} {qn or ""}')
if fatal:
return play_info_obj['data']
else:
return play_info_obj.get('data')
def json2srt(self, json_data): def json2srt(self, json_data):
srt_data = '' srt_data = ''
@ -638,6 +642,11 @@ class BiliBiliIE(BilibiliBaseIE):
headers['Referer'] = url headers['Referer'] = url
initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id) 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: if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
self.raise_login_required() self.raise_login_required()
@ -646,19 +655,6 @@ class BiliBiliIE(BilibiliBaseIE):
'This video may be deleted or geo-restricted. ' 'This video may be deleted or geo-restricted. '
'You might want to try a VPN or a proxy server (with --proxy)', expected=True) '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') 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. # Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
@ -686,9 +682,24 @@ class BiliBiliIE(BilibiliBaseIE):
play_info = ( play_info = (
traverse_obj( 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})) ('data', {dict}))
or self._download_playinfo(video_id, cid, headers=headers)) 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)
festival_info = {} festival_info = {}
if is_festival: if is_festival: