From c1c7ba5dc344c9b79d842e81a5ef4a03ff5df7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 8 May 2020 00:22:14 -0400 Subject: [PATCH] WIP --- bazarr/config.py | 59 ++++++++++++++++++++++++++++++++++++ bazarr/init.py | 12 ++------ bazarr/main.py | 14 ++------- bazarr/scheduler.py | 21 +++++++------ views/settingsgeneral.html | 2 -- views/settingsscheduler.html | 3 +- 6 files changed, 77 insertions(+), 34 deletions(-) diff --git a/bazarr/config.py b/bazarr/config.py index 71e580a96..f29ed5bbe 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -157,6 +157,12 @@ base_url = settings.general.base_url def save_settings(settings_items): from database import database + + configure_debug = False + configure_captcha = False + update_schedule = False + configure_proxy = False + for key, value in settings_items: # Intercept database stored settings if key == 'enabled_languages': @@ -184,12 +190,40 @@ def save_settings(settings_items): if key == 'settings-auth-password': value = hashlib.md5(value.encode('utf-8')).hexdigest() + if key == 'settings-general-debug': + configure_debug = True + + if key in ['settings-general-anti_captcha_provider', 'settings-anticaptcha-anti_captcha_key', + 'settings-deathbycaptcha-username', 'settings-deathbycaptcha-password']: + configure_captcha = True + + if key == 'update_schedule': + update_schedule = True + + if key in ['settings-proxy-type', 'settings-proxy-url', 'settings-proxy-port', 'settings-proxy-username', + 'settings-proxy-password']: + configure_proxy = True + if settings_keys[0] == 'settings': settings[settings_keys[1]][settings_keys[2]] = str(value) with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: settings.write(handle) + # Reconfigure Bazarr to reflect changes + if configure_debug: + from logger import configure_logging + configure_logging(settings.general.getboolean('debug') or args.debug) + + if configure_captcha: + configure_captcha_func() + + if update_schedule: + from scheduler import update_configurable_tasks + update_configurable_tasks() + + if configure_proxy: + configure_proxy_func() def url_sonarr(): @@ -253,3 +287,28 @@ def url_radarr_short(): settings.radarr.base_url = settings.radarr.base_url[:-1] return protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port + + +def configure_captcha_func(): + # set anti-captcha provider and key + if settings.general.anti_captcha_provider == 'anti-captcha' and settings.anticaptcha.anti_captcha_key != "": + os.environ["ANTICAPTCHA_CLASS"] = 'AntiCaptchaProxyLess' + os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(settings.anticaptcha.anti_captcha_key) + elif settings.general.anti_captcha_provider == 'death-by-captcha' and settings.deathbycaptcha.username != "" and \ + settings.deathbycaptcha.password != "": + os.environ["ANTICAPTCHA_CLASS"] = 'DeathByCaptchaProxyLess' + os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(':'.join( + {settings.deathbycaptcha.username, settings.deathbycaptcha.password})) + else: + os.environ["ANTICAPTCHA_CLASS"] = '' + +def configure_proxy_func(): + if settings.proxy.type != 'None': + if settings.proxy.username != '' and settings.proxy.password != '': + proxy = settings.proxy.type + '://' + settings.proxy.username + ':' + settings.proxy.password + '@' + \ + settings.proxy.url + ':' + settings.proxy.port + else: + proxy = settings.proxy.type + '://' + settings.proxy.url + ':' + settings.proxy.port + os.environ['HTTP_PROXY'] = str(proxy) + os.environ['HTTPS_PROXY'] = str(proxy) + os.environ['NO_PROXY'] = str(settings.proxy.exclude) \ No newline at end of file diff --git a/bazarr/init.py b/bazarr/init.py index 1a6c2831b..d37947de5 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -5,7 +5,7 @@ import time import rarfile from cork import Cork -from config import settings +from config import settings, configure_captcha_func from get_args import args from logger import configure_logging from helper import create_path_mapping_dict @@ -18,15 +18,7 @@ import datetime os.environ["SZ_USER_AGENT"] = "Bazarr/1" # set anti-captcha provider and key -if settings.general.anti_captcha_provider == 'anti-captcha' and settings.anticaptcha.anti_captcha_key != "": - os.environ["ANTICAPTCHA_CLASS"] = 'AntiCaptchaProxyLess' - os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(settings.anticaptcha.anti_captcha_key) -elif settings.general.anti_captcha_provider == 'death-by-captcha' and settings.deathbycaptcha.username != "" and settings.deathbycaptcha.password != "": - os.environ["ANTICAPTCHA_CLASS"] = 'DeathByCaptchaProxyLess' - os.environ["ANTICAPTCHA_ACCOUNT_KEY"] = str(':'.join( - {settings.deathbycaptcha.username, settings.deathbycaptcha.password})) -else: - os.environ["ANTICAPTCHA_CLASS"] = '' +configure_captcha_func() # Check if args.config_dir exist if not os.path.exists(args.config_dir): diff --git a/bazarr/main.py b/bazarr/main.py index ae04375ae..21faa9e56 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -11,11 +11,9 @@ import sys import libs import io -import pretty import ast import hashlib import warnings -import queueconfig import apprise import requests import calendar @@ -23,7 +21,7 @@ import calendar from get_args import args from logger import empty_log -from config import settings, url_sonarr, url_radarr, url_radarr_short, url_sonarr_short, base_url +from config import settings, url_sonarr, url_radarr, url_radarr_short, url_sonarr_short, base_url, configure_proxy_func from init import * import logging @@ -62,15 +60,7 @@ scheduler = Scheduler() if args.release_update: check_and_apply_update() -if settings.proxy.type != 'None': - if settings.proxy.username != '' and settings.proxy.password != '': - proxy = settings.proxy.type + '://' + settings.proxy.username + ':' + settings.proxy.password + '@' + \ - settings.proxy.url + ':' + settings.proxy.port - else: - proxy = settings.proxy.type + '://' + settings.proxy.url + ':' + settings.proxy.port - os.environ['HTTP_PROXY'] = str(proxy) - os.environ['HTTPS_PROXY'] = str(proxy) - os.environ['NO_PROXY'] = str(settings.proxy.exclude) +configure_proxy_func() # Reset restart required warning on start database.execute("UPDATE system SET configured='0', updated='0'") diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index 6f358fe2c..cf005d482 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -47,14 +47,14 @@ class Scheduler: self.aps_scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) # configure all tasks - self.__sonarr_update_task() - self.__radarr_update_task() self.__cache_cleanup_task() self.update_configurable_tasks() self.aps_scheduler.start() def update_configurable_tasks(self): + self.__sonarr_update_task() + self.__radarr_update_task() self.__sonarr_full_update_task() self.__radarr_full_update_task() self.__update_bazarr_task() @@ -142,17 +142,20 @@ class Scheduler: def __sonarr_update_task(self): if settings.general.getboolean('use_sonarr'): self.aps_scheduler.add_job( - update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15, - id='update_series', name='Update Series list from Sonarr') + update_series, IntervalTrigger(minutes=int(settings.sonarr.series_sync)), max_instances=1, + coalesce=True, misfire_grace_time=15, id='update_series', name='Update Series list from Sonarr', + replace_existing=True) self.aps_scheduler.add_job( - sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, - id='sync_episodes', name='Sync episodes with Sonarr') + sync_episodes, IntervalTrigger(minutes=int(settings.sonarr.episodes_sync)), max_instances=1, + coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr', + replace_existing=True) def __radarr_update_task(self): if settings.general.getboolean('use_radarr'): self.aps_scheduler.add_job( - update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, - id='update_movies', name='Update Movie list from Radarr') + update_movies, IntervalTrigger(minutes=int(settings.radarr.movies_sync)), max_instances=1, + coalesce=True, misfire_grace_time=15, id='update_movies', name='Update Movie list from Radarr', + replace_existing=True) def __cache_cleanup_task(self): self.aps_scheduler.add_job(cache_maintenance, IntervalTrigger(hours=24), max_instances=1, coalesce=True, @@ -228,7 +231,7 @@ class Scheduler: name='Search for wanted Series Subtitles', replace_existing=True) if settings.general.getboolean('use_radarr'): self.aps_scheduler.add_job( - wanted_search_missing_subtitles_movies, IntervalTrigger(hours=int(settings.general.wanted_search_frequency)), + wanted_search_missing_subtitles_movies, IntervalTrigger(hours=int(settings.general.wanted_search_frequency_movie)), max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles_movies', name='Search for wanted Movies Subtitles', replace_existing=True) diff --git a/views/settingsgeneral.html b/views/settingsgeneral.html index 6dc0627e8..38c686a4e 100644 --- a/views/settingsgeneral.html +++ b/views/settingsgeneral.html @@ -79,7 +79,6 @@
-{# #}
@@ -128,7 +127,6 @@
-
diff --git a/views/settingsscheduler.html b/views/settingsscheduler.html index 1a5edb2e0..6f5446860 100644 --- a/views/settingsscheduler.html +++ b/views/settingsscheduler.html @@ -246,12 +246,13 @@ $('#settings-radarr-full_update_day').val('{{settings.radarr.full_update_day}}').trigger('change'); $('#settings-radarr-full_update_hour').val('{{settings.radarr.full_update_hour}}').trigger('change'); $('#settings-general-wanted_search_frequency').val('{{settings.general.wanted_search_frequency}}').trigger('change'); - $('#settings-general-wanted_search_frequency_movie').val('{{settings.general.wanted_search_frequency}}').trigger('change'); + $('#settings-general-wanted_search_frequency_movie').val('{{settings.general.wanted_search_frequency_movie}}').trigger('change'); $('#settings-general-upgrade_frequency').val('{{settings.general.upgrade_frequency}}').trigger('change'); $('.selectpicker').selectpicker('refresh') $('#save_button').on('click', function() { var formdata = new FormData(document.getElementById("settings_form")); + formdata.append('update_schedule', 'true'); // Make sure all checkbox input are sent with true/false value $('input[type=checkbox]').each(function () {