From 3d98836f3b84cc52ba66de0186cba71689d33749 Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 29 Jul 2018 22:39:37 -0400 Subject: [PATCH] Aded option to ignore embedded subtitles #69 --- bazarr.py | 7 ++++++- get_general_settings.py | 6 ++++-- list_subtitles.py | 28 ++++++++++++++++++++++------ update_db.py | 7 +++++++ views/settings.tpl | 25 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/bazarr.py b/bazarr.py index 6f0059435..b6690bfd9 100644 --- a/bazarr.py +++ b/bazarr.py @@ -682,6 +682,11 @@ def save_settings(): settings_general_scenename = 'False' else: settings_general_scenename = 'True' + settings_general_embedded = request.forms.get('settings_general_embedded') + if settings_general_embedded is None: + settings_general_embedded = 'False' + else: + settings_general_embedded = 'True' settings_general_minimum_score = request.forms.get('settings_general_minimum_score') settings_general_use_postprocessing = request.forms.get('settings_general_use_postprocessing') if settings_general_use_postprocessing is None: @@ -703,7 +708,7 @@ def save_settings(): before = c.execute("SELECT ip, port, base_url, log_level, path_mapping, use_sonarr, use_radarr, path_mapping_movie FROM table_settings_general").fetchone() after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_loglevel), unicode(settings_general_pathmapping), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie)) - c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?, use_sonarr=?, use_radarr=?, path_mapping_movie=?, page_size=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie), unicode(settings_page_size))) + c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?, use_sonarr=?, use_radarr=?, path_mapping_movie=?, page_size=?, use_embedded_subs=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie), unicode(settings_page_size), unicode(settings_general_embedded))) conn.commit() if after != before: configured() diff --git a/get_general_settings.py b/get_general_settings.py index 219cb1646..9254f0d5a 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -50,8 +50,9 @@ def get_general_settings(): movie_default_language = general_settings[21] movie_default_hi = general_settings[22] page_size = general_settings[23] + use_embedded_subs = general_settings[24] - return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size] + return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size, use_embedded_subs] def path_replace(path): for path_mapping in path_mappings: @@ -129,4 +130,5 @@ serie_default_hi = result[17] movie_default_enabled = result[18] movie_default_language = result[19] movie_default_hi = result[20] -page_size = result[21] \ No newline at end of file +page_size = result[21] +use_embedded_subs = result[22] \ No newline at end of file diff --git a/list_subtitles.py b/list_subtitles.py index de2f372f6..6dc6f3766 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -25,7 +25,8 @@ def store_subtitles(file): for subtitle_track in mkv.subtitle_tracks: try: - actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)),None]) + if alpha2_from_alpha3(subtitle_track.language) != None: + actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)),None]) except: pass except: @@ -79,7 +80,8 @@ def store_subtitles_movie(file): for subtitle_track in mkv.subtitle_tracks: try: - actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)), None]) + if alpha2_from_alpha3(subtitle_track.language) != None: + actual_subtitles.append([str(alpha2_from_alpha3(subtitle_track.language)), None]) except: pass except: @@ -131,13 +133,20 @@ def list_missing_subtitles(*no): c_db.close() missing_subtitles_global = [] - + use_embedded_subs = get_general_settings()[22] for episode_subtitles in episodes_subtitles: + actual_subtitles_temp = [] actual_subtitles = [] desired_subtitles = [] missing_subtitles = [] if episode_subtitles[1] != None: - actual_subtitles = ast.literal_eval(episode_subtitles[1]) + if use_embedded_subs == "True": + actual_subtitles = ast.literal_eval(episode_subtitles[1]) + else: + actual_subtitles_temp = ast.literal_eval(episode_subtitles[1]) + for subtitle in actual_subtitles_temp: + if subtitle[1] != None: + actual_subtitles.append(subtitle) if episode_subtitles[2] != None: desired_subtitles = ast.literal_eval(episode_subtitles[2]) actual_subtitles_list = [] @@ -171,13 +180,20 @@ def list_missing_subtitles_movies(*no): c_db.close() missing_subtitles_global = [] - + use_embedded_subs = get_general_settings()[22] for movie_subtitles in movies_subtitles: + actual_subtitles_temp = [] actual_subtitles = [] desired_subtitles = [] missing_subtitles = [] if movie_subtitles[1] != None: - actual_subtitles = ast.literal_eval(movie_subtitles[1]) + if use_embedded_subs == "True": + actual_subtitles = ast.literal_eval(movie_subtitles[1]) + else: + actual_subtitles_temp = ast.literal_eval(movie_subtitles[1]) + for subtitle in actual_subtitles_temp: + if subtitle[1] != None: + actual_subtitles.append(subtitle) if movie_subtitles[2] != None: desired_subtitles = ast.literal_eval(movie_subtitles[2]) actual_subtitles_list = [] diff --git a/update_db.py b/update_db.py index 16dcfe616..302f1b0e2 100644 --- a/update_db.py +++ b/update_db.py @@ -171,6 +171,13 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) except: pass + try: + c.execute('alter table table_settings_general add column "use_embedded_subs" "text"') + except: + pass + else: + c.execute('UPDATE table_settings_general SET use_embedded_subs="True"') + # Commit change to db db.commit() diff --git a/views/settings.tpl b/views/settings.tpl index f7780bddf..6be43df0b 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -764,6 +764,25 @@ + +