2018-08-16 10:01:49 +08:00
from get_argv import no_update
2018-08-24 03:58:15 +08:00
from get_settings import get_general_settings , automatic , get_radarr_settings , get_sonarr_settings
2018-08-16 04:51:46 +08:00
from get_series import update_series
from get_episodes import update_all_episodes , update_all_movies , sync_episodes
from get_movies import update_movies
from list_subtitles import store_subtitles
2018-09-17 08:27:00 +08:00
from get_subtitle import wanted_search_missing_subtitles
2018-09-18 01:56:00 +08:00
if no_update is False :
from check_update import check_and_apply_update
2017-10-17 07:27:19 +08:00
2017-10-23 11:00:11 +08:00
from apscheduler . schedulers . background import BackgroundScheduler
2018-09-17 08:27:00 +08:00
from apscheduler . triggers . interval import IntervalTrigger
from apscheduler . triggers . cron import CronTrigger
2017-11-16 10:07:21 +08:00
from datetime import datetime
2018-03-14 07:30:29 +08:00
import pytz
2018-03-10 12:17:51 +08:00
from tzlocal import get_localzone
2018-05-27 11:01:57 +08:00
integration = get_general_settings ( )
2018-04-09 11:45:53 +08:00
def sonarr_full_update ( ) :
2018-09-25 19:58:23 +08:00
if integration [ 12 ] is True :
full_update = get_sonarr_settings ( ) [ 5 ]
if full_update == " Daily " :
scheduler . add_job ( update_all_episodes , CronTrigger ( hour = 4 ) , 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 , coalesce = True ,
misfire_grace_time = 15 , id = ' update_all_episodes ' ,
name = ' Update all episodes subtitles from disk ' , replace_existing = True )
elif full_update == " Manually " :
scheduler . add_job ( update_all_episodes , CronTrigger ( year = ' 2100 ' ) , hour = 4 , max_instances = 1 , coalesce = True ,
misfire_grace_time = 15 , id = ' update_all_episodes ' ,
name = ' Update all episodes subtitles from disk ' , replace_existing = True )
2018-05-27 11:01:57 +08:00
def radarr_full_update ( ) :
2018-09-25 19:58:23 +08:00
if integration [ 13 ] is True :
full_update = get_radarr_settings ( ) [ 5 ]
if full_update == " Daily " :
scheduler . add_job ( update_all_movies , CronTrigger ( hour = 5 ) , 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 ,
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 ,
misfire_grace_time = 15 , id = ' update_all_movies ' , name = ' Update all movies subtitles from disk ' ,
replace_existing = True )
2018-04-09 11:45:53 +08:00
def execute_now ( taskid ) :
2018-05-27 11:01:57 +08:00
scheduler . modify_job ( taskid , next_run_time = datetime . now ( ) )
2018-04-09 11:45:53 +08:00
2018-03-10 12:17:51 +08:00
if str ( get_localzone ( ) ) == " local " :
2018-03-14 07:30:29 +08:00
scheduler = BackgroundScheduler ( timezone = pytz . timezone ( ' UTC ' ) )
2018-03-10 12:17:51 +08:00
else :
scheduler = BackgroundScheduler ( )
2017-10-17 07:27:19 +08:00
2018-08-16 10:01:49 +08:00
if no_update is False :
2018-08-24 03:58:15 +08:00
if automatic is True :
2018-09-17 08:27:00 +08:00
scheduler . add_job ( check_and_apply_update , IntervalTrigger ( hours = 6 ) , max_instances = 1 , coalesce = True , misfire_grace_time = 15 , id = ' update_bazarr ' , name = ' Update bazarr from source on Github ' )
2018-08-16 10:01:49 +08:00
else :
2018-09-17 08:27:00 +08:00
scheduler . add_job ( check_and_apply_update , CronTrigger ( year = ' 2100 ' ) , hour = 4 , id = ' update_bazarr ' , name = ' Update bazarr from source on Github ' )
2018-05-27 11:01:57 +08:00
2018-08-24 03:58:15 +08:00
if integration [ 12 ] is True :
2018-09-17 08:27:00 +08:00
scheduler . add_job ( update_series , IntervalTrigger ( 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 , IntervalTrigger ( minutes = 5 ) , max_instances = 1 , coalesce = True , misfire_grace_time = 15 , id = ' sync_episodes ' , name = ' Sync episodes with Sonarr ' )
2018-05-27 11:01:57 +08:00
2018-08-24 03:58:15 +08:00
if integration [ 13 ] is True :
2018-09-17 08:27:00 +08:00
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 ' )
2018-05-27 11:01:57 +08:00
2018-08-24 03:58:15 +08:00
if integration [ 12 ] is True or integration [ 13 ] is True :
2018-09-17 08:27:00 +08:00
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 ' )
2018-05-27 11:01:57 +08:00
2018-05-30 08:38:52 +08:00
sonarr_full_update ( )
radarr_full_update ( )
2018-09-18 01:56:00 +08:00
scheduler . start ( )