diff --git a/bazarr.py b/bazarr.py index bb2f35987..2ebd25e2d 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.4.0' +bazarr_version = '0.4.1' import gc gc.enable() @@ -427,7 +427,8 @@ def save_settings(): else: settings_sonarr_ssl = 'True' settings_sonarr_apikey = request.forms.get('settings_sonarr_apikey') - c.execute("UPDATE table_settings_sonarr SET ip = ?, port = ?, base_url = ?, ssl = ?, apikey = ?", (settings_sonarr_ip, settings_sonarr_port, settings_sonarr_baseurl, settings_sonarr_ssl, settings_sonarr_apikey)) + settings_sonarr_sync = request.forms.get('settings_sonarr_sync') + c.execute("UPDATE table_settings_sonarr SET ip = ?, port = ?, base_url = ?, ssl = ?, apikey = ?, full_update = ?", (settings_sonarr_ip, settings_sonarr_port, settings_sonarr_baseurl, settings_sonarr_ssl, settings_sonarr_apikey, settings_sonarr_sync)) settings_subliminal_providers = request.forms.getall('settings_subliminal_providers') c.execute("UPDATE table_settings_providers SET enabled = 0") @@ -599,6 +600,9 @@ def save_settings(): logging.info('Settings saved succesfully.') + # reschedule full update task according to settings + sonarr_full_update() + redirect(ref) @route(base_url + 'check_update') @@ -692,10 +696,15 @@ def system(): task_list = [] for job in scheduler.get_jobs(): + if job.next_run_time is not None: + next_run = pretty.date(job.next_run_time.replace(tzinfo=None)) + else: + next_run = "Never" + if job.trigger.__str__().startswith('interval'): - task_list.append([job.name, get_time_from_interval(str(job.trigger)), pretty.date(job.next_run_time.replace(tzinfo=None)), job.id]) + task_list.append([job.name, get_time_from_interval(str(job.trigger)), next_run, job.id]) elif job.trigger.__str__().startswith('cron'): - task_list.append([job.name, get_time_from_cron(job.trigger.fields), pretty.date(job.next_run_time.replace(tzinfo=None)), job.id]) + task_list.append([job.name, get_time_from_cron(job.trigger.fields), next_run, job.id]) i = 0 with open(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log')) as f: diff --git a/get_sonarr_settings.py b/get_sonarr_settings.py index 08e6064e5..8824ec957 100644 --- a/get_sonarr_settings.py +++ b/get_sonarr_settings.py @@ -20,6 +20,7 @@ def get_sonarr_settings(): baseurl_sonarr = config_sonarr[2] ssl_sonarr = config_sonarr[3] apikey_sonarr = config_sonarr[4] + full_update = config_sonarr[5] if ssl_sonarr == 1: protocol_sonarr = "https" @@ -36,4 +37,4 @@ def get_sonarr_settings(): url_sonarr = protocol_sonarr + "://" + ip_sonarr + ":" + port_sonarr + baseurl_sonarr url_sonarr_short = protocol_sonarr + "://" + ip_sonarr + ":" + port_sonarr - return [url_sonarr, url_sonarr_short, apikey_sonarr] \ No newline at end of file + return [url_sonarr, url_sonarr_short, apikey_sonarr, full_update] \ No newline at end of file diff --git a/scheduler.py b/scheduler.py index b4c8ba614..82ea1dcbd 100644 --- a/scheduler.py +++ b/scheduler.py @@ -1,4 +1,5 @@ from get_general_settings import * +from get_sonarr_settings import get_sonarr_settings from get_series import * from get_episodes import * from list_subtitles import * @@ -10,6 +11,20 @@ from datetime import datetime import pytz from tzlocal import get_localzone + +def sonarr_full_update(): + full_update = get_sonarr_settings()[3] + if full_update == "Daily": + scheduler.add_job(update_all_episodes, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes from Sonarr', replace_existing=True) + elif full_update == "Weekly": + scheduler.add_job(update_all_episodes, 'cron', day_of_week='sun', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes from Sonarr', replace_existing=True) + elif full_update == "Manually": + scheduler.add_job(update_all_episodes, 'cron', year='2100', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes from Sonarr', replace_existing=True) + +def execute_now(taskid): + scheduler.modify_job(taskid, jobstore=None, next_run_time=datetime.now()) + + if str(get_localzone()) == "local": scheduler = BackgroundScheduler(timezone=pytz.timezone('UTC')) else: @@ -20,11 +35,7 @@ if automatic == 'True': else: scheduler.add_job(check_and_apply_update, 'cron', year='2100', hour=4, id='update_bazarr', name='Update bazarr from source on Github') scheduler.add_job(update_series, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr') -scheduler.add_job(add_new_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='add_new_episodes', name='Add new episodes from Sonarr') -scheduler.add_job(update_all_episodes, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes', name='Update all episodes from Sonarr') -scheduler.add_job(list_missing_subtitles, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='list_missing_subtitles', name='Process missing subtitles for all series') +scheduler.add_job(sync_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr') scheduler.add_job(wanted_search_missing_subtitles, 'interval', hours=3, max_instances=1, coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles') -scheduler.start() - -def execute_now(taskid): - scheduler.modify_job(taskid, jobstore=None, next_run_time=datetime.now()) +sonarr_full_update() +scheduler.start() \ No newline at end of file diff --git a/update_db.py b/update_db.py index 6f42a1613..389880bc6 100644 --- a/update_db.py +++ b/update_db.py @@ -75,6 +75,13 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) except: pass + try: + c.execute('alter table table_settings_sonarr add column "full_update" "text"') + except: + pass + else: + c.execute('UPDATE table_settings_sonarr SET full_update="Daily"') + # Commit change to db db.commit() diff --git a/views/settings.tpl b/views/settings.tpl index 1495e435d..537b87a38 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -353,7 +353,7 @@