mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
fix: simplify logic
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
parent
5161f08991
commit
43ce0a98fd
1 changed files with 4 additions and 18 deletions
|
@ -30,7 +30,7 @@
|
||||||
update_url_query,
|
update_url_query,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
urljoin,
|
urljoin, url_basename,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -441,27 +441,13 @@ def _yield_dms_formats(self, api_data, video_id):
|
||||||
video_fmts = sorted((fmt for fmt in dms_fmts if fmt['vcodec'] != 'none'), key=lambda f: f['tbr'])
|
video_fmts = sorted((fmt for fmt in dms_fmts if fmt['vcodec'] != 'none'), key=lambda f: f['tbr'])
|
||||||
self._remove_duplicate_formats(video_fmts)
|
self._remove_duplicate_formats(video_fmts)
|
||||||
|
|
||||||
def find_dms_format(search_target, target_fmt_id):
|
|
||||||
for item in search_target:
|
|
||||||
if item.get('id', {str}) == target_fmt_id:
|
|
||||||
return item
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Calculate the true vbr/tbr by subtracting the lowest abr
|
# Calculate the true vbr/tbr by subtracting the lowest abr
|
||||||
min_abr = min(traverse_obj(audios, (..., 'bitRate', {float_or_none})), default=0) / 1000
|
min_abr = min(traverse_obj(audios, (..., 'bitRate', {float_or_none})), default=0) / 1000
|
||||||
for video_fmt in video_fmts:
|
for video_fmt in video_fmts:
|
||||||
video_fmt['tbr'] -= min_abr
|
video_fmt['tbr'] -= min_abr
|
||||||
|
video_fmt['id'] = url_basename(video_fmt['url']).rpartition('.')[0]
|
||||||
video_fmt_id = self._search_regex(r'https://delivery.domand.nicovideo.jp/hlsbid/[a-z0-9]+/playlists/media/([a-z0-9\-]+).m3u8', video_fmt['url'], 'video format id', fatal=False)
|
video_fmt['quality'] = traverse_obj(videos, (
|
||||||
if video_fmt_id:
|
lambda _, v: v['id'] == video_fmt['id'], 'qualityLevel', {int_or_none}, any)) or -1
|
||||||
dms_video_fmt = find_dms_format(videos, video_fmt_id)
|
|
||||||
if dms_video_fmt:
|
|
||||||
video_fmt['format_id'] = video_fmt_id
|
|
||||||
video_fmt['quality'] = dms_video_fmt.get('qualityLevel', {int})
|
|
||||||
yield video_fmt
|
|
||||||
continue
|
|
||||||
|
|
||||||
video_fmt['format_id'] = f'video-{video_fmt["tbr"]:.0f}'
|
|
||||||
yield video_fmt
|
yield video_fmt
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
|
|
Loading…
Reference in a new issue