pull/997/head
Louis Vézina 5 years ago
parent 106528977a
commit c1c7ba5dc3

@ -157,6 +157,12 @@ base_url = settings.general.base_url
def save_settings(settings_items): def save_settings(settings_items):
from database import database from database import database
configure_debug = False
configure_captcha = False
update_schedule = False
configure_proxy = False
for key, value in settings_items: for key, value in settings_items:
# Intercept database stored settings # Intercept database stored settings
if key == 'enabled_languages': if key == 'enabled_languages':
@ -184,12 +190,40 @@ def save_settings(settings_items):
if key == 'settings-auth-password': if key == 'settings-auth-password':
value = hashlib.md5(value.encode('utf-8')).hexdigest() 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': if settings_keys[0] == 'settings':
settings[settings_keys[1]][settings_keys[2]] = str(value) settings[settings_keys[1]][settings_keys[2]] = str(value)
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle: with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
settings.write(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(): def url_sonarr():
@ -253,3 +287,28 @@ def url_radarr_short():
settings.radarr.base_url = settings.radarr.base_url[:-1] settings.radarr.base_url = settings.radarr.base_url[:-1]
return protocol_radarr + "://" + settings.radarr.ip + ":" + settings.radarr.port 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)

@ -5,7 +5,7 @@ import time
import rarfile import rarfile
from cork import Cork from cork import Cork
from config import settings from config import settings, configure_captcha_func
from get_args import args from get_args import args
from logger import configure_logging from logger import configure_logging
from helper import create_path_mapping_dict from helper import create_path_mapping_dict
@ -18,15 +18,7 @@ import datetime
os.environ["SZ_USER_AGENT"] = "Bazarr/1" os.environ["SZ_USER_AGENT"] = "Bazarr/1"
# set anti-captcha provider and key # set anti-captcha provider and key
if settings.general.anti_captcha_provider == 'anti-captcha' and settings.anticaptcha.anti_captcha_key != "": configure_captcha_func()
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"] = ''
# Check if args.config_dir exist # Check if args.config_dir exist
if not os.path.exists(args.config_dir): if not os.path.exists(args.config_dir):

@ -11,11 +11,9 @@ import sys
import libs import libs
import io import io
import pretty
import ast import ast
import hashlib import hashlib
import warnings import warnings
import queueconfig
import apprise import apprise
import requests import requests
import calendar import calendar
@ -23,7 +21,7 @@ import calendar
from get_args import args from get_args import args
from logger import empty_log 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 * from init import *
import logging import logging
@ -62,15 +60,7 @@ scheduler = Scheduler()
if args.release_update: if args.release_update:
check_and_apply_update() check_and_apply_update()
if settings.proxy.type != 'None': configure_proxy_func()
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)
# Reset restart required warning on start # Reset restart required warning on start
database.execute("UPDATE system SET configured='0', updated='0'") database.execute("UPDATE system SET configured='0', updated='0'")

@ -47,14 +47,14 @@ class Scheduler:
self.aps_scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) self.aps_scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
# configure all tasks # configure all tasks
self.__sonarr_update_task()
self.__radarr_update_task()
self.__cache_cleanup_task() self.__cache_cleanup_task()
self.update_configurable_tasks() self.update_configurable_tasks()
self.aps_scheduler.start() self.aps_scheduler.start()
def update_configurable_tasks(self): def update_configurable_tasks(self):
self.__sonarr_update_task()
self.__radarr_update_task()
self.__sonarr_full_update_task() self.__sonarr_full_update_task()
self.__radarr_full_update_task() self.__radarr_full_update_task()
self.__update_bazarr_task() self.__update_bazarr_task()
@ -142,17 +142,20 @@ class Scheduler:
def __sonarr_update_task(self): def __sonarr_update_task(self):
if settings.general.getboolean('use_sonarr'): if settings.general.getboolean('use_sonarr'):
self.aps_scheduler.add_job( self.aps_scheduler.add_job(
update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15, update_series, IntervalTrigger(minutes=int(settings.sonarr.series_sync)), max_instances=1,
id='update_series', name='Update Series list from Sonarr') coalesce=True, misfire_grace_time=15, id='update_series', name='Update Series list from Sonarr',
replace_existing=True)
self.aps_scheduler.add_job( self.aps_scheduler.add_job(
sync_episodes, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, sync_episodes, IntervalTrigger(minutes=int(settings.sonarr.episodes_sync)), max_instances=1,
id='sync_episodes', name='Sync episodes with Sonarr') coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr',
replace_existing=True)
def __radarr_update_task(self): def __radarr_update_task(self):
if settings.general.getboolean('use_radarr'): if settings.general.getboolean('use_radarr'):
self.aps_scheduler.add_job( self.aps_scheduler.add_job(
update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15, update_movies, IntervalTrigger(minutes=int(settings.radarr.movies_sync)), max_instances=1,
id='update_movies', name='Update Movie list from Radarr') coalesce=True, misfire_grace_time=15, id='update_movies', name='Update Movie list from Radarr',
replace_existing=True)
def __cache_cleanup_task(self): def __cache_cleanup_task(self):
self.aps_scheduler.add_job(cache_maintenance, IntervalTrigger(hours=24), max_instances=1, coalesce=True, 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) name='Search for wanted Series Subtitles', replace_existing=True)
if settings.general.getboolean('use_radarr'): if settings.general.getboolean('use_radarr'):
self.aps_scheduler.add_job( 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', max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles_movies',
name='Search for wanted Movies Subtitles', replace_existing=True) name='Search for wanted Movies Subtitles', replace_existing=True)

@ -79,7 +79,6 @@
<option value="form">Form</option> <option value="form">Form</option>
</select> </select>
<label for="settings-auth-type">Require Username and Password to access Bazarr</label><br> <label for="settings-auth-type">Require Username and Password to access Bazarr</label><br>
{# <label class="restart">Requires restart to take effect</label>#}
</div> </div>
</div> </div>
<div id="authentication_div"> <div id="authentication_div">
@ -128,7 +127,6 @@
<option value="socks4">Socks4</option> <option value="socks4">Socks4</option>
<option value="socks5">Socks5</option> <option value="socks5">Socks5</option>
</select><br> </select><br>
<label class="restart">Requires restart to take effect</label>
</div> </div>
</div> </div>
<div id="proxy_div"> <div id="proxy_div">

@ -246,12 +246,13 @@
$('#settings-radarr-full_update_day').val('{{settings.radarr.full_update_day}}').trigger('change'); $('#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-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').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'); $('#settings-general-upgrade_frequency').val('{{settings.general.upgrade_frequency}}').trigger('change');
$('.selectpicker').selectpicker('refresh') $('.selectpicker').selectpicker('refresh')
$('#save_button').on('click', function() { $('#save_button').on('click', function() {
var formdata = new FormData(document.getElementById("settings_form")); var formdata = new FormData(document.getElementById("settings_form"));
formdata.append('update_schedule', 'true');
// Make sure all checkbox input are sent with true/false value // Make sure all checkbox input are sent with true/false value
$('input[type=checkbox]').each(function () { $('input[type=checkbox]').each(function () {

Loading…
Cancel
Save