1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 09:37:25 +00:00

Small fix for external subtitles hi detection.

This commit is contained in:
morpheus65535 2020-11-03 15:30:38 -05:00
parent 951f2f8a03
commit 5d99d3ddf9

View file

@ -479,34 +479,36 @@ def guess_external_subtitles(dest_folder, subtitles):
elif not subtitles[subtitle].hi: elif not subtitles[subtitle].hi:
subtitle_path = os.path.join(dest_folder, subtitle) subtitle_path = os.path.join(dest_folder, subtitle)
# to improve performance, skip detection of files larger that 1M # check if file exist:
if os.path.getsize(subtitle_path) > 1 * 1024 * 1024: if os.path.exists(subtitle_path) and os.path.splitext(subtitle_path)[1] in core.SUBTITLE_EXTENSIONS:
logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " + # to improve performance, skip detection of files larger that 1M
subtitle_path) if os.path.getsize(subtitle_path) > 1 * 1024 * 1024:
continue logging.debug("BAZARR subtitles file is too large to be text based. Skipping this file: " +
subtitle_path)
with open(subtitle_path, 'rb') as f:
text = f.read()
try:
text = text.decode('utf-8')
except UnicodeDecodeError:
detector = Detector()
try:
guess = detector.detect(text)
except:
logging.debug("BAZARR skipping this subtitles because we can't guess the encoding. "
"It's probably a binary file: " + subtitle_path)
continue continue
else:
logging.debug('BAZARR detected encoding %r', guess)
try:
text = text.decode(guess)
except:
logging.debug("BAZARR skipping this subtitles because we can't decode the file using the "
"guessed encoding. It's probably a binary file: " + subtitle_path)
continue
if bool(re.search(hi_regex, text)): with open(subtitle_path, 'rb') as f:
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True) text = f.read()
try:
text = text.decode('utf-8')
except UnicodeDecodeError:
detector = Detector()
try:
guess = detector.detect(text)
except:
logging.debug("BAZARR skipping this subtitles because we can't guess the encoding. "
"It's probably a binary file: " + subtitle_path)
continue
else:
logging.debug('BAZARR detected encoding %r', guess)
try:
text = text.decode(guess)
except:
logging.debug("BAZARR skipping this subtitles because we can't decode the file using the "
"guessed encoding. It's probably a binary file: " + subtitle_path)
continue
if bool(re.search(hi_regex, text)):
subtitles[subtitle] = Language.rebuild(subtitles[subtitle], forced=False, hi=True)
return subtitles return subtitles