This commit is contained in:
2026-01-27 14:56:01 -08:00
parent 334841dcfa
commit a44b80fd1d
7 changed files with 253 additions and 109 deletions

View File

@@ -671,6 +671,29 @@ class YtDlpTool:
pass
return None
def resolve_height_selector(self, format_str: Optional[str]) -> Optional[str]:
"""Resolve numeric heights (720, 1080p) to yt-dlp height selectors.
Examples:
"720" -> "bv*[height<=720]+ba"
"1080p" -> "bv*[height<=1080]+ba"
"""
if not format_str or not isinstance(format_str, str):
return None
s = format_str.strip().lower()
if not s:
return None
# Strip trailing 'p' if present (e.g. 720p -> 720)
if s.endswith('p'):
s = s[:-1]
if s.isdigit():
height = int(s)
if height >= 144:
return f"bv*[height<={height}]+ba"
return None
def _load_defaults(self) -> YtDlpDefaults:
cfg = self._config
@@ -787,7 +810,13 @@ class YtDlpTool:
if opts.no_playlist:
base_options["noplaylist"] = True
fmt = opts.ytdl_format or self.default_format(opts.mode)
ytdl_format = opts.ytdl_format
if ytdl_format and opts.mode != "audio":
resolved = self.resolve_height_selector(ytdl_format)
if resolved:
ytdl_format = resolved
fmt = ytdl_format or self.default_format(opts.mode)
base_options["format"] = fmt
if opts.mode == "audio":