|
|
|
@ -366,23 +366,29 @@ def guess_external_subtitles(dest_folder, subtitles):
|
|
|
|
|
subtitle_path)
|
|
|
|
|
continue
|
|
|
|
|
detected_language = None
|
|
|
|
|
with open(subtitle_path, 'r', errors='ignore') as f:
|
|
|
|
|
text = f.read()
|
|
|
|
|
try:
|
|
|
|
|
encoding = UnicodeDammit(text)
|
|
|
|
|
if six.PY2:
|
|
|
|
|
text = text.decode(encoding.original_encoding)
|
|
|
|
|
detected_language = langdetect.detect(text)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception('BAZARR Error trying to detect language for this subtitles file: ' +
|
|
|
|
|
subtitle_path + ' You should try to delete this subtitles file manually and ask '
|
|
|
|
|
'Bazarr to download it again.')
|
|
|
|
|
else:
|
|
|
|
|
if detected_language:
|
|
|
|
|
logging.debug("BAZARR external subtitles detected and guessed this language: " + str(
|
|
|
|
|
detected_language))
|
|
|
|
|
try:
|
|
|
|
|
subtitles[subtitle] = Language.rebuild(Language.fromietf(detected_language))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if six.PY3:
|
|
|
|
|
with open(subtitle_path, 'r', errors='ignore') as f:
|
|
|
|
|
text = f.read()
|
|
|
|
|
else:
|
|
|
|
|
with open(subtitle_path, 'r') as f:
|
|
|
|
|
text = f.read()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
encoding = UnicodeDammit(text)
|
|
|
|
|
if six.PY2:
|
|
|
|
|
text = text.decode(encoding.original_encoding)
|
|
|
|
|
detected_language = langdetect.detect(text)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception('BAZARR Error trying to detect language for this subtitles file: ' +
|
|
|
|
|
subtitle_path + ' You should try to delete this subtitles file manually and ask '
|
|
|
|
|
'Bazarr to download it again.')
|
|
|
|
|
else:
|
|
|
|
|
if detected_language:
|
|
|
|
|
logging.debug("BAZARR external subtitles detected and guessed this language: " + str(
|
|
|
|
|
detected_language))
|
|
|
|
|
try:
|
|
|
|
|
subtitles[subtitle] = Language.rebuild(Language.fromietf(detected_language))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
return subtitles
|
|
|
|
|