mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 10:55:08 +00:00
feat(dl): add -fsl/--forced-s-lang to filter forced subtitles by language
This commit is contained in:
@@ -536,6 +536,7 @@ def _perform_download(
|
||||
s_lang=params.get("s_lang", ["all"]),
|
||||
require_subs=params.get("require_subs", []),
|
||||
forced_subs=params.get("forced_subs", False),
|
||||
forced_s_lang=params.get("forced_s_lang", []),
|
||||
exact_lang=params.get("exact_lang", False),
|
||||
sub_format=params.get("sub_format"),
|
||||
video_only=params.get("video_only", False),
|
||||
|
||||
@@ -44,6 +44,7 @@ DEFAULT_DOWNLOAD_PARAMS = {
|
||||
"s_lang": ["all"],
|
||||
"require_subs": [],
|
||||
"forced_subs": False,
|
||||
"forced_s_lang": [],
|
||||
"exact_lang": False,
|
||||
"sub_format": None,
|
||||
"video_only": False,
|
||||
|
||||
@@ -689,6 +689,11 @@ async def download(request: web.Request) -> web.Response:
|
||||
forced_subs:
|
||||
type: boolean
|
||||
description: Include forced subtitle tracks (default - false)
|
||||
forced_s_lang:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: Languages wanted for forced subtitles, implies forced_subs (default - [])
|
||||
exact_lang:
|
||||
type: boolean
|
||||
description: Use exact language matching (no variants) (default - false)
|
||||
|
||||
@@ -163,6 +163,21 @@ def is_exact_match(language: Union[str, Language], languages: Sequence[Union[str
|
||||
return closest_match(language, list(map(str, languages)))[1] <= LANGUAGE_EXACT_DISTANCE
|
||||
|
||||
|
||||
def keep_forced_subtitle(
|
||||
forced: bool,
|
||||
language: Union[str, Language],
|
||||
forced_s_lang: Sequence[str],
|
||||
exact: bool = False,
|
||||
) -> bool:
|
||||
"""The -fsl filter: non-forced tracks always pass, forced tracks only if they match forced_s_lang."""
|
||||
if not forced:
|
||||
return True
|
||||
if not forced_s_lang:
|
||||
return False
|
||||
match_func = is_exact_match if exact else is_close_match
|
||||
return match_func(language, forced_s_lang)
|
||||
|
||||
|
||||
def find_missing_langs(
|
||||
requested: Sequence[str],
|
||||
available: Sequence[Union[str, Language, None]],
|
||||
|
||||
Reference in New Issue
Block a user