mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
misc
This commit is contained in:
parent
995fc27931
commit
47254db76d
1 changed files with 42 additions and 51 deletions
|
@ -68,58 +68,49 @@ def _check_missing_formats(self, play_info, formats):
|
||||||
f'become a premium member to download them. {self._login_hint()}')
|
f'become a premium member to download them. {self._login_hint()}')
|
||||||
|
|
||||||
def _extract_storyboard(self, duration, aid=None, bvid=None, cid=None):
|
def _extract_storyboard(self, duration, aid=None, bvid=None, cid=None):
|
||||||
video_id = aid or bvid
|
if not (video_id := aid or bvid):
|
||||||
query = filter_dict({
|
|
||||||
'aid': aid,
|
|
||||||
'bvid': bvid,
|
|
||||||
'cid': cid,
|
|
||||||
})
|
|
||||||
if not aid and not bvid:
|
|
||||||
return {}
|
return {}
|
||||||
idx = 1
|
if storyboard_info := traverse_obj(self._download_json(
|
||||||
while storyboard_info := traverse_obj(self._download_json(
|
|
||||||
'https://api.bilibili.com/x/player/videoshot', video_id,
|
'https://api.bilibili.com/x/player/videoshot', video_id,
|
||||||
'Downloading storyboard info', query={
|
note='Downloading storyboard info', errnote='Failed to download storyboard info',
|
||||||
'index': idx,
|
query=filter_dict({
|
||||||
**query,
|
'index': 1,
|
||||||
}), 'data'):
|
'aid': aid,
|
||||||
if storyboard_info.get('image') and storyboard_info.get('index'):
|
'bvid': bvid,
|
||||||
rows, cols = storyboard_info.get('img_x_len'), storyboard_info.get('img_y_len')
|
'cid': cid,
|
||||||
fragments = []
|
})), ('data', {lambda v: v if v['image'] and v['index'] else None})):
|
||||||
last_duration = 0.0
|
rows, cols = traverse_obj(storyboard_info, (('img_x_len', 'img_y_len'),))
|
||||||
for i, url in enumerate(storyboard_info['image'], start=1):
|
fragments = []
|
||||||
duration_index = i * rows * cols - 1
|
last_duration = 0.0
|
||||||
if duration_index < len(storyboard_info['index']) - 1:
|
for i, url in enumerate(storyboard_info['image'], start=1):
|
||||||
current_duration = traverse_obj(storyboard_info, ('index', duration_index))
|
duration_index = i * rows * cols - 1
|
||||||
else:
|
if duration_index < len(storyboard_info['index']) - 1:
|
||||||
current_duration = duration
|
current_duration = traverse_obj(storyboard_info, ('index', duration_index))
|
||||||
if current_duration > last_duration and current_duration <= duration:
|
else:
|
||||||
fragments.append({
|
current_duration = duration
|
||||||
'url': sanitize_url(url),
|
if not current_duration or current_duration <= last_duration or current_duration > duration:
|
||||||
'duration': current_duration - last_duration,
|
break
|
||||||
})
|
fragments.append({
|
||||||
last_duration = current_duration
|
'url': sanitize_url(url),
|
||||||
else:
|
'duration': current_duration - last_duration,
|
||||||
break
|
})
|
||||||
if fragments:
|
if fragments:
|
||||||
yield {
|
return {
|
||||||
'format_id': f'sb{idx}',
|
'format_id': 'sb',
|
||||||
'format_note': 'storyboard',
|
'format_note': 'storyboard',
|
||||||
'ext': 'mhtml',
|
'ext': 'mhtml',
|
||||||
'protocol': 'mhtml',
|
'protocol': 'mhtml',
|
||||||
'acodec': 'none',
|
'acodec': 'none',
|
||||||
'vcodec': 'none',
|
'vcodec': 'none',
|
||||||
'url': 'about:invalid',
|
'url': 'about:invalid',
|
||||||
'width': storyboard_info.get('img_x_size'),
|
'width': storyboard_info.get('img_x_size'),
|
||||||
'height': storyboard_info.get('img_y_size'),
|
'height': storyboard_info.get('img_y_size'),
|
||||||
'fps': len(storyboard_info['image']) * rows * cols / duration,
|
'fps': len(storyboard_info['image']) * rows * cols / duration if rows and cols else None,
|
||||||
'rows': rows,
|
'rows': rows,
|
||||||
'columns': cols,
|
'columns': cols,
|
||||||
'fragments': fragments,
|
'fragments': fragments,
|
||||||
}
|
}
|
||||||
else:
|
return {}
|
||||||
return
|
|
||||||
idx += 1
|
|
||||||
|
|
||||||
def extract_formats(self, play_info, aid=None, bvid=None, cid=None):
|
def extract_formats(self, play_info, aid=None, bvid=None, cid=None):
|
||||||
format_names = {
|
format_names = {
|
||||||
|
@ -183,7 +174,7 @@ def extract_formats(self, play_info, aid=None, bvid=None, cid=None):
|
||||||
}),
|
}),
|
||||||
**parse_resolution(format_names.get(play_info.get('quality'))),
|
**parse_resolution(format_names.get(play_info.get('quality'))),
|
||||||
})
|
})
|
||||||
formats.extend(self._extract_storyboard(
|
formats.append(self._extract_storyboard(
|
||||||
float_or_none(play_info.get('timelength'), scale=1000), aid=aid, bvid=bvid, cid=cid))
|
float_or_none(play_info.get('timelength'), scale=1000), aid=aid, bvid=bvid, cid=cid))
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue