diff options
author | Vitiko <[email protected]> | 2023-05-28 22:06:43 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2023-05-28 22:06:43 -0400 |
commit | 4725496313a53e47cda01a092e6829a282413e0b (patch) | |
tree | 0b018832501507b714102906efd5096e213c1a5b | |
parent | 77531090b2c2c98d7cbb7f562222d04fcfc66c89 (diff) | |
download | bazarr-4725496313a53e47cda01a092e6829a282413e0b.tar.gz bazarr-4725496313a53e47cda01a092e6829a282413e0b.zip |
Language-equals: add compatibility for more providersv1.2.2-beta.10
Some providers directly uses language codes within their query
implementations. This 'translator' method will take care of that.
-rw-r--r-- | libs/subliminal_patch/core.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index aa3ec3051..70e1004dc 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -155,6 +155,19 @@ class _LanguageEquals(list): if len(item) != 2 or not any(isinstance(i, Language) for i in item): raise ValueError(f"Not a valid equal tuple: {item}") + def translate(self, items: set): + translated = set() + + for equals in self: + from_, to_ = equals + if to_ in items: + logger.debug("Translating %s -> %s", to_, from_) + translated.add(from_) + else: + translated.add(to_) + + return translated or items + def check_set(self, items: set): """ Check a set of languages. For example, if the set is {Language('es')} and one of the equals of the instance is (Language('es'), Language('es', 'MX')), the set will now have @@ -343,7 +356,7 @@ class SZProviderPool(ProviderPool): logger.info('Listing subtitles with provider %r and languages %r', provider, provider_languages) results = [] try: - results = self[provider].list_subtitles(video, provider_languages) + results = self[provider].list_subtitles(video, self.lang_equals.translate(provider_languages)) seen = [] out = [] for s in results: |