[ie/bilibili] Fix supporter-only video extraction (#11711)

Fix bug in 239f5f36fe
Closes #11702
Authored by: grqz, bashonly

Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
N/Ame 2024-12-03 14:19:22 +13:00 committed by GitHub
parent d8fb349086
commit f05a1cd149
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -652,13 +652,6 @@ def _real_extract(self, url):
else: else:
video_data = initial_state['videoData'] video_data = initial_state['videoData']
if video_data.get('is_upower_exclusive'):
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level', {dict})) or {}
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.
@ -726,10 +719,20 @@ def _real_extract(self, url):
self._get_interactive_entries(video_id, cid, metainfo, headers=headers), **metainfo, self._get_interactive_entries(video_id, cid, metainfo, headers=headers), **metainfo,
duration=traverse_obj(initial_state, ('videoData', 'duration', {int_or_none})), duration=traverse_obj(initial_state, ('videoData', 'duration', {int_or_none})),
__post_extractor=self.extract_comments(aid)) __post_extractor=self.extract_comments(aid))
else:
formats = self.extract_formats(play_info) formats = self.extract_formats(play_info)
if not traverse_obj(play_info, ('dash')): if video_data.get('is_upower_exclusive'):
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level', {dict})) or {}
msg = f'{join_nonempty("title", "sub_title", from_dict=high_level, delim="")}. {self._login_hint()}'
if not formats:
raise ExtractorError(f'This is a supporter-only video: {msg}', expected=True)
if '试看' in traverse_obj(play_info, ('accept_description', ..., {str})):
self.report_warning(
f'This is a supporter-only video, only the preview will be extracted: {msg}',
video_id=video_id)
if not traverse_obj(play_info, 'dash'):
# we only have legacy formats and need additional work # we only have legacy formats and need additional work
has_qn = lambda x: x in traverse_obj(formats, (..., 'quality')) has_qn = lambda x: x in traverse_obj(formats, (..., 'quality'))
for qn in traverse_obj(play_info, ('accept_quality', lambda _, v: not has_qn(v), {int})): for qn in traverse_obj(play_info, ('accept_quality', lambda _, v: not has_qn(v), {int})):
@ -773,7 +776,7 @@ def _real_extract(self, url):
} for idx, fragment in enumerate(formats[0]['fragments'])], } for idx, fragment in enumerate(formats[0]['fragments'])],
'duration': float_or_none(play_info.get('timelength'), scale=1000), 'duration': float_or_none(play_info.get('timelength'), scale=1000),
} }
else:
return { return {
**metainfo, **metainfo,
'formats': formats, 'formats': formats,