Fix for continue in finally not supported under Python 3.7

pull/1136/head
Louis Vézina 4 years ago
parent 92bb9aa2ff
commit 9f0b6a85f0

@ -438,10 +438,10 @@ def guess_external_subtitles(dest_folder, subtitles):
subtitle_path = os.path.join(dest_folder, subtitle)
# to improve performance, skip detection of files larger that 1M
if os.path.getsize(subtitle_path) > 1 * 1024 * 1024:
logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " +
subtitle_path)
continue
#if os.path.getsize(subtitle_path) > 1 * 1024 * 1024:
# logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " +
# subtitle_path)
# continue
with open(subtitle_path, 'rb') as f:
text = f.read()
@ -452,11 +452,12 @@ def guess_external_subtitles(dest_folder, subtitles):
detector = Detector()
guess = detector.detect(text)
logging.debug('BAZARR detected encoding %r', guess)
text = text.decode(guess)
finally:
try:
if bool(re.search(hi_regex, text)):
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True)
except TypeError:
text = text.decode(guess)
except:
# text could not be decoded with guessed encoding, we wont try to detect HI fo rthis one
continue
if bool(re.search(hi_regex, text)):
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True)
return subtitles

Loading…
Cancel
Save