diff options
author | XPA <96982836+xpadev-net@users.noreply.github.com> | 2025-02-24 04:07:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-23 19:07:08 +0000 |
commit | 7508e34f203e97389f1d04db92140b13401dd724 (patch) | |
tree | 1b6cbf623cb140e128fe08e23d5463aed9ca8986 | |
parent | 9807181cfbf87bfa732f415c30412bdbd77cbf81 (diff) |
[ie/niconico] Fix format sorting (#12442)
Authored by: xpadev-net
-rw-r--r-- | yt_dlp/extractor/niconico.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/yt_dlp/extractor/niconico.py b/yt_dlp/extractor/niconico.py index 77a22777b..62dd0ab9c 100644 --- a/yt_dlp/extractor/niconico.py +++ b/yt_dlp/extractor/niconico.py @@ -28,6 +28,7 @@ from ..utils import ( try_get, unescapeHTML, update_url_query, + url_basename, url_or_none, urlencode_postdata, urljoin, @@ -432,6 +433,7 @@ class NiconicoIE(InfoExtractor): 'format_id': ('id', {str}), 'abr': ('bitRate', {float_or_none(scale=1000)}), 'asr': ('samplingRate', {int_or_none}), + 'quality': ('qualityLevel', {int_or_none}), }), get_all=False), 'acodec': 'aac', } @@ -443,7 +445,9 @@ class NiconicoIE(InfoExtractor): min_abr = min(traverse_obj(audios, (..., 'bitRate', {float_or_none})), default=0) / 1000 for video_fmt in video_fmts: video_fmt['tbr'] -= min_abr - video_fmt['format_id'] = f'video-{video_fmt["tbr"]:.0f}' + video_fmt['format_id'] = url_basename(video_fmt['url']).rpartition('.')[0] + video_fmt['quality'] = traverse_obj(videos, ( + lambda _, v: v['id'] == video_fmt['format_id'], 'qualityLevel', {int_or_none}, any)) or -1 yield video_fmt def _real_extract(self, url): |