diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index fcd7ce3be..d4685c289 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -31,7 +31,7 @@ from subliminal.core import guessit, ProviderPool, io, is_windows_special_path, ThreadPoolExecutor, check_video from subliminal_patch.exceptions import TooManyRequests, APIThrottled -from subzero.language import Language, ENDSWITH_LANGUAGECODE_RE +from subzero.language import Language, ENDSWITH_LANGUAGECODE_RE, FULL_LANGUAGE_LIST from scandir import scandir, scandir_generic as _scandir_generic import six @@ -610,7 +610,8 @@ def _search_external_subtitles(path, languages=None, only_one=False, scandir_gen forced = "forced" in adv_tag # remove possible language code for matching - p_root_bare = ENDSWITH_LANGUAGECODE_RE.sub("", p_root) + p_root_bare = ENDSWITH_LANGUAGECODE_RE.sub( + lambda m: "" if str(m.group(1)).lower() in FULL_LANGUAGE_LIST else m.group(0), p_root) p_root_lower = p_root_bare.lower() diff --git a/libs/subzero/language.py b/libs/subzero/language.py index d212a02f4..38cfb8113 100644 --- a/libs/subzero/language.py +++ b/libs/subzero/language.py @@ -4,7 +4,7 @@ import types import re from babelfish.exceptions import LanguageError -from babelfish import Language as Language_, basestr +from babelfish import Language as Language_, basestr, LANGUAGE_MATRIX from six.moves import zip repl_map = { @@ -33,6 +33,12 @@ repl_map = { } +ALPHA2_LIST = list(set(filter(lambda x: x, map(lambda x: x.alpha2, LANGUAGE_MATRIX)) + repl_map.values())) +ALPHA3b_LIST = list(set(filter(lambda x: x, map(lambda x: x.alpha3, LANGUAGE_MATRIX)) + + filter(lambda x: len(x) == 3, repl_map.keys()))) +FULL_LANGUAGE_LIST = ALPHA2_LIST + ALPHA3b_LIST + + def language_from_stream(l): if not l: raise LanguageError()