Added ability to customize tasks execution frequencies.

pull/543/head
Louis Vézina 5 years ago
parent 3e20252434
commit 490e4ad515

@ -45,9 +45,11 @@ defaults = {
'subfolder_custom': '',
'update_restart': 'True',
'upgrade_subs': 'True',
'upgrade_frequency': '12',
'days_to_upgrade_subs': '7',
'upgrade_manual': 'True',
'anti_captcha_provider': 'None'
'anti_captcha_provider': 'None',
'wanted_search_frequency': '3'
},
'auth': {
'type': 'None',
@ -61,6 +63,8 @@ defaults = {
'ssl': 'False',
'apikey': '',
'full_update': 'Daily',
'full_update_day': '6',
'full_update_hour': '4',
'only_monitored': 'False',
},
'radarr': {
@ -70,6 +74,8 @@ defaults = {
'ssl': 'False',
'apikey': '',
'full_update': 'Daily',
'full_update_day': '6',
'full_update_hour': '5',
'only_monitored': 'False',
},
'proxy': {

@ -19,6 +19,7 @@ import platform
import apprise
from peewee import fn, JOIN
import operator
from calendar import day_name
from get_args import args
from init import *
@ -1505,6 +1506,7 @@ def save_settings():
settings_general_single_language = 'False'
else:
settings_general_single_language = 'True'
settings_general_wanted_search_frequency = request.forms.get('settings_general_wanted_search_frequency')
settings_general_scenename = request.forms.get('settings_general_scenename')
if settings_general_scenename is None:
settings_general_scenename = 'False'
@ -1561,6 +1563,7 @@ def save_settings():
settings_upgrade_subs = 'False'
else:
settings_upgrade_subs = 'True'
settings_upgrade_subs_frequency = request.forms.get('settings_upgrade_subs_frequency')
settings_days_to_upgrade_subs = request.forms.get('settings_days_to_upgrade_subs')
settings_upgrade_manual = request.forms.get('settings_upgrade_manual')
if settings_upgrade_manual is None:
@ -1592,6 +1595,7 @@ def save_settings():
settings.analytics.enabled = text_type(settings_analytics_enabled)
settings.general.single_language = text_type(settings_general_single_language)
settings.general.minimum_score = text_type(settings_general_minimum_score)
settings.general.wanted_search_frequency = text_type(settings_general_wanted_search_frequency)
settings.general.use_scenename = text_type(settings_general_scenename)
settings.general.use_postprocessing = text_type(settings_general_use_postprocessing)
settings.general.postprocessing_cmd = text_type(settings_general_postprocessing_cmd)
@ -1605,6 +1609,7 @@ def save_settings():
else:
settings.general.subfolder_custom = text_type(settings_subfolder_custom)
settings.general.upgrade_subs = text_type(settings_upgrade_subs)
settings.general.upgrade_frequency = text_type(settings_upgrade_subs_frequency)
settings.general.days_to_upgrade_subs = text_type(settings_days_to_upgrade_subs)
settings.general.upgrade_manual = text_type(settings_upgrade_manual)
settings.general.anti_captcha_provider = text_type(settings_anti_captcha_provider)
@ -1709,7 +1714,9 @@ def save_settings():
else:
settings_sonarr_only_monitored = 'True'
settings_sonarr_sync = request.forms.get('settings_sonarr_sync')
settings_sonarr_sync_day = request.forms.get('settings_sonarr_sync_day')
settings_sonarr_sync_hour = request.forms.get('settings_sonarr_sync_hour')
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)
@ -1717,7 +1724,9 @@ def save_settings():
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.sonarr.full_update_day = text_type(settings_sonarr_sync_day)
settings.sonarr.full_update_hour = text_type(settings_sonarr_sync_hour)
settings_radarr_ip = request.forms.get('settings_radarr_ip')
settings_radarr_port = request.forms.get('settings_radarr_port')
settings_radarr_baseurl = request.forms.get('settings_radarr_baseurl')
@ -1733,7 +1742,9 @@ def save_settings():
else:
settings_radarr_only_monitored = 'True'
settings_radarr_sync = request.forms.get('settings_radarr_sync')
settings_radarr_sync_day = request.forms.get('settings_radarr_sync_day')
settings_radarr_sync_hour = request.forms.get('settings_radarr_sync_hour')
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)
@ -1741,7 +1752,9 @@ def save_settings():
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.radarr.full_update_day = text_type(settings_radarr_sync_day)
settings.radarr.full_update_hour = text_type(settings_radarr_sync_hour)
settings_subliminal_providers = request.forms.getall('settings_subliminal_providers')
settings.general.enabled_providers = u'' if not settings_subliminal_providers else ','.join(
settings_subliminal_providers)
@ -1869,6 +1882,8 @@ def save_settings():
schedule_update_job()
sonarr_full_update()
radarr_full_update()
schedule_wanted_search()
schedule_upgrade_subs()
logging.info('BAZARR Settings saved succesfully.')
@ -1894,7 +1909,7 @@ def check_update():
@custom_auth_basic(check_credentials)
def system():
authorize()
def get_time_from_interval(td_object):
seconds = int(td_object.total_seconds())
periods = [
@ -1914,54 +1929,26 @@ def system():
strings.append("%s %s%s" % (period_value, period_name, has_s))
return ", ".join(strings)
def get_time_from_cron(cron):
text = ""
sun = str(cron[4])
year = str(cron[0])
if year == "2100":
return "Never"
day = str(cron[4])
hour = str(cron[5])
minute = str(cron[6])
second = str(cron[7])
if sun != "*":
text = "Sunday at "
if hour != "0" and hour != "*":
text = text + hour
if hour == "0" or hour == "1":
text = text + " hour"
elif sun != "*" or hour == "4" or hour == "5":
text = text + "am"
else:
text = text + " hours"
if minute != "*" and second != "0":
text = text + ", "
elif minute == "*" and second != "0":
text = text + " and "
elif minute != "0" and minute != "*" and second == "0":
text = text + " and "
if minute != "0" and minute != "*":
text = text + minute
if minute == "0" or minute == "1":
text = text + " minute"
else:
text = text + " minutes"
if second != "0" and second != "*":
text = text + " and "
if second != "0" and second != "*":
text = text + second
if second == "0" or second == "1":
text = text + " second"
else:
text = text + " seconds"
if text != "" and sun == "*":
text = "everyday at " + text
elif text == "":
text = "Never"
text = ""
if day == "*":
text = "everyday"
else:
text = "every " + day_name[int(day)]
if hour != "*":
text += " at " + hour + ":00"
return text
task_list = []
for job in scheduler.get_jobs():
if isinstance(job.trigger, CronTrigger):

@ -25,11 +25,11 @@ def sonarr_full_update():
if settings.general.getboolean('use_sonarr'):
full_update = settings.sonarr.full_update
if full_update == "Daily":
scheduler.add_job(update_all_episodes, CronTrigger(hour=4), max_instances=1, coalesce=True,
scheduler.add_job(update_all_episodes, CronTrigger(hour=settings.sonarr.full_update_hour), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_episodes',
name='Update all episodes subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
scheduler.add_job(update_all_episodes, CronTrigger(day_of_week='sun', hour=4), max_instances=1,
scheduler.add_job(update_all_episodes, CronTrigger(day_of_week=settings.sonarr.full_update_day, hour=settings.sonarr.full_update_hour), max_instances=1,
coalesce=True,
misfire_grace_time=15, id='update_all_episodes',
name='Update all episodes subtitles from disk', replace_existing=True)
@ -43,17 +43,17 @@ def radarr_full_update():
if settings.general.getboolean('use_radarr'):
full_update = settings.radarr.full_update
if full_update == "Daily":
scheduler.add_job(update_all_movies, CronTrigger(hour=5), max_instances=1, coalesce=True,
scheduler.add_job(update_all_movies, CronTrigger(hour=settings.radarr.full_update_hour), max_instances=1, coalesce=True,
misfire_grace_time=15,
id='update_all_movies', name='Update all movies subtitles from disk',
replace_existing=True)
elif full_update == "Weekly":
scheduler.add_job(update_all_movies, CronTrigger(day_of_week='sun', hour=5), max_instances=1, coalesce=True,
scheduler.add_job(update_all_movies, CronTrigger(day_of_week=settings.radarr.full_update_day, hour=settings.radarr.full_update_hour), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_movies',
name='Update all movies subtitles from disk',
replace_existing=True)
elif full_update == "Manually":
scheduler.add_job(update_all_movies, CronTrigger(year='2100'), hour=5, max_instances=1, coalesce=True,
scheduler.add_job(update_all_movies, CronTrigger(year='2100'), max_instances=1, coalesce=True,
misfire_grace_time=15, id='update_all_movies',
name='Update all movies subtitles from disk',
replace_existing=True)
@ -113,14 +113,20 @@ if settings.general.getboolean('use_radarr'):
scheduler.add_job(update_movies, IntervalTrigger(minutes=5), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_movies', name='Update movies list from Radarr')
if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use_radarr'):
scheduler.add_job(wanted_search_missing_subtitles, IntervalTrigger(hours=3), max_instances=1, coalesce=True,
misfire_grace_time=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
def schedule_wanted_search():
if settings.general.getboolean('use_sonarr') or settings.general.getboolean('use_radarr'):
scheduler.add_job(wanted_search_missing_subtitles,
IntervalTrigger(hours=int(settings.general.wanted_search_frequency)), max_instances=1,
coalesce=True, misfire_grace_time=15, id='wanted_search_missing_subtitles',
name='Search for wanted subtitles', replace_existing=True)
if settings.general.getboolean('upgrade_subs') and (settings.general.getboolean('use_sonarr') or
settings.general.getboolean('use_radarr')):
scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=12), max_instances=1, coalesce=True,
misfire_grace_time=15, id='upgrade_subtitles', name='Upgrade previously downloaded subtitles')
def schedule_upgrade_subs():
if settings.general.getboolean('upgrade_subs') and (settings.general.getboolean('use_sonarr') or
settings.general.getboolean('use_radarr')):
scheduler.add_job(upgrade_subtitles, IntervalTrigger(hours=int(settings.general.upgrade_frequency)),
max_instances=1, coalesce=True, misfire_grace_time=15, id='upgrade_subtitles',
name='Upgrade previously downloaded subtitles', replace_existing=True)
scheduler.add_job(cache_maintenance, IntervalTrigger(hours=24), max_instances=1, coalesce=True,
misfire_grace_time=15, id='cache_cleanup', name='Cache maintenance')
@ -128,6 +134,8 @@ scheduler.add_job(cache_maintenance, IntervalTrigger(hours=24), max_instances=1,
schedule_update_job()
sonarr_full_update()
radarr_full_update()
schedule_wanted_search()
schedule_upgrade_subs()
scheduler.start()

@ -126,14 +126,33 @@
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Full sync frequency</label>
<label>Full filesystem scan</label>
</div>
<div class="five wide column">
<div class="three wide column">
<div class='field'>
<select name="settings_radarr_sync" id="settings_radarr_sync" class="ui fluid selection dropdown">
<option value="Manually">Manually</option>
<option value="Daily">Daily (at 5am)</option>
<option value="Weekly">Weekly (sunday at 5am)</option>
<option value="Daily">Daily</option>
<option value="Weekly">Weekly</option>
</select>
</div>
</div>
<div id="settings_radarr_sync_day_div" class="three wide column">
<div class='field'>
<select name="settings_radarr_sync_day" id="settings_radarr_sync_day" class="ui fluid selection dropdown">
% import calendar
% for idx, i in enumerate(calendar.day_name):
<option value="{{idx}}">{{i}}</option>
%end
</select>
</div>
</div>
<div id="settings_radarr_sync_hour_div" class="two wide column">
<div class='field'>
<select name="settings_radarr_sync_hour" id="settings_radarr_sync_hour" class="ui fluid selection dropdown">
% for i in range(24):
<option value="{{i}}">{{i}}:00</option>
%end
</select>
</div>
</div>
@ -154,8 +173,28 @@
$("#settings_only_monitored_radarr").checkbox('uncheck');
}
$('#settings_radarr_sync').dropdown('setting', 'onChange', function(){
if ($('#settings_radarr_sync').val() === "Manually") {
$('#settings_radarr_sync_day_div').hide();
$('#settings_radarr_sync_hour_div').hide();
} else if ($('#settings_radarr_sync').val() === "Daily") {
$('#settings_radarr_sync_day_div').hide();
$('#settings_radarr_sync_hour_div').show();
} else if ($('#settings_radarr_sync').val() === "Weekly") {
$('#settings_radarr_sync_day_div').show();
$('#settings_radarr_sync_hour_div').show();
}
});
$('#settings_radarr_sync').dropdown('clear');
$('#settings_radarr_sync').dropdown('set selected','{{!settings.radarr.full_update}}');
$('#settings_radarr_sync').dropdown('refresh');
$('#settings_radarr_sync_day').dropdown('clear');
$('#settings_radarr_sync_day').dropdown('set selected','{{!settings.radarr.full_update_day}}');
$('#settings_radarr_sync_day').dropdown('refresh');
$('#settings_radarr_sync_hour').dropdown('clear');
$('#settings_radarr_sync_hour').dropdown('set selected','{{!settings.radarr.full_update_hour}}');
$('#settings_radarr_sync_hour').dropdown('refresh');
$('#radarr_validate').on('click', function() {
if ($('#radarr_ssl_div').checkbox('is checked')) {

@ -126,14 +126,33 @@
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Full sync frequency</label>
<label>Full filesystem scan</label>
</div>
<div class="five wide column">
<div class="three wide column">
<div class='field'>
<select name="settings_sonarr_sync" id="settings_sonarr_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>
<option value="Daily">Daily</option>
<option value="Weekly">Weekly</option>
</select>
</div>
</div>
<div id="settings_sonarr_sync_day_div" class="three wide column">
<div class='field'>
<select name="settings_sonarr_sync_day" id="settings_sonarr_sync_day" class="ui fluid selection dropdown">
% import calendar
% for idx, i in enumerate(calendar.day_name):
<option value="{{idx}}">{{i}}</option>
%end
</select>
</div>
</div>
<div id="settings_sonarr_sync_hour_div" class="two wide column">
<div class='field'>
<select name="settings_sonarr_sync_hour" id="settings_sonarr_sync_hour" class="ui fluid selection dropdown">
% for i in range(24):
<option value="{{i}}">{{i}}:00</option>
%end
</select>
</div>
</div>
@ -154,8 +173,28 @@
$("#settings_only_monitored_sonarr").checkbox('uncheck');
}
$('#settings_sonarr_sync').dropdown('setting', 'onChange', function(){
if ($('#settings_sonarr_sync').val() === "Manually") {
$('#settings_sonarr_sync_day_div').hide();
$('#settings_sonarr_sync_hour_div').hide();
} else if ($('#settings_sonarr_sync').val() === "Daily") {
$('#settings_sonarr_sync_day_div').hide();
$('#settings_sonarr_sync_hour_div').show();
} else if ($('#settings_sonarr_sync').val() === "Weekly") {
$('#settings_sonarr_sync_day_div').show();
$('#settings_sonarr_sync_hour_div').show();
}
});
$('#settings_sonarr_sync').dropdown('clear');
$('#settings_sonarr_sync').dropdown('set selected','{{!settings.sonarr.full_update}}');
$('#settings_sonarr_sync').dropdown('refresh');
$('#settings_sonarr_sync_day').dropdown('clear');
$('#settings_sonarr_sync_day').dropdown('set selected','{{!settings.sonarr.full_update_day}}');
$('#settings_sonarr_sync_day').dropdown('refresh');
$('#settings_sonarr_sync_hour').dropdown('clear');
$('#settings_sonarr_sync_hour').dropdown('set selected','{{!settings.sonarr.full_update_hour}}');
$('#settings_sonarr_sync_hour').dropdown('refresh');
$('#sonarr_validate').on('click', function() {
if ($('#sonarr_ssl_div').checkbox('is checked')) {

@ -1,6 +1,22 @@
<div class="ui dividing header">Subtitles options</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="two wide column"></div>
<div class="right aligned four wide column">
<label>Search for missing subtitles frequency (in hours)</label>
</div>
<div class="five wide column">
<div class='field'>
<select name="settings_general_wanted_search_frequency" id="settings_general_wanted_search_frequency" class="ui fluid selection dropdown">
% for i in [1,3,6,12,24]:
<option value="{{i}}">{{i}}</option>
%end
</select>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Use scene name when available</label>
@ -117,13 +133,29 @@
<div class="collapsed center aligned column">
<div class="ui basic icon"
data-tooltip='Schedule a task that run every 12 hours to upgrade subtitles previously downloaded by Bazarr.'
data-tooltip='Schedule a task to upgrade subtitles previously downloaded by Bazarr.'
data-inverted="">
<i class="help circle large icon"></i>
</div>
</div>
</div>
<div class="middle aligned row upgrade_subs">
<div class="two wide column"></div>
<div class="right aligned four wide column">
<label>Upgrade frequency (in hours)</label>
</div>
<div class="five wide column">
<div class='field'>
<select name="settings_upgrade_subs_frequency" id="settings_upgrade_subs_frequency" class="ui fluid selection dropdown">
% for i in [1,3,6,12,24]:
<option value="{{i}}">{{i}}</option>
%end
</select>
</div>
</div>
</div>
<div class="middle aligned row upgrade_subs">
<div class="two wide column"></div>
<div class="right aligned four wide column">
@ -540,6 +572,10 @@
</div>
<script>
$('#settings_general_wanted_search_frequency').dropdown('clear');
$('#settings_general_wanted_search_frequency').dropdown('set selected','{{!settings.general.wanted_search_frequency}}');
$('#settings_general_wanted_search_frequency').dropdown('refresh');
if ($('#settings_single_language').data("single-language") === "True") {
$("#settings_single_language").checkbox('check');
} else {
@ -558,6 +594,10 @@
$("#settings_upgrade_subs").checkbox('uncheck');
}
$('#settings_upgrade_subs_frequency').dropdown('clear');
$('#settings_upgrade_subs_frequency').dropdown('set selected','{{!settings.general.upgrade_frequency}}');
$('#settings_upgrade_subs_frequency').dropdown('refresh');
if ($('#settings_upgrade_manual').data("upgrade-manual") === "True") {
$("#settings_upgrade_manual").checkbox('check');
} else {

Loading…
Cancel
Save