From 303182471c2ca62e37d633a7ced0556b0c36fc2c Mon Sep 17 00:00:00 2001 From: josdion Date: Sun, 14 Jun 2020 08:35:58 +0300 Subject: [PATCH] return to encoding auto detection in case the provider has set invalid encoding --- libs/subliminal_patch/subtitle.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/subliminal_patch/subtitle.py b/libs/subliminal_patch/subtitle.py index b3dc3ebcb..5429004eb 100644 --- a/libs/subliminal_patch/subtitle.py +++ b/libs/subliminal_patch/subtitle.py @@ -105,7 +105,7 @@ class Subtitle(Subtitle_): return self def get_encoding(self): - return self.encoding if self.encoding else self.guess_encoding() + return self.guess_encoding() def set_encoding(self, encoding): ge = self.get_encoding() @@ -116,7 +116,6 @@ class Subtitle(Subtitle_): logger.debug("Changing encoding: to %s, from %s", encoding, ge) self.content = unicontent.encode(encoding) self._guessed_encoding = encoding - self.encoding = encoding def normalize(self): """ @@ -141,6 +140,16 @@ class Subtitle(Subtitle_): if self._guessed_encoding: return self._guessed_encoding + if self.encoding: + # check provider encoding and use it only if it is valid + try: + self.content.decode(self.encoding) + self._guessed_encoding = self.encoding + return self._guessed_encoding + except: + # provider specified encoding is invalid, fallback to guessing + pass + logger.info('Guessing encoding for language %s', self.language) encodings = ['utf-8']