bazarr/scheduler.py

43 lines
2.6 KiB
Python
Raw Normal View History

2017-11-15 09:20:44 +08:00
from get_general_settings import *
from get_sonarr_settings import get_sonarr_settings
2017-10-23 11:00:11 +08:00
from get_series import *
from get_episodes import *
2018-05-02 18:25:42 +08:00
from get_movies import *
from list_subtitles import *
2017-10-23 11:00:11 +08:00
from get_subtitle import *
2017-11-07 13:17:14 +08:00
from check_update import *
2017-10-17 07:27:19 +08:00
2017-10-23 11:00:11 +08:00
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime
2018-03-14 07:30:29 +08:00
import pytz
from tzlocal import get_localzone
def sonarr_full_update():
full_update = get_sonarr_settings()[3]
if full_update == "Daily":
2018-05-02 18:25:42 +08:00
scheduler.add_job(update_all_episodes_and_movies, 'cron', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
elif full_update == "Weekly":
2018-05-02 18:25:42 +08:00
scheduler.add_job(update_all_episodes_and_movies, 'cron', day_of_week='sun', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
elif full_update == "Manually":
2018-05-02 18:25:42 +08:00
scheduler.add_job(update_all_episodes_and_movies, 'cron', year='2100', hour=4, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_all_episodes_and_movies', name='Update all subtitles from disk', replace_existing=True)
def execute_now(taskid):
scheduler.modify_job(taskid, jobstore=None, next_run_time=datetime.now())
if str(get_localzone()) == "local":
2018-03-14 07:30:29 +08:00
scheduler = BackgroundScheduler(timezone=pytz.timezone('UTC'))
else:
scheduler = BackgroundScheduler()
2017-10-17 07:27:19 +08:00
2017-11-15 09:20:44 +08:00
if automatic == 'True':
scheduler.add_job(check_and_apply_update, 'interval', hours=6, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github')
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(sync_episodes, 'interval', minutes=5, max_instances=1, coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr')
2018-05-02 18:25:42 +08:00
scheduler.add_job(update_movies, 'interval', minutes=1, max_instances=1, coalesce=True, misfire_grace_time=15, id='update_movies', name='Update movies list from Radarr')
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()