From 47261c0c9132f8eb00730004cdb451caaf0ed3bb Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 13 Jan 2018 15:45:21 -0500 Subject: [PATCH] Adding exception logging for subtitles file encoding detection #37 --- list_subtitles.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/list_subtitles.py b/list_subtitles.py index 3158ba3b4..4d0010a53 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -39,10 +39,14 @@ def store_subtitles(file): text = list(islice(f, 20)) text = ' '.join(text) encoding = chardet.detect(text)['encoding'] - text = text.decode(encoding) - detected_language = langdetect.detect(text) - if len(detected_language) > 0: - actual_subtitles.append([str(detected_language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))]) + try: + text = text.decode(encoding) + except Exception as e: + logging.exception('Error trying to detect character encoding for this subtitles file: ' + path_replace(os.path.join(os.path.dirname(file), subtitle))) + else: + detected_language = langdetect.detect(text) + if len(detected_language) > 0: + actual_subtitles.append([str(detected_language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))]) conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor()