added mhtml support and fixed some bugs in the process

This commit is contained in:
2026-04-22 21:19:55 -07:00
parent 90787bd0a2
commit 67c272db4b
9 changed files with 564 additions and 66 deletions
+11 -20
View File
@@ -30,7 +30,9 @@ from tool.ytdlp import (
_download_with_timeout,
_format_chapters_note,
_read_text_file,
collapse_picker_formats,
format_for_table_selection,
get_selection_format_id,
is_browseable_format,
is_url_supported_by_ytdlp,
list_formats,
@@ -349,25 +351,20 @@ def _format_id_for_query_index(
raise ValueError("Unable to list formats for the URL")
if s_val and not s_val.startswith("#"):
if any(str(f.get("format_id", "")) == s_val for f in fmts):
return s_val
for item in fmts:
if str(item.get("format_id", "")) == s_val:
normalized = get_selection_format_id(item, video_audio_suffix="bestaudio")
return normalized or s_val
candidate_formats = [f for f in fmts if is_browseable_format(f)]
candidate_formats = collapse_picker_formats(fmts, video_audio_suffix="bestaudio")
filtered_formats = candidate_formats if candidate_formats else list(fmts)
if idx <= 0 or idx > len(filtered_formats):
raise ValueError(f"Format index {idx} out of range")
chosen = filtered_formats[idx - 1]
selection_format_id = str(chosen.get("format_id") or "").strip()
selection_format_id = get_selection_format_id(chosen, video_audio_suffix="bestaudio")
if not selection_format_id:
raise ValueError("Selected format has no format_id")
try:
vcodec = str(chosen.get("vcodec", "none"))
acodec = str(chosen.get("acodec", "none"))
if vcodec != "none" and acodec == "none":
selection_format_id = f"{selection_format_id}+bestaudio"
except Exception:
pass
return selection_format_id
@@ -633,7 +630,7 @@ class ytdlp(TableProviderMixin, Provider):
) -> List[Dict[str, Any]]:
if not isinstance(formats, list):
return []
browseable = [fmt for fmt in formats if isinstance(fmt, dict) and is_browseable_format(fmt)]
browseable = collapse_picker_formats(formats, video_audio_suffix="ba")
return browseable if browseable else list(formats)
def enrich_playlist_entries(
@@ -797,7 +794,7 @@ class ytdlp(TableProviderMixin, Provider):
if not formats or len(formats) <= 1:
return False
candidate_formats = [f for f in formats if is_browseable_format(f)]
candidate_formats = collapse_picker_formats(formats, video_audio_suffix="bestaudio")
filtered_formats = candidate_formats if candidate_formats else list(formats)
base_cmd = f'download-file "{url}"'
remaining_args = [arg for arg in args if arg not in [url] and not str(arg).startswith("-")]
@@ -810,13 +807,7 @@ class ytdlp(TableProviderMixin, Provider):
results_list: List[Dict[str, Any]] = []
for idx, fmt in enumerate(filtered_formats, 1):
format_id = fmt.get("format_id", "")
selection_format_id = format_id
try:
if str(fmt.get("vcodec", "none")) != "none" and str(fmt.get("acodec", "none")) == "none" and format_id:
selection_format_id = f"{format_id}+bestaudio"
except Exception:
selection_format_id = format_id
selection_format_id = get_selection_format_id(fmt, video_audio_suffix="bestaudio")
format_dict = format_for_table_selection(
fmt,