mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2025-10-23 15:11:08 +00:00
feat: add --exact-lang flag for precise language matching
New --exact-lang CLI flag that enables exact language code matching instead of fuzzy matching. This allows users to get specific regional variants without matching all related variants. Examples: - `-l es-419` normally matches all Spanish (es-ES, es-419, es-MX) - `-l es-419 --exact-lang` matches ONLY es-419 (Latin American Spanish) Fixes language detection issue where specific variants like es-419 (Latin American Spanish) would match all Spanish variants instead of just close regional variants.
This commit is contained in:
@@ -180,6 +180,12 @@ class dl:
|
||||
help="Required subtitle languages. Downloads all subtitles only if these languages exist. Cannot be used with --s-lang.",
|
||||
)
|
||||
@click.option("-fs", "--forced-subs", is_flag=True, default=False, help="Include forced subtitle tracks.")
|
||||
@click.option(
|
||||
"--exact-lang",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Use exact language matching (no variants). With this flag, -l es-419 matches ONLY es-419, not es-ES or other variants.",
|
||||
)
|
||||
@click.option(
|
||||
"--proxy",
|
||||
type=str,
|
||||
@@ -468,6 +474,7 @@ class dl:
|
||||
s_lang: list[str],
|
||||
require_subs: list[str],
|
||||
forced_subs: bool,
|
||||
exact_lang: bool,
|
||||
sub_format: Optional[Subtitle.Codec],
|
||||
video_only: bool,
|
||||
audio_only: bool,
|
||||
@@ -709,7 +716,9 @@ class dl:
|
||||
else:
|
||||
if language not in processed_video_lang:
|
||||
processed_video_lang.append(language)
|
||||
title.tracks.videos = title.tracks.by_language(title.tracks.videos, processed_video_lang)
|
||||
title.tracks.videos = title.tracks.by_language(
|
||||
title.tracks.videos, processed_video_lang, exact_match=exact_lang
|
||||
)
|
||||
if not title.tracks.videos:
|
||||
self.log.error(f"There's no {processed_video_lang} Video Track...")
|
||||
sys.exit(1)
|
||||
@@ -792,16 +801,20 @@ class dl:
|
||||
f"Required languages found ({', '.join(require_subs)}), downloading all available subtitles"
|
||||
)
|
||||
elif s_lang and "all" not in s_lang:
|
||||
from unshackle.core.utilities import is_exact_match
|
||||
|
||||
match_func = is_exact_match if exact_lang else is_close_match
|
||||
|
||||
missing_langs = [
|
||||
lang_
|
||||
for lang_ in s_lang
|
||||
if not any(is_close_match(lang_, [sub.language]) for sub in title.tracks.subtitles)
|
||||
if not any(match_func(lang_, [sub.language]) for sub in title.tracks.subtitles)
|
||||
]
|
||||
if missing_langs:
|
||||
self.log.error(", ".join(missing_langs) + " not found in tracks")
|
||||
sys.exit(1)
|
||||
|
||||
title.tracks.select_subtitles(lambda x: is_close_match(x.language, s_lang))
|
||||
title.tracks.select_subtitles(lambda x: match_func(x.language, s_lang))
|
||||
if not title.tracks.subtitles:
|
||||
self.log.error(f"There's no {s_lang} Subtitle Track...")
|
||||
sys.exit(1)
|
||||
@@ -865,7 +878,7 @@ class dl:
|
||||
elif "all" not in processed_lang:
|
||||
per_language = 1
|
||||
title.tracks.audio = title.tracks.by_language(
|
||||
title.tracks.audio, processed_lang, per_language=per_language
|
||||
title.tracks.audio, processed_lang, per_language=per_language, exact_match=exact_lang
|
||||
)
|
||||
if not title.tracks.audio:
|
||||
self.log.error(f"There's no {processed_lang} Audio Track, cannot continue...")
|
||||
|
||||
Reference in New Issue
Block a user