diff --git a/bazarr/config.py b/bazarr/config.py index 0f40dedd7..14791a3f2 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -31,7 +31,6 @@ defaults = { 'page_size': '25', 'minimum_score_movie': '70', 'use_embedded_subs': 'True', - 'only_monitored': 'False', 'adaptive_searching': 'False', 'enabled_providers': '' }, @@ -46,7 +45,8 @@ defaults = { 'base_url': '/', 'ssl': 'False', 'apikey': '', - 'full_update': 'Daily' + 'full_update': 'Daily', + 'only_monitored': 'False', }, 'radarr': { 'ip': '127.0.0.1', @@ -54,7 +54,8 @@ defaults = { 'base_url': '/', 'ssl': 'False', 'apikey': '', - 'full_update': 'Daily' + 'full_update': 'Daily', + 'only_monitored': 'False', }, 'proxy': { 'type': 'None', diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 2c83f8482..f1ca5e960 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -35,7 +35,7 @@ def sync_episodes(): c = db.cursor() # Get current episodes id in DB - current_episodes_db = c.execute('SELECT sonarrEpisodeId FROM table_episodes').fetchall() + current_episodes_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall() current_episodes_db_list = [x[0] for x in current_episodes_db] current_episodes_sonarr = [] @@ -109,15 +109,16 @@ def sync_episodes(): c.execute('DELETE FROM table_episodes WHERE sonarrEpisodeId = ?', (removed_episode,)) db.commit() + # Get episodes list after INSERT and UPDATE + episodes_now_in_db = c.execute('SELECT sonarrEpisodeId, path FROM table_episodes').fetchall() + # Close database connection c.close() - # TODO: Commented until I find a way to make it store only episodes really updated. - #for updated_episode in episodes_to_update: - # store_subtitles(path_replace(updated_episode[1])) - - for added_episode in episodes_to_add: - store_subtitles(path_replace(added_episode[3])) + # Get only episodes added or modified and store subtitles for them + altered_episodes = set(episodes_now_in_db).difference(set(current_episodes_db)) + for altered_episode in altered_episodes: + store_subtitles(path_replace(altered_episode[1])) logging.debug('BAZARR All episodes synced from Sonarr into database.') diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index dba586154..d3df675a5 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -42,7 +42,7 @@ def update_movies(): # Get current movies in DB db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() - current_movies_db = c.execute('SELECT tmdbId FROM table_movies').fetchall() + current_movies_db = c.execute('SELECT tmdbId, path FROM table_movies').fetchall() db.close() current_movies_db_list = [x[0] for x in current_movies_db] @@ -106,23 +106,23 @@ def update_movies(): else: added_result = c.executemany('''INSERT OR IGNORE INTO table_movies(title, path, tmdbId, languages, subtitles,`hearing_impaired`, radarrId, overview, poster, fanart, `audio_language`, sceneName, monitored, sortTitle) VALUES (?,?,?,(SELECT languages FROM table_movies WHERE tmdbId = ?), '[]',(SELECT `hearing_impaired` FROM table_movies WHERE tmdbId = ?), ?, ?, ?, ?, ?, ?, ?, ?)''', movies_to_add) db.commit() - db.close() removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr)) - db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) - c = db.cursor() for removed_movie in removed_movies: c.execute('DELETE FROM table_movies WHERE tmdbId = ?', (removed_movie,)) - db.commit() - db.close() + db.commit() - for added_movie in movies_to_add: - store_subtitles_movie(path_replace_movie(added_movie[1])) + # Get movies list after INSERT and UPDATE + movies_now_in_db = c.execute('SELECT tmdbId, path FROM table_movies').fetchall() + + # Close database connection + db.close() - # TODO: Commented until I find a way to make it store only episodes really updated. - # for updated_movie in movies_to_update: - # store_subtitles_movie(path_replace_movie(updated_movie[1])) + # Get only movies added or modified and store subtitles for them + altered_movies = set(movies_now_in_db).difference(set(current_movies_db)) + for altered_movie in altered_movies: + store_subtitles_movie(path_replace_movie(altered_movie[1])) logging.debug('BAZARR All movies synced from Radarr into database.') diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index b82fc7d80..6255b0ccc 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -467,13 +467,13 @@ def manual_download_subtitle(path, language, hi, subtitle, provider, providers_a return message else: logging.error( - 'BAZARR Tried to manually download a subtitles for file: ' + path + " but we weren't able to do (probably throttled by ' + str(subtitle.provider_name) + '. Please retry later or select a subtitles from another provider.") + "BAZARR Tried to manually download a subtitles for file: " + path + " but we weren't able to do (probably throttled by " + str(subtitle.provider_name) + ". Please retry later or select a subtitles from another provider.") return None logging.debug('BAZARR Ended manually downloading subtitles for file: ' + path) def series_download_subtitles(no): - if settings.general.getboolean('only_monitored'): + if settings.sonarr.getboolean('only_monitored'): monitored_only_query_string = ' AND monitored = "True"' else: monitored_only_query_string = "" @@ -625,17 +625,22 @@ def wanted_search_missing_subtitles(): db.create_function("path_substitution_movie", 1, path_replace_movie) c = db.cursor() - if settings.general.getboolean('only_monitored'): - monitored_only_query_string = ' AND monitored = "True"' + if settings.sonarr.getboolean('only_monitored'): + monitored_only_query_string_sonarr = ' AND monitored = "True"' else: - monitored_only_query_string = "" + monitored_only_query_string_sonarr = "" + + if settings.radarr.getboolean('only_monitored'): + monitored_only_query_string_radarr = ' AND monitored = "True"' + else: + monitored_only_query_string_radarr = "" c.execute( - "SELECT path_substitution(path) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string) + "SELECT path_substitution(path) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string_sonarr) episodes = c.fetchall() c.execute( - "SELECT path_substitution_movie(path) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string) + "SELECT path_substitution_movie(path) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string_radarr) movies = c.fetchall() c.close() @@ -652,7 +657,7 @@ def wanted_search_missing_subtitles(): def search_active(timestamp): - if settings.general.getboolean('only_monitored'): + if settings.general.getboolean('adaptive_searching'): search_deadline = timedelta(weeks=3) search_delta = timedelta(weeks=1) aa = datetime.fromtimestamp(float(timestamp)) diff --git a/bazarr/init.py b/bazarr/init.py index 530a8c88f..80ab440c5 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -6,7 +6,10 @@ import logging import time from cork import Cork -from configparser2 import ConfigParser +try: + from configparser import ConfigParser +except ImportError: + from configparser2 import ConfigParser from config import settings from check_update import check_releases from get_args import args @@ -84,6 +87,14 @@ if cfg.has_section('general'): cfg.set('general', 'debug', 'False') with open(config_file, 'w+') as configfile: cfg.write(configfile) + + if cfg.has_option('general', 'only_monitored'): + only_monitored = cfg.get('general', 'only_monitored') + cfg.set('sonarr', 'only_monitored', str(only_monitored)) + cfg.set('radarr', 'only_monitored', str(only_monitored)) + cfg.remove_option('general', 'only_monitored') + with open(config_file, 'w+') as configfile: + cfg.write(configfile) # Move providers settings from DB to config file try: @@ -95,9 +106,13 @@ try: db.close() providers_list = [] - if len(enabled_providers) > 0: + if enabled_providers: for provider in enabled_providers: providers_list.append(provider[0]) + else: + providers_list = None + + if settings_providers: for provider in settings_providers: if provider[0] == 'opensubtitles': settings.opensubtitles.username = provider[2] @@ -108,8 +123,6 @@ try: elif provider[0] == 'legendastv': settings.legendastv.username = provider[2] settings.legendastv.password = provider[3] - else: - providers_list = None settings.general.enabled_providers = u'' if not providers_list else ','.join(providers_list) with open(os.path.join(config_dir, 'config', 'config.ini'), 'w+') as handle: diff --git a/bazarr/main.py b/bazarr/main.py index 7973e0837..8bea99b81 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -259,11 +259,6 @@ def save_wizard(): settings_general_single_language = 'False' else: settings_general_single_language = 'True' - settings_general_adaptive_searching = request.forms.get('settings_general_adaptive_searching') - if settings_general_adaptive_searching is None: - settings_general_adaptive_searching = 'False' - else: - settings_general_adaptive_searching = 'True' settings_general_use_sonarr = request.forms.get('settings_general_use_sonarr') if settings_general_use_sonarr is None: settings_general_use_sonarr = 'False' @@ -283,7 +278,6 @@ def save_wizard(): settings.general.use_sonarr = text_type(settings_general_use_sonarr) settings.general.use_radarr = text_type(settings_general_use_radarr) settings.general.path_mappings_movie = text_type(settings_general_pathmapping_movie) - settings.general.adaptive_searching = text_type(settings_general_adaptive_searching) settings_sonarr_ip = request.forms.get('settings_sonarr_ip') settings_sonarr_port = request.forms.get('settings_sonarr_port') @@ -294,12 +288,18 @@ def save_wizard(): else: settings_sonarr_ssl = 'True' settings_sonarr_apikey = request.forms.get('settings_sonarr_apikey') + settings_sonarr_only_monitored = request.forms.get('settings_sonarr_only_monitored') + if settings_sonarr_only_monitored is None: + settings_sonarr_only_monitored = 'False' + else: + settings_sonarr_only_monitored = 'True' settings.sonarr.ip = text_type(settings_sonarr_ip) settings.sonarr.port = text_type(settings_sonarr_port) settings.sonarr.base_url = text_type(settings_sonarr_baseurl) settings.sonarr.ssl = text_type(settings_sonarr_ssl) settings.sonarr.apikey = text_type(settings_sonarr_apikey) + settings.sonarr.only_monitored = text_type(settings_sonarr_only_monitored) settings_radarr_ip = request.forms.get('settings_radarr_ip') settings_radarr_port = request.forms.get('settings_radarr_port') @@ -310,16 +310,18 @@ def save_wizard(): else: settings_radarr_ssl = 'True' settings_radarr_apikey = request.forms.get('settings_radarr_apikey') - if settings_radarr_apikey != '': - settings.general.use_radarr = 'True' + settings_radarr_only_monitored = request.forms.get('settings_radarr_only_monitored') + if settings_radarr_only_monitored is None: + settings_radarr_only_monitored = 'False' else: - settings.general.use_radarr = 'False' + settings_radarr_only_monitored = 'True' settings.radarr.ip = text_type(settings_radarr_ip) settings.radarr.port = text_type(settings_radarr_port) settings.radarr.base_url = text_type(settings_radarr_baseurl) settings.radarr.ssl = text_type(settings_radarr_ssl) settings.radarr.apikey = text_type(settings_radarr_apikey) + settings.radarr.only_monitored = text_type(settings_radarr_only_monitored) settings_subliminal_providers = request.forms.getall('settings_subliminal_providers') settings.general.enabled_providers = u'' if not settings_subliminal_providers else ','.join(settings_subliminal_providers) @@ -477,7 +479,7 @@ def series(): offset = (int(page) - 1) * page_size max_page = int(math.ceil(missing_count / (page_size + 0.0))) - if settings.general.getboolean('only_monitored'): + if settings.sonarr.getboolean('only_monitored'): monitored_only_query_string = ' AND monitored = "True"' else: monitored_only_query_string = "" @@ -957,7 +959,7 @@ def wantedseries(): db.create_function("path_substitution", 1, path_replace) c = db.cursor() - if settings.general.getboolean('only_monitored'): + if settings.sonarr.getboolean('only_monitored'): monitored_only_query_string = ' AND monitored = "True"' else: monitored_only_query_string = "" @@ -989,7 +991,7 @@ def wantedmovies(): db.create_function("path_substitution", 1, path_replace_movie) c = db.cursor() - if settings.general.getboolean('only_monitored'): + if settings.radarr.getboolean('only_monitored'): monitored_only_query_string = ' AND monitored = "True"' else: monitored_only_query_string = "" @@ -1089,11 +1091,6 @@ def save_settings(): settings_general_embedded = 'False' else: settings_general_embedded = 'True' - settings_general_only_monitored = request.forms.get('settings_general_only_monitored') - if settings_general_only_monitored is None: - settings_general_only_monitored = 'False' - else: - settings_general_only_monitored = 'True' settings_general_adaptive_searching = request.forms.get('settings_general_adaptive_searching') if settings_general_adaptive_searching is None: settings_general_adaptive_searching = 'False' @@ -1140,7 +1137,6 @@ def save_settings(): settings.general.page_size = text_type(settings_page_size) settings.general.minimum_score_movie = text_type(settings_general_minimum_score_movies) settings.general.use_embedded_subs = text_type(settings_general_embedded) - settings.general.only_monitored = text_type(settings_general_only_monitored) settings.general.adaptive_searching = text_type(settings_general_adaptive_searching) if after != before: @@ -1216,6 +1212,11 @@ def save_settings(): else: settings_sonarr_ssl = 'True' settings_sonarr_apikey = request.forms.get('settings_sonarr_apikey') + settings_sonarr_only_monitored = request.forms.get('settings_sonarr_only_monitored') + if settings_sonarr_only_monitored is None: + settings_sonarr_only_monitored = 'False' + else: + settings_sonarr_only_monitored = 'True' settings_sonarr_sync = request.forms.get('settings_sonarr_sync') settings.sonarr.ip = text_type(settings_sonarr_ip) @@ -1223,6 +1224,7 @@ def save_settings(): settings.sonarr.base_url = text_type(settings_sonarr_baseurl) settings.sonarr.ssl = text_type(settings_sonarr_ssl) settings.sonarr.apikey = text_type(settings_sonarr_apikey) + settings.sonarr.only_monitored = text_type(settings_sonarr_only_monitored) settings.sonarr.full_update = text_type(settings_sonarr_sync) settings_radarr_ip = request.forms.get('settings_radarr_ip') @@ -1234,6 +1236,11 @@ def save_settings(): else: settings_radarr_ssl = 'True' settings_radarr_apikey = request.forms.get('settings_radarr_apikey') + settings_radarr_only_monitored = request.forms.get('settings_radarr_only_monitored') + if settings_radarr_only_monitored is None: + settings_radarr_only_monitored = 'False' + else: + settings_radarr_only_monitored = 'True' settings_radarr_sync = request.forms.get('settings_radarr_sync') settings.radarr.ip = text_type(settings_radarr_ip) @@ -1241,6 +1248,7 @@ def save_settings(): settings.radarr.base_url = text_type(settings_radarr_baseurl) settings.radarr.ssl = text_type(settings_radarr_ssl) settings.radarr.apikey = text_type(settings_radarr_apikey) + settings.radarr.only_monitored = text_type(settings_radarr_only_monitored) settings.radarr.full_update = text_type(settings_radarr_sync) settings_subliminal_providers = request.forms.getall('settings_subliminal_providers') @@ -1323,7 +1331,10 @@ def save_settings(): # reschedule full update task according to settings sonarr_full_update() - redirect(ref) + if ref.find('saved=true') > 0: + redirect(ref) + else: + redirect(ref + "?saved=true") @route(base_url + 'check_update') @@ -1754,7 +1765,7 @@ def api_history(): def test_url(protocol, url): url = urllib.unquote(url) try: - result = requests.get(protocol + "://" + url, allow_redirects=False).json()['version'] + result = requests.get(protocol + "://" + url, allow_redirects=False, verify=False).json()['version'] except: return dict(status=False) else: diff --git a/views/menu.tpl b/views/menu.tpl index 48e40680d..399a2a0fa 100644 --- a/views/menu.tpl +++ b/views/menu.tpl @@ -28,16 +28,22 @@ % import sqlite3 % from config import settings - %if settings.general.getboolean('only_monitored'): - % monitored_only_query_string = ' AND monitored = "True"' + %if settings.sonarr.getboolean('only_monitored'): + % monitored_only_query_string_sonarr = ' AND monitored = "True"' %else: - % monitored_only_query_string = "" + % monitored_only_query_string_sonarr = "" + %end + + %if settings.radarr.getboolean('only_monitored'): + % monitored_only_query_string_radarr = ' AND monitored = "True"' + %else: + % monitored_only_query_string_radarr = "" %end % conn = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) % c = conn.cursor() - % wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone() - % wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string).fetchone() + % wanted_series = c.execute("SELECT COUNT(*) FROM table_episodes WHERE missing_subtitles != '[]'" + monitored_only_query_string_sonarr).fetchone() + % wanted_movies = c.execute("SELECT COUNT(*) FROM table_movies WHERE missing_subtitles != '[]'" + monitored_only_query_string_radarr).fetchone()
diff --git a/views/settings.tpl b/views/settings.tpl index 438251940..3cd0fea8b 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -40,7 +40,7 @@
-
Loading...
+
Saving settings...
% include('menu.tpl') @@ -780,6 +780,26 @@
+ +
+
+ +
+
+
+ + +
+
+ +
+ @@ -906,6 +926,26 @@ + +
+
+ +
+
+
+ + +
+
+ +
+ @@ -1020,128 +1060,219 @@
- +
-
- +
+
- +
+
+
Subtitles providers
+
+
- +
-
- +
+
- -
Subtitles providers
-
-
+
- +
-
-
- +
+
+ +
-
-
-
Providers settings (optional)
-
-
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+
+
- +
-
-
-

Username

+
+
+ +
-
-
-

Password (stored in clear text)

+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
- +
-
-
- +
+
+ +
-
-
- +
+
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+
- +
-
-
- +
+
+ +
-
-
- +
+
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+
- +
-
-
- +
+
+ +
-
-
- +
+
+ +
+ + +
+
+
@@ -1348,7 +1479,34 @@