This commit is contained in:
2026-02-10 23:00:30 -08:00
parent c2449d0ba7
commit 5323b7c76f
6 changed files with 192 additions and 104 deletions

View File

@@ -770,8 +770,8 @@ class YtDlpTool:
"""Resolve numeric heights (720, 1080p) to yt-dlp height selectors.
Examples:
"720" -> "bv*[height<=720]+ba"
"1080p" -> "bv*[height<=1080]+ba"
"720" -> "bestvideo[height<=720]+bestaudio/best[height<=720]"
"1080p" -> "bestvideo[height<=1080]+bestaudio/best[height<=1080]"
"""
if not format_str or not isinstance(format_str, str):
return None
@@ -783,10 +783,33 @@ class YtDlpTool:
# Strip trailing 'p' if present (e.g. 720p -> 720)
if s.endswith('p'):
s = s[:-1]
# Heuristic: 240/360/480/720/1080/1440/2160 are common height inputs
# But small IDs like 18, 22, 137 are format IDs.
# YouTube Format IDs are usually 2-3 digits.
# Heights are also 3-4 digits.
# "240" is ambiguous (Format 240 vs Height 240).
# We assume common video heights are intended as heights.
if s.isdigit():
height = int(s)
if height >= 144:
return f"bv*[height<={height}]+ba"
val = int(s)
# Common video heights that overlap with format IDs:
# - None currently overlap with common legacy itag IDs (17,18,22,34-38,43-46)
# or dash video IDs (133-137, 160, 242-248, 264, 271, 278, 298-315...).
# - 240, 360, 480, 720, 1080, 1440, 2160
#
# Format 240 is likely not a thing (242, 243, ... exist).
# Format 480 ... none in common lists.
# Format 720 ... none.
# So if it looks like a standard resolution, treat as height constraint.
if val in {144, 240, 360, 480, 540, 720, 1080, 1440, 2160, 2880, 4320}:
return f"bestvideo[height<={val}]+bestaudio/best[height<={val}]"
# If user types something like 500, we can also treat as height constraint if > 100
if val >= 100 and val not in {133, 134, 135, 136, 137, 160, 242, 243, 244, 247, 248, 278, 394, 395, 396, 397, 398, 399}:
return f"bestvideo[height<={val}]+bestaudio/best[height<={val}]"
return None
def _load_defaults(self) -> YtDlpDefaults: