diff --git a/bazarr.py b/bazarr.py index 9545c9e03..1fc02cbf4 100644 --- a/bazarr.py +++ b/bazarr.py @@ -21,6 +21,7 @@ from fdsend import send_file import urllib from init_db import * +from update_db import * from get_languages import * from get_providers import * @@ -38,7 +39,7 @@ import logging from logging.handlers import TimedRotatingFileHandler logger = logging.getLogger('waitress') -db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) +db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() c.execute("SELECT log_level FROM table_settings_general") log_level = c.fetchone() @@ -68,7 +69,7 @@ def configure_logging(): f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|', '%d/%m/%Y %H:%M:%S') fh.setFormatter(f) - logging.getLogger("enzyme").setLevel(logging.ERROR) + logging.getLogger("enzyme").setLevel(logging.CRITICAL) logging.getLogger("apscheduler").setLevel(logging.WARNING) logging.getLogger("subliminal").setLevel(logging.ERROR) root = logging.getLogger() @@ -96,7 +97,7 @@ def image_proxy(url): @route(base_url) def series(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db.create_function("path_substitution", 1, path_replace) c = db.cursor() c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster FROM table_shows ORDER BY title") @@ -126,7 +127,7 @@ def edit_series(no): else: hi = "False" - conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = conn.cursor() c.execute("UPDATE table_shows SET languages = ?, hearing_impaired = ? WHERE tvdbId LIKE ?", (str(lang), hi, no)) conn.commit() @@ -138,7 +139,7 @@ def edit_series(no): @route(base_url + 'episodes/', method='GET') def episodes(no): - conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) conn.create_function("path_substitution", 1, path_replace) c = conn.cursor() @@ -173,7 +174,7 @@ def search_missing_subtitles(no): @route(base_url + 'history') def history(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() c.execute("SELECT COUNT(*) FROM table_history") @@ -193,7 +194,7 @@ def history(): @route(base_url + 'wanted') def wanted(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db.create_function("path_substitution", 1, path_replace) c = db.cursor() @@ -221,7 +222,7 @@ def wanted_search_missing_subtitles_list(): @route(base_url + 'settings') def settings(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() c.execute("SELECT * FROM table_settings_general") settings_general = c.fetchone() @@ -238,7 +239,7 @@ def settings(): def save_settings(): ref = request.environ['HTTP_REFERER'] - conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = conn.cursor() settings_general_ip = request.forms.get('settings_general_ip') @@ -437,7 +438,7 @@ def get_subtitle(): sonarrEpisodeId = request.forms.get('sonarrEpisodeId') tvdbid = request.forms.get('tvdbid') - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() c.execute("SELECT name FROM table_settings_providers WHERE enabled = 1") providers = c.fetchall() diff --git a/get_episodes.py b/get_episodes.py index f8ad5ab34..c8c5b16cf 100644 --- a/get_episodes.py +++ b/get_episodes.py @@ -7,7 +7,7 @@ from list_subtitles import * def update_all_episodes(): # Open database connection - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Get Sonarr API URL from database config table @@ -67,7 +67,7 @@ def update_all_episodes(): def add_new_episodes(): # Open database connection - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Get Sonarr API URL from database config table diff --git a/get_general_settings.py b/get_general_settings.py index c8c770e0e..35b477569 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -3,7 +3,7 @@ import os import ast # Open database connection -db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) +db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Get general settings from database table diff --git a/get_languages.py b/get_languages.py index efb7cc4b0..6189cd67e 100644 --- a/get_languages.py +++ b/get_languages.py @@ -8,7 +8,7 @@ langs = [[lang.alpha_3,lang.alpha_2,lang.name] if hasattr(lang, 'alpha_2')] # Open database connection -db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) +db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Insert languages in database table diff --git a/get_providers.py b/get_providers.py index c02e5c126..9442a4d60 100644 --- a/get_providers.py +++ b/get_providers.py @@ -6,7 +6,7 @@ from subliminal import * providers_list = sorted(provider_manager.names()) # Open database connection -db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) +db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Insert providers in database table diff --git a/get_series.py b/get_series.py index 07c52f924..dd3046755 100644 --- a/get_series.py +++ b/get_series.py @@ -6,7 +6,7 @@ from get_sonarr_settings import * def update_series(): # Open database connection - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() if apikey_sonarr == None: diff --git a/get_sonarr_settings.py b/get_sonarr_settings.py index bf64883b4..fd0b3aa5c 100644 --- a/get_sonarr_settings.py +++ b/get_sonarr_settings.py @@ -3,7 +3,7 @@ import os import ast # Open database connection -db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) +db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Get Sonarr API URL from database config table diff --git a/get_subtitle.py b/get_subtitle.py index 48c1c9e12..45d7402f2 100644 --- a/get_subtitle.py +++ b/get_subtitle.py @@ -30,7 +30,7 @@ def download_subtitle(path, language, hi, providers): return None def series_download_subtitles(no): - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), tmieout=30) c_db = conn_db.cursor() episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall() series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone() @@ -50,7 +50,7 @@ def series_download_subtitles(no): list_missing_subtitles(no) def wanted_download_subtitles(path): - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() episodes_details = c_db.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, table_shows.hearing_impaired FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.path = ? AND missing_subtitles != '[]'", (path_replace_reverse(path),)).fetchall() enabled_providers = c_db.execute("SELECT name FROM table_settings_providers WHERE enabled = 1").fetchall() @@ -69,7 +69,7 @@ def wanted_download_subtitles(path): history_log(1, episode[3], episode[2], message) def wanted_search_missing_subtitles(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) db.create_function("path_substitution", 1, path_replace) c = db.cursor() diff --git a/init_db.py b/init_db.py index 1a9e6304f..5b8e92f93 100644 --- a/init_db.py +++ b/init_db.py @@ -34,7 +34,7 @@ else: fd.close() # Open database connection - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Execute script and commit change to database diff --git a/list_subtitles.py b/list_subtitles.py index 4161eaf06..fe7649114 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -54,7 +54,7 @@ def store_subtitles(file): for subtitle, language in subtitles.iteritems(): actual_subtitles.append([str(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')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse(file))) @@ -70,7 +70,7 @@ def list_missing_subtitles(*no): query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0]) except: pass - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() episodes_subtitles = c_db.execute("SELECT table_episodes.sonarrEpisodeId, table_episodes.subtitles, table_shows.languages FROM table_episodes INNER JOIN table_shows on table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId" + query_string).fetchall() c_db.close() @@ -94,14 +94,14 @@ def list_missing_subtitles(*no): missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list)) missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles[0]])) - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() c_db.executemany("UPDATE table_episodes SET missing_subtitles = ? WHERE sonarrEpisodeId = ?", (missing_subtitles_global)) conn_db.commit() c_db.close() def full_scan_subtitles(): - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() episodes = c_db.execute("SELECT path FROM table_episodes").fetchall() c_db.close() @@ -110,7 +110,7 @@ def full_scan_subtitles(): store_subtitles(path_replace(episode[0])) def series_scan_subtitles(no): - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() episodes = c_db.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall() c_db.close() @@ -121,7 +121,7 @@ def series_scan_subtitles(no): list_missing_subtitles(no) def new_scan_subtitles(): - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c_db = conn_db.cursor() episodes = c_db.execute("SELECT path FROM table_episodes WHERE subtitles is null").fetchall() c_db.close() diff --git a/update_db.py b/update_db.py new file mode 100644 index 000000000..a4e1b01ec --- /dev/null +++ b/update_db.py @@ -0,0 +1,25 @@ +import os +import sqlite3 + +# Check if database exist +if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) == True: + # Open database connection + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) + c = db.cursor() + + # Execute table modification + try: + c.execute('alter table table_settings_providers add column "username" "text"') + except: + pass + + try: + c.execute('alter table table_settings_providers add column "password" "text"') + except: + pass + + # Commit change to db + db.commit() + + # Close database connection + db.close() diff --git a/utils.py b/utils.py index 68adf89ad..21884bd2f 100644 --- a/utils.py +++ b/utils.py @@ -4,7 +4,7 @@ import time def history_log(action, sonarrSeriesId, sonarrEpisodeId, description): # Open database connection - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() # Get Sonarr API URL from database config table