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