feat(dl): add --require-audio/--require-video and --warn-only alias

Gate a title on audio or video languages that must exist, independent of what -l/-al/-vl select. --require-subs joins the same gate: its --s-lang conflict and download-all side effect are gone, so -sl now decides what to keep. Requiring a language that is also excluded fails at parse time.
This commit is contained in:
imSp4rky
2026-08-23 12:24:45 -06:00
parent 2d005fcc1c
commit d8739b3561
12 changed files with 355 additions and 36 deletions
+2
View File
@@ -563,6 +563,8 @@ def perform_download(
v_lang=params.get("v_lang", []),
a_lang=params.get("a_lang", []),
s_lang=params.get("s_lang", ["all"]),
require_audio=params.get("require_audio", []),
require_video=params.get("require_video", []),
require_subs=params.get("require_subs", []),
forced_subs=params.get("forced_subs", False),
forced_s_lang=params.get("forced_s_lang", []),
+6 -2
View File
@@ -44,6 +44,8 @@ DEFAULT_DOWNLOAD_PARAMS = {
"v_lang": [],
"a_lang": [],
"s_lang": ["all"],
"require_audio": [],
"require_video": [],
"require_subs": [],
"forced_subs": False,
"forced_s_lang": [],
@@ -1044,8 +1046,10 @@ def validate_download_parameters(data: Dict[str, Any]) -> Optional[str]:
if data.get("no_audio") and data.get("audio_only"):
return "Cannot use both no_audio and audio_only"
if data.get("s_lang") and data.get("require_subs"):
return "Cannot use both s_lang and require_subs"
for key in ("require_audio", "require_video", "require_subs"):
value = data.get(key)
if value is not None and (not isinstance(value, list) or not all(isinstance(v, str) for v in value)):
return f"{key} must be an array of language strings"
if "range" in data and data["range"]:
# "HDR10P" is the canonical range value ("+" is awkward in scripts); "HDR10+" stays valid.
+10
View File
@@ -681,6 +681,16 @@ async def download(request: web.Request) -> web.Response:
items:
type: string
description: Language for subtitle tracks (a '-' prefix excludes, e.g. ["all", "-es"]) (default - ["all"])
require_audio:
type: array
items:
type: string
description: Audio languages that must exist, else the job fails (default - [])
require_video:
type: array
items:
type: string
description: Video languages that must exist, else the job fails (default - [])
require_subs:
type: array
items:
+17
View File
@@ -243,6 +243,23 @@ def find_missing_langs(
return [tok for tok in requested if tok not in skip and not match_func(tok, available)]
def missing_required_langs(
required: Sequence[str],
available: Sequence[Union[str, Language, None]],
original: Optional[Union[str, Language]] = None,
*,
exact: bool = False,
) -> list[str]:
"""
Return the required language tokens that match no available track language.
"orig" becomes the title language, and drops out when the title has none. An exclusion
token ("-fr") asks for a language to be absent, so it is never a required language.
"""
wanted, _ = partition_exclusions(list(required))
return find_missing_langs(resolve_sort_langs(wanted, original), available, exact=exact)
def as_requested(tokens: Sequence[str], orig_token: Optional[str]) -> str:
"""Return language tokens as the user wrote them, so 'orig' reads as 'orig' and not the language it resolved to."""
return ", ".join("orig" if tok == orig_token else tok for tok in tokens)