diff --git a/misc/config.py b/misc/config.py index 46f6133..70d2b58 100644 --- a/misc/config.py +++ b/misc/config.py @@ -47,6 +47,30 @@ base_config = { 'blacklist_title_keywords': ['untitled', 'barbie'], 'allowed_countries': ['us', 'gb', 'ca'] } + }, + 'automatic': { + 'movies': { + 'interval': 24, + 'anticipated': 10, + 'trending': 2, + 'popular': 3 + }, + 'shows': { + 'interval': 72, + 'anticipated': 100, + 'trending': 2, + 'popular': 1 + }, + 'notifications': { + 'plex slack': { + 'type': 'slack', + 'webhook': 'http://' + }, + 'my pushover': { + 'client_id': '....', + 'client_secret': '....' + } + } } } cfg = None diff --git a/misc/log.py b/misc/log.py index 251724f..0abfbcd 100644 --- a/misc/log.py +++ b/misc/log.py @@ -18,6 +18,7 @@ class Logger: # disable bloat loggers logging.getLogger('urllib3').setLevel(logging.ERROR) + logging.getLogger('schedule').setLevel(logging.ERROR) # init console_logger self.console_handler = logging.StreamHandler(sys.stdout) diff --git a/requirements.txt b/requirements.txt index cd28427..27f2206 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ +backoff==1.4.3 +schedule==0.4.3 attrdict==2.0.0 click==6.7 -backoff==1.4.3 requests==2.18.4 diff --git a/traktarr.py b/traktarr.py index 92afffd..baa4681 100644 --- a/traktarr.py +++ b/traktarr.py @@ -2,6 +2,7 @@ import time import click +import schedule from media.radarr import Radarr from media.sonarr import Sonarr @@ -20,6 +21,7 @@ log = logger.get_logger('traktarr') # Click @click.group(help='Add new shows & movies to Sonarr/Radarr from Trakt lists.') +@click.version_option('1.0.0', prog_name='traktarr') def app(): pass @@ -143,6 +145,10 @@ def shows(list_type, add_limit=0, add_delay=2.5, no_search=False): log.info("Added %d new show(s) to Sonarr", added_shows) +############################################################ +# MOVIES +############################################################ + @app.command(help='Add new movies to Radarr.') @click.option('--list-type', '-t', type=click.Choice(['anticipated', 'trending', 'popular']), help='Trakt list to process.', required=True) @@ -243,6 +249,42 @@ def movies(list_type, add_limit=0, add_delay=2.5, no_search=False): log.info("Added %d new movie(s) to Radarr", added_movies) +############################################################ +# AUTOMATIC +############################################################ + +def automatic_shows(): + log.info("Running") + + +def automatic_movies(): + log.info("Running") + + +@app.command(help='Run in automatic mode.') +@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr / Radarr.', + show_default=True) +@click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.') +def run(add_delay=2.5, no_search=False): + # add tasks to repeat + schedule.every(1).minutes.do(automatic_movies) + schedule.every(2).minutes.do(automatic_shows) + + # run schedule + log.info("Automatic mode is now running...") + while True: + try: + schedule.run_pending() + except KeyboardInterrupt: + log.info("Scheduled tasks are no longer being processed due to Ctrl + C") + break + except Exception: + log.exception("Unhandled exception occurred while processing scheduled tasks: ") + else: + time.sleep(1) + log.info("Automatic mode is now finished!") + + ############################################################ # MAIN ############################################################