From b732538366e23ac6bc3ea4dd64007d62d1f005af Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 13 Jan 2018 09:21:12 -0500 Subject: [PATCH] Correction about #36 --- list_subtitles.py | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/list_subtitles.py b/list_subtitles.py index 2ad8e5ec3..87d17846c 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -10,41 +10,6 @@ import chardet from get_general_settings import * -def list_subtitles(file): - languages = [] - actual_subtitles = [] - if os.path.exists(file): - if os.path.splitext(file)[1] == '.mkv': - try: - with open(file, 'rb') as f: - mkv = enzyme.MKV(f) - - for subtitle_track in mkv.subtitle_tracks: - try: - languages.append([str(pycountry.languages.lookup(subtitle_track.language).alpha_2),None]) - except: - pass - except: - print file - #pass - - subtitles = core.search_external_subtitles(file) - - for subtitle, language in subtitles.iteritems(): - if str(language) != 'und': - actual_subtitles.append([str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))]) - else: - with open(path_replace(os.path.join(os.path.dirname(file), subtitle)), 'r') as f: - text = [next(f) for x in xrange(5)] - text = ' '.join(text) - encoding = chardet.detect(text)['encoding'] - text = text.decode(encoding) - 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))]) - - return actual_subtitles - def store_subtitles(file): languages = [] actual_subtitles = [] @@ -71,10 +36,12 @@ def store_subtitles(file): else: with open(path_replace(os.path.join(os.path.dirname(file), subtitle)), 'r') as f: text = [next(f) for x in xrange(20)] - text = ' '.join(text).decode('iso-8859-1') + text = ' '.join(text) + encoding = chardet.detect(text)['encoding'] + text = text.decode(encoding) detected_language = langdetect.detect(text) if len(detected_language) > 0: - actual_subtitles.append([str(detected_language), unicode(path_replace_reverse(os.path.join(os.path.dirname(file), subtitle)))]) + actual_subtitles.append([str(detected_language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))]) conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor()