This commit is contained in:
2026-02-09 17:22:40 -08:00
parent d2e571b6f1
commit c86aae1ff6
5 changed files with 35 additions and 22 deletions

View File

@@ -23,7 +23,6 @@ from SYS.pipeline_progress import PipelineProgress
from SYS.result_table import Table
from SYS.rich_display import stderr_console as get_stderr_console
from SYS import pipeline as pipeline_context
from SYS.utils import sha256_file
from SYS.metadata import normalize_urls as normalize_url_list
from tool.ytdlp import (
@@ -1443,6 +1442,7 @@ class Download_File(Cmdlet):
for url in supported_url:
try:
debug(f"[download-file] Processing URL in loop: {url}")
debug(f"[download-file] ytdl_format parameter passed in: {ytdl_format}")
canonical_url = url
if not skip_per_url_preflight or clip_ranges:
@@ -1493,7 +1493,6 @@ class Download_File(Cmdlet):
):
actual_format = forced_single_format_id
forced_single_applied = True
if (
actual_format
and isinstance(actual_format, str)
@@ -1519,7 +1518,7 @@ class Download_File(Cmdlet):
if vcodec != "none" and acodec == "none":
debug(f"Selected video-only format {actual_format}; using {actual_format}+ba for audio")
actual_format = f"{actual_format}+ba"
except Exception:
except Exception as e:
pass
attempted_single_format_fallback = False
@@ -1941,22 +1940,27 @@ class Download_File(Cmdlet):
height_selector = None
if query_format and not query_wants_audio:
try:
height_selector = ytdlp_tool.resolve_height_selector(query_format)
# Check if this looks like a YouTube format ID (used when selecting from format table)
# Format IDs are typically 3 digits and come from user selections
# Only treat as height if it looks like a resolution (ends with 'p' or is 1080+)
is_likely_format_id = (
len(str(query_format).strip()) == 3 and
str(query_format).strip().isdigit()
)
if not is_likely_format_id:
height_selector = ytdlp_tool.resolve_height_selector(query_format)
except Exception:
height_selector = None
if height_selector:
if query_wants_audio:
# Explicit audio request should map to best-audio-only selector
ytdl_format = "ba"
elif height_selector:
ytdl_format = height_selector
else:
import re
if re.match(r"^\s*#?\d+\s*$", str(query_format)):
# Numeric format like "720" or "1080p" - will be resolved later via resolve_height_selector
# Don't set ytdl_format yet; let it fall through to per-URL resolution
pass
else:
# Non-numeric format string - use as literal
ytdl_format = query_format
debug(f"DEBUG: [download-file] Using literal query_format '{query_format}' as ytdl_format")
elif query_format:
# Use query_format as literal format ID (e.g., from table selection like '251')
ytdl_format = query_format
playlist_selection_handled = False
if len(supported_url) == 1 and not playlist_items:
@@ -1965,10 +1969,8 @@ class Download_File(Cmdlet):
# If query_format is provided and numeric, resolve it now.
if query_format and not query_wants_audio and not ytdl_format:
try:
debug(f"[download-file] Resolving format for {candidate_url} (query='{query_format}')...")
idx_fmt = self._format_id_for_query_index(query_format, candidate_url, formats_cache, ytdlp_tool)
if idx_fmt:
debug(f"Resolved format selection '{query_format}' -> {idx_fmt}")
ytdl_format = idx_fmt
except ValueError as e:
# Fallback: Treat as literal format if resolution fails or it's not a valid row index.