From bc321392f2c83e3304ce0b49ef184ac67f39a652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:24:47 -0400 Subject: [PATCH] Fix for history logging. --- bazarr/get_subtitle.py | 8 ++++---- bazarr/main.py | 4 ++-- bazarr/utils.py | 28 ++++++++++++---------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index 0d4b834e8..1305e89df 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -505,7 +505,7 @@ def series_download_subtitles(no): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] store_subtitles(path_replace(episode[0])) @@ -547,7 +547,7 @@ def episode_download_subtitles(no): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] store_subtitles(path_replace(episode[0])) @@ -636,7 +636,7 @@ def wanted_download_subtitles(path, l, count_episodes): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] store_subtitles(path_replace(episode[0])) @@ -905,7 +905,7 @@ def upgrade_subtitles(): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] store_subtitles(path_replace(episode[0])) diff --git a/bazarr/main.py b/bazarr/main.py index c66b92e1b..37c249f6d 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1835,7 +1835,7 @@ def get_subtitle(): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) @@ -1893,7 +1893,7 @@ def manual_get_subtitle(): message = result[0] path = result[1] forced = result[5] - language_code = result[2] + ":forced" if forced else "" + language_code = result[2] + ":forced" if forced else result[2] provider = result[3] score = result[4] history_log(2, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) diff --git a/bazarr/utils.py b/bazarr/utils.py index 7432abf6e..5e8fe4cdd 100644 --- a/bazarr/utils.py +++ b/bazarr/utils.py @@ -14,18 +14,14 @@ def history_log(action, sonarrSeriesId, sonarrEpisodeId, description, video_path # Open database connection db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() - - if forced: - language = language + ":forced" - - # Get Sonarr API URL from database config table + history = c.execute( '''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''', (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description, video_path, language, provider, score)) - + # Commit changes to DB db.commit() - + # Close database connection db.close() @@ -35,38 +31,38 @@ def history_log_movie(action, radarrId, description, video_path=None, language=N # Open database connection db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() - + if forced: language = language + ":forced" - + history = c.execute( '''INSERT INTO table_history_movie(action, radarrId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''', (action, radarrId, time.time(), description, video_path, language, provider, score)) - + # Commit changes to DB db.commit() - + # Close database connection db.close() def get_binary(name): binaries_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'bin')) - + exe = None installed_exe = which(name) - + if installed_exe and os.path.isfile(installed_exe): return installed_exe else: if platform.system() == "Windows": # Windows exe = os.path.abspath(os.path.join(binaries_dir, "Windows", "i386", name, "%s.exe" % name)) - + elif platform.system() == "Darwin": # MacOSX exe = os.path.abspath(os.path.join(binaries_dir, "MacOSX", "i386", name, name)) - + elif platform.system() == "Linux": # Linux exe = os.path.abspath(os.path.join(binaries_dir, "Linux", platform.machine(), name, name)) - + if exe and os.path.isfile(exe): return exe