mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-07-01 15:59:37 +00:00
Compare commits
No commits in common. "a13a336aa6f906812701abec8101b73b73db8ff7" and "d8fb3490863653182864d2a53522f350d67a9ff8" have entirely different histories.
a13a336aa6
...
d8fb349086
@ -62,7 +62,7 @@ class BilibiliBaseIE(InfoExtractor):
|
|||||||
'support_formats', lambda _, v: v['quality'] not in parsed_qualities))], delim=', ')
|
'support_formats', lambda _, v: v['quality'] not in parsed_qualities))], delim=', ')
|
||||||
if missing_formats:
|
if missing_formats:
|
||||||
self.to_screen(
|
self.to_screen(
|
||||||
f'Format(s) {missing_formats} are missing; you have to '
|
f'Format(s) {missing_formats} are missing; you have to login or '
|
||||||
f'become a premium member to download them. {self._login_hint()}')
|
f'become a premium member to download them. {self._login_hint()}')
|
||||||
|
|
||||||
def extract_formats(self, play_info):
|
def extract_formats(self, play_info):
|
||||||
@ -164,18 +164,14 @@ 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, query=None):
|
def _download_playinfo(self, bvid, cid, headers=None, qn=None):
|
||||||
params = {'bvid': bvid, 'cid': cid, 'fnval': 4048, **(query or {})}
|
params = {'bvid': bvid, 'cid': cid, 'fnval': 4048}
|
||||||
if self.is_logged_in:
|
if qn:
|
||||||
params.pop('try_look', None)
|
params['qn'] = qn
|
||||||
if qn := params.get('qn'):
|
|
||||||
note = f'Downloading video format {qn} for cid {cid}'
|
|
||||||
else:
|
|
||||||
note = f'Downloading video formats for cid {cid}'
|
|
||||||
|
|
||||||
return self._download_json(
|
return 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, note=note)['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):
|
def json2srt(self, json_data):
|
||||||
srt_data = ''
|
srt_data = ''
|
||||||
@ -194,7 +190,7 @@ class BilibiliBaseIE(InfoExtractor):
|
|||||||
}
|
}
|
||||||
|
|
||||||
video_info = self._download_json(
|
video_info = self._download_json(
|
||||||
'https://api.bilibili.com/x/player/wbi/v2', video_id,
|
'https://api.bilibili.com/x/player/v2', video_id,
|
||||||
query={'aid': aid, 'cid': cid} if aid else {'bvid': video_id, 'cid': cid},
|
query={'aid': aid, 'cid': cid} if aid else {'bvid': video_id, 'cid': cid},
|
||||||
note=f'Extracting subtitle info {cid}', headers=self._HEADERS)
|
note=f'Extracting subtitle info {cid}', headers=self._HEADERS)
|
||||||
if traverse_obj(video_info, ('data', 'need_login_subtitle')):
|
if traverse_obj(video_info, ('data', 'need_login_subtitle')):
|
||||||
@ -210,7 +206,7 @@ class BilibiliBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
def _get_chapters(self, aid, cid):
|
def _get_chapters(self, aid, cid):
|
||||||
chapters = aid and cid and self._download_json(
|
chapters = aid and cid and self._download_json(
|
||||||
'https://api.bilibili.com/x/player/wbi/v2', aid, query={'aid': aid, 'cid': cid},
|
'https://api.bilibili.com/x/player/v2', aid, query={'aid': aid, 'cid': cid},
|
||||||
note='Extracting chapters', fatal=False, headers=self._HEADERS)
|
note='Extracting chapters', fatal=False, headers=self._HEADERS)
|
||||||
return traverse_obj(chapters, ('data', 'view_points', ..., {
|
return traverse_obj(chapters, ('data', 'view_points', ..., {
|
||||||
'title': 'content',
|
'title': 'content',
|
||||||
@ -289,7 +285,7 @@ class BilibiliBaseIE(InfoExtractor):
|
|||||||
('data', 'interaction', 'graph_version', {int_or_none}))
|
('data', 'interaction', 'graph_version', {int_or_none}))
|
||||||
cid_edges = self._get_divisions(video_id, graph_version, {1: {'cid': cid}}, 1)
|
cid_edges = self._get_divisions(video_id, graph_version, {1: {'cid': cid}}, 1)
|
||||||
for cid, edges in cid_edges.items():
|
for cid, edges in cid_edges.items():
|
||||||
play_info = self._download_playinfo(video_id, cid, headers=headers, query={'try_look': 1})
|
play_info = self._download_playinfo(video_id, cid, headers=headers)
|
||||||
yield {
|
yield {
|
||||||
**metainfo,
|
**metainfo,
|
||||||
'id': f'{video_id}_{cid}',
|
'id': f'{video_id}_{cid}',
|
||||||
@ -656,6 +652,13 @@ class BiliBiliIE(BilibiliBaseIE):
|
|||||||
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.
|
||||||
@ -685,7 +688,7 @@ class BiliBiliIE(BilibiliBaseIE):
|
|||||||
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, query={'try_look': 1}))
|
or self._download_playinfo(video_id, cid, headers=headers))
|
||||||
|
|
||||||
festival_info = {}
|
festival_info = {}
|
||||||
if is_festival:
|
if is_festival:
|
||||||
@ -723,72 +726,62 @@ class BiliBiliIE(BilibiliBaseIE):
|
|||||||
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')):
|
||||||
|
# we only have legacy formats and need additional work
|
||||||
|
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})):
|
||||||
|
formats.extend(traverse_obj(
|
||||||
|
self.extract_formats(self._download_playinfo(video_id, cid, headers=headers, qn=qn)),
|
||||||
|
lambda _, v: not has_qn(v['quality'])))
|
||||||
|
self._check_missing_formats(play_info, formats)
|
||||||
|
flv_formats = traverse_obj(formats, lambda _, v: v['fragments'])
|
||||||
|
if flv_formats and len(flv_formats) < len(formats):
|
||||||
|
# Flv and mp4 are incompatible due to `multi_video` workaround, so drop one
|
||||||
|
if not self._configuration_arg('prefer_multi_flv'):
|
||||||
|
dropped_fmts = ', '.join(
|
||||||
|
f'{f.get("format_note")} ({f.get("format_id")})' for f in flv_formats)
|
||||||
|
formats = traverse_obj(formats, lambda _, v: not v.get('fragments'))
|
||||||
|
if dropped_fmts:
|
||||||
|
self.to_screen(
|
||||||
|
f'Dropping incompatible flv format(s) {dropped_fmts} since mp4 is available. '
|
||||||
|
'To extract flv, pass --extractor-args "bilibili:prefer_multi_flv"')
|
||||||
|
else:
|
||||||
|
formats = traverse_obj(
|
||||||
|
# XXX: Filtering by extractor-arg is for testing purposes
|
||||||
|
formats, lambda _, v: v['quality'] == int(self._configuration_arg('prefer_multi_flv')[0]),
|
||||||
|
) or [max(flv_formats, key=lambda x: x['quality'])]
|
||||||
|
|
||||||
if video_data.get('is_upower_exclusive'):
|
if traverse_obj(formats, (0, 'fragments')):
|
||||||
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level', {dict})) or {}
|
# We have flv formats, which are individual short videos with their own timestamps and metainfo
|
||||||
msg = f'{join_nonempty("title", "sub_title", from_dict=high_level, delim=",")}. {self._login_hint()}'
|
# Binary concatenation corrupts their timestamps, so we need a `multi_video` workaround
|
||||||
if not formats:
|
return {
|
||||||
raise ExtractorError(f'This is a supporter-only video: {msg}', expected=True)
|
**metainfo,
|
||||||
if '试看' in traverse_obj(play_info, ('accept_description', ..., {str})):
|
'_type': 'multi_video',
|
||||||
self.report_warning(
|
'entries': [{
|
||||||
f'This is a supporter-only video, only the preview will be extracted: {msg}',
|
'id': f'{metainfo["id"]}_{idx}',
|
||||||
video_id=video_id)
|
'title': metainfo['title'],
|
||||||
|
'http_headers': metainfo['http_headers'],
|
||||||
if not traverse_obj(play_info, 'dash'):
|
'formats': [{
|
||||||
# we only have legacy formats and need additional work
|
**fragment,
|
||||||
has_qn = lambda x: x in traverse_obj(formats, (..., 'quality'))
|
'format_id': formats[0].get('format_id'),
|
||||||
for qn in traverse_obj(play_info, ('accept_quality', lambda _, v: not has_qn(v), {int})):
|
}],
|
||||||
formats.extend(traverse_obj(
|
'subtitles': self.extract_subtitles(video_id, cid) if idx == 0 else None,
|
||||||
self.extract_formats(self._download_playinfo(video_id, cid, headers=headers, query={'qn': qn})),
|
'__post_extractor': self.extract_comments(aid) if idx == 0 else None,
|
||||||
lambda _, v: not has_qn(v['quality'])))
|
} for idx, fragment in enumerate(formats[0]['fragments'])],
|
||||||
self._check_missing_formats(play_info, formats)
|
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
||||||
flv_formats = traverse_obj(formats, lambda _, v: v['fragments'])
|
}
|
||||||
if flv_formats and len(flv_formats) < len(formats):
|
else:
|
||||||
# Flv and mp4 are incompatible due to `multi_video` workaround, so drop one
|
return {
|
||||||
if not self._configuration_arg('prefer_multi_flv'):
|
**metainfo,
|
||||||
dropped_fmts = ', '.join(
|
'formats': formats,
|
||||||
f'{f.get("format_note")} ({f.get("format_id")})' for f in flv_formats)
|
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
||||||
formats = traverse_obj(formats, lambda _, v: not v.get('fragments'))
|
'chapters': self._get_chapters(aid, cid),
|
||||||
if dropped_fmts:
|
'subtitles': self.extract_subtitles(video_id, cid),
|
||||||
self.to_screen(
|
'__post_extractor': self.extract_comments(aid),
|
||||||
f'Dropping incompatible flv format(s) {dropped_fmts} since mp4 is available. '
|
}
|
||||||
'To extract flv, pass --extractor-args "bilibili:prefer_multi_flv"')
|
|
||||||
else:
|
|
||||||
formats = traverse_obj(
|
|
||||||
# XXX: Filtering by extractor-arg is for testing purposes
|
|
||||||
formats, lambda _, v: v['quality'] == int(self._configuration_arg('prefer_multi_flv')[0]),
|
|
||||||
) or [max(flv_formats, key=lambda x: x['quality'])]
|
|
||||||
|
|
||||||
if traverse_obj(formats, (0, 'fragments')):
|
|
||||||
# We have flv formats, which are individual short videos with their own timestamps and metainfo
|
|
||||||
# Binary concatenation corrupts their timestamps, so we need a `multi_video` workaround
|
|
||||||
return {
|
|
||||||
**metainfo,
|
|
||||||
'_type': 'multi_video',
|
|
||||||
'entries': [{
|
|
||||||
'id': f'{metainfo["id"]}_{idx}',
|
|
||||||
'title': metainfo['title'],
|
|
||||||
'http_headers': metainfo['http_headers'],
|
|
||||||
'formats': [{
|
|
||||||
**fragment,
|
|
||||||
'format_id': formats[0].get('format_id'),
|
|
||||||
}],
|
|
||||||
'subtitles': self.extract_subtitles(video_id, cid) if idx == 0 else None,
|
|
||||||
'__post_extractor': self.extract_comments(aid) if idx == 0 else None,
|
|
||||||
} for idx, fragment in enumerate(formats[0]['fragments'])],
|
|
||||||
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
**metainfo,
|
|
||||||
'formats': formats,
|
|
||||||
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
|
||||||
'chapters': self._get_chapters(aid, cid),
|
|
||||||
'subtitles': self.extract_subtitles(video_id, cid),
|
|
||||||
'__post_extractor': self.extract_comments(aid),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BiliBiliBangumiIE(BilibiliBaseIE):
|
class BiliBiliBangumiIE(BilibiliBaseIE):
|
||||||
@ -866,16 +859,10 @@ class BiliBiliBangumiIE(BilibiliBaseIE):
|
|||||||
self.raise_login_required('This video is for premium members only')
|
self.raise_login_required('This video is for premium members only')
|
||||||
|
|
||||||
headers['Referer'] = url
|
headers['Referer'] = url
|
||||||
|
play_info = self._download_json(
|
||||||
play_info = (
|
'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
|
||||||
self._search_json(
|
'Extracting episode', query={'fnval': '4048', 'ep_id': episode_id},
|
||||||
r'playurlSSRData\s*=', webpage, 'embedded page info', episode_id,
|
headers=headers)
|
||||||
end_pattern='\n', default=None)
|
|
||||||
or self._download_json(
|
|
||||||
'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
|
|
||||||
'Extracting episode', query={'fnval': 12240, 'ep_id': episode_id},
|
|
||||||
headers=headers))
|
|
||||||
|
|
||||||
premium_only = play_info.get('code') == -10403
|
premium_only = play_info.get('code') == -10403
|
||||||
play_info = traverse_obj(play_info, ('result', 'video_info', {dict})) or {}
|
play_info = traverse_obj(play_info, ('result', 'video_info', {dict})) or {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user