Implement Sonarr full update scheduled task interval to be customised

pull/56/merge
morpheus65535 7 years ago
parent 755580cf18
commit 421119c75f

@ -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:

@ -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]
return [url_sonarr, url_sonarr_short, apikey_sonarr, full_update]

@ -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')
sonarr_full_update()
scheduler.start()
def execute_now(taskid):
scheduler.modify_job(taskid, jobstore=None, next_run_time=datetime.now())

@ -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()

@ -353,7 +353,7 @@
</div>
<div class="ui bottom attached tab segment" data-tab="sonarr">
<div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div>
<div class="ui dividing header">Sonarr settings</div>
<div class="ui dividing header">Connection settings</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
@ -439,6 +439,26 @@
</div>
</div>
</div>
<div class="ui dividing header">Synchronization</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Full sync frequency</label>
</div>
<div class="five wide column">
<div class='field'>
<select name="settings_sonarr_sync" id="settings_sync" class="ui fluid selection dropdown">
<option value="Manually">Manually</option>
<option value="Daily">Daily (at 4am)</option>
<option value="Weekly">Weekly (sunday at 4am)</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="subliminal">
<div class="ui container"><button class="submit ui blue right floated button" type="submit" value="Submit" form="settings_form">Save</button></div>
@ -766,11 +786,14 @@
$('#settings_languages').dropdown('set selected',{{!enabled_languages}});
$('#settings_branch').dropdown('clear');
$('#settings_branch').dropdown('set selected','{{!settings_general[5]}}');
$('#settings_sync').dropdown('clear');
$('#settings_sync').dropdown('set selected','{{!settings_sonarr[5]}}');
$('#settings_loglevel').dropdown();
$('#settings_providers').dropdown();
$('#settings_languages').dropdown();
$('#settings_branch').dropdown();
$('#settings_sync').dropdown();
</script>
<script>

Loading…
Cancel
Save