From 3a87391868c5aa70279d23be0a41ada2a388c5f8 Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 14 Mar 2018 16:28:42 -0400 Subject: [PATCH] Added scenename and minimum score settings #48 --- bazarr.py | 10 ++++++-- get_general_settings.py | 8 ++++-- get_subtitle.py | 19 ++++++++------ update_db.py | 14 ++++++++++ views/settings.tpl | 57 ++++++++++++++++++++++++++++++++++++++--- 5 files changed, 93 insertions(+), 15 deletions(-) diff --git a/bazarr.py b/bazarr.py index 9f410e769..599c7f563 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.3.6' +bazarr_version = '0.3.7' import os import sys @@ -394,10 +394,16 @@ def save_settings(): settings_general_single_language = 'False' else: settings_general_single_language = 'True' + settings_general_scenename = request.forms.get('settings_general_scenename') + if settings_general_scenename is None: + settings_general_scenename = 'False' + else: + settings_general_scenename = 'True' + settings_general_minimum_score = request.forms.get('settings_general_minimum_score') before = c.execute("SELECT ip, port, base_url FROM table_settings_general").fetchone() after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl)) - c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?", (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))) + c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?", (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) )) conn.commit() if after != before: configured() diff --git a/get_general_settings.py b/get_general_settings.py index d5175f67d..3e3e5e456 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -27,8 +27,10 @@ def get_general_settings(): branch = general_settings[5] automatic = general_settings[6] single_language = general_settings[9] + minimum_score = general_settings[10] + use_scenename = general_settings[11] - return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language] + return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename] def path_replace(path): for path_mapping in path_mappings: @@ -60,4 +62,6 @@ path_mappings = result[3] log_level = result[4] branch = result[5] automatic = result[6] -single_language = result[7] \ No newline at end of file +single_language = result[7] +minimum_score = result[8] +use_scenename = result[9] diff --git a/get_subtitle.py b/get_subtitle.py index 4ec0ff6ae..d1b45a158 100644 --- a/get_subtitle.py +++ b/get_subtitle.py @@ -14,31 +14,34 @@ from notifier import send_notifications region.configure('dogpile.cache.memory') def download_subtitle(path, language, hi, providers, providers_auth, sceneName): + minimum_score = int(get_general_settings()[8]) + use_scenename = get_general_settings()[9] try: - if sceneName is None: + if sceneName is None or use_scenename == "False": + used_sceneName = False video = scan_video(path) else: + used_sceneName = True video = Video.fromname(sceneName) except Exception as e: logging.exception('Error trying to extract information from this filename: ' + path) return None else: try: - best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, hearing_impaired=hi, provider_configs=providers_auth) - + best_subtitles = download_best_subtitles([video], {Language(language)}, providers=providers, min_score=minimum_score, hearing_impaired=hi, provider_configs=providers_auth) except Exception as e: - logging.exception('Error trying to best subtitles for this file: ' + path) + logging.exception('Error trying to get the best subtitles for this file: ' + path) return None else: try: best_subtitle = best_subtitles[video][0] except: - pass + logging.debug('No subtitles found for ' + path) return None else: single = get_general_settings()[7] try: - if sceneName is not None: + if used_sceneName == True: video = scan_video(path) if single == 'True': result = save_subtitles(video, [best_subtitle], single=True, encoding='utf-8') @@ -50,8 +53,8 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName): else: downloaded_provider = str(result[0]).strip('<>').split(' ')[0][:-8] downloaded_language = pycountry.languages.lookup(str(str(result[0]).strip('<>').split(' ')[2].strip('[]'))).name - if sceneName is not None: - message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using scene name from Sonarr guessing." + if used_sceneName == True: + message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using this scene name obtained from Sonarr: " + sceneName else: message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " using filename guessing." diff --git a/update_db.py b/update_db.py index 2c4b57c88..f1c0cd883 100644 --- a/update_db.py +++ b/update_db.py @@ -58,6 +58,20 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) from scheduler import execute_now execute_now('update_all_episodes') + try: + c.execute('alter table table_settings_general add column "minimum_score" "text"') + except: + pass + else: + c.execute('UPDATE table_settings_general SET minimum_score="0"') + + try: + c.execute('alter table table_settings_general add column "use_scenename" "text"') + except: + pass + else: + c.execute('UPDATE table_settings_general SET use_scenename="True"') + # Commit change to db db.commit() diff --git a/views/settings.tpl b/views/settings.tpl index 2ff7871fb..24faf786b 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -366,11 +366,57 @@