Adding exception logging for subtitles file encoding detection #37

pull/56/merge
morpheus65535 7 years ago
parent d805576f83
commit 47261c0c91

@ -39,7 +39,11 @@ def store_subtitles(file):
text = list(islice(f, 20))
text = ' '.join(text)
encoding = chardet.detect(text)['encoding']
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))])

Loading…
Cancel
Save