From 77531090b2c2c98d7cbb7f562222d04fcfc66c89 Mon Sep 17 00:00:00 2001 From: Vitiko Date: Sun, 28 May 2023 21:05:21 -0400 Subject: [PATCH 1/2] no log: reduce debug call verbosity --- libs/subliminal_patch/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index 1e293455b..aa3ec3051 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -168,12 +168,12 @@ class _LanguageEquals(list): for equals in self: from_, to_ = equals if from_ in items: - logger.debug("Adding %s to %s", to_, items) + logger.debug("Adding %s to %s item(s) set", to_, len(items)) to_add.append(to_) new_items = items.copy() new_items.update(to_add) - logger.debug("New set: %s", new_items) + logger.debug("New set: %s items", len(new_items)) return new_items def update_subtitle(self, subtitle): From 4725496313a53e47cda01a092e6829a282413e0b Mon Sep 17 00:00:00 2001 From: Vitiko Date: Sun, 28 May 2023 22:06:43 -0400 Subject: [PATCH 2/2] Language-equals: add compatibility for more providers Some providers directly uses language codes within their query implementations. This 'translator' method will take care of that. --- libs/subliminal_patch/core.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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: