From def7818ed5392bb1e46d34d0019cdd9810e0e664 Mon Sep 17 00:00:00 2001 From: Mitchell Klijs Date: Wed, 30 May 2018 21:44:06 +0200 Subject: [PATCH 1/4] Add priorty to pushover notifications --- README.md | 8 ++++++-- notifications/pushover.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1c58e2e..1c6c8d0 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,8 @@ You can repeat this process for as many users as you like. "pushover": { "service": "pushover", "app_token": "", - "user_token": "" + "user_token": "", + "priority": 0 }, "slack": { "service": "slack", @@ -564,7 +565,8 @@ Currently, only Pushover and Slack are supported. More will be added later. "pushover": { "service": "pushover", "app_token": "", - "user_token": "" + "user_token": "", + "priority": 0 }, "slack": { "service": "slack", @@ -582,6 +584,8 @@ Currently, only Pushover and Slack are supported. More will be added later. `app_token` and `user_token` - retrieve from Pushover.net. +You can specify a priority for the messages send via Pushover using the priority key. It can be any Pushover priority value (https://pushover.net/api#priority). + _Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be exactly `"pushover"`._ diff --git a/notifications/pushover.py b/notifications/pushover.py index 9374dc1..35f8ddd 100644 --- a/notifications/pushover.py +++ b/notifications/pushover.py @@ -8,9 +8,10 @@ log = logger.get_logger(__name__) class Pushover: NAME = "Pushover" - def __init__(self, app_token, user_token): + def __init__(self, app_token, user_token, priority=0): self.app_token = app_token self.user_token = user_token + self.priority = priority log.debug("Initialized Pushover notification agent") def send(self, **kwargs): @@ -23,7 +24,8 @@ class Pushover: payload = { 'token': self.app_token, 'user': self.user_token, - 'message': kwargs['message'] + 'message': kwargs['message'], + 'priority': self.priority, } resp = requests.post('https://api.pushover.net/1/messages.json', data=payload, timeout=30) return True if resp.status_code == 200 else False From cede6f812de3f5dfdad9f385aab3af003af91e16 Mon Sep 17 00:00:00 2001 From: desimaniac Date: Wed, 30 May 2018 14:49:15 -0500 Subject: [PATCH 2/4] Readme: Priority tweak. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c6c8d0..269ba27 100644 --- a/README.md +++ b/README.md @@ -584,7 +584,7 @@ Currently, only Pushover and Slack are supported. More will be added later. `app_token` and `user_token` - retrieve from Pushover.net. -You can specify a priority for the messages send via Pushover using the priority key. It can be any Pushover priority value (https://pushover.net/api#priority). +You can specify a priority for the messages send via Pushover using the `priority` key. It can be any Pushover priority value (https://pushover.net/api#priority). _Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be exactly `"pushover"`._ From 052d19bff04923b8b3932220179a420cd8c1f789 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 31 May 2018 22:10:06 +0100 Subject: [PATCH 3/4] added ability to sort list by votes/rating/release date (first aired for tv) --- helpers/misc.py | 14 ++++++++++++++ traktarr.py | 34 ++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/helpers/misc.py b/helpers/misc.py index 0c6572b..b217584 100644 --- a/helpers/misc.py +++ b/helpers/misc.py @@ -1,3 +1,5 @@ +from copy import copy + from misc.log import logger log = logger.get_logger(__name__) @@ -63,3 +65,15 @@ def allowed_genres(genre, object_type, trakt_object): allowed_object = True break return allowed_object + + +def sorted_list(original_list, list_type, sort_key, reverse=True): + prepared_list = copy(original_list) + for item in prepared_list: + if not item[list_type][sort_key]: + if sort_key == 'released' or sort_key == 'first_aired': + item[list_type][sort_key] = "" + else: + item[list_type][sort_key] = 0 + + return sorted(prepared_list, key=lambda k: k[list_type][sort_key], reverse=reverse) diff --git a/traktarr.py b/traktarr.py index 4718e74..88678c8 100755 --- a/traktarr.py +++ b/traktarr.py @@ -175,13 +175,15 @@ def show(show_id, folder=None, no_search=False): required=True) @click.option('--add-limit', '-l', default=0, help='Limit number of shows added to Sonarr.', show_default=True) @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr.', show_default=True) +@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']), + help='Sort list to process.') @click.option('--genre', '-g', default=None, help='Only add shows from this genre to Sonarr.') @click.option('--folder', '-f', default=None, help='Add shows with this root folder to Sonarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding shows to Sonarr.') @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config') -def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, +def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, notifications=False, authenticate_user=None): from media.sonarr import Sonarr from media.trakt import Trakt @@ -246,9 +248,16 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea log.info("Removed existing Sonarr shows from Trakt shows list, shows left to process: %d", len(processed_series_list)) - # sort filtered series list by highest votes - sorted_series_list = sorted(processed_series_list, key=lambda k: k['show']['votes'], reverse=True) - log.info("Sorted shows list to process by highest votes") + # sort filtered series list + if sort == 'release': + sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'first_aired') + log.info("Sorted shows list to process by release date") + elif sort == 'rating': + sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'rating') + log.info("Sorted shows list to process by highest rating") + else: + sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'votes') + log.info("Sorted shows list to process by highest votes") # loop series_list log.info("Processing list now...") @@ -352,13 +361,15 @@ def movie(movie_id, folder=None, no_search=False): required=True) @click.option('--add-limit', '-l', default=0, help='Limit number of movies added to Radarr.', show_default=True) @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Radarr.', show_default=True) +@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']), + help='Sort list to process.') @click.option('--genre', '-g', default=None, help='Only add movies from this genre to Radarr.') @click.option('--folder', '-f', default=None, help='Add movies with this root folder to Radarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding movies to Radarr.') @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config.') -def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, +def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, notifications=False, authenticate_user=None): from media.radarr import Radarr from media.trakt import Trakt @@ -424,9 +435,16 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se log.info("Removed existing Radarr movies from Trakt movies list, movies left to process: %d", len(processed_movies_list)) - # sort filtered movie list by highest votes - sorted_movies_list = sorted(processed_movies_list, key=lambda k: k['movie']['votes'], reverse=True) - log.info("Sorted movie list to process by highest votes") + # sort filtered movie list + if sort == 'release': + sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'released') + log.info("Sorted movies list to process by release date") + elif sort == 'rating': + sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'rating') + log.info("Sorted movies list to process by highest rating") + else: + sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'votes') + log.info("Sorted movies list to process by highest votes") # loop movies log.info("Processing list now...") From c4ecf56faad1e2af9091b8ac6bb4aae237a2b5d2 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 1 Jun 2018 21:25:40 +0100 Subject: [PATCH 4/4] add --sort/-s to run mode. --- traktarr.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/traktarr.py b/traktarr.py index 88678c8..00fc4b1 100755 --- a/traktarr.py +++ b/traktarr.py @@ -183,8 +183,8 @@ def show(show_id, folder=None, no_search=False): @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config') -def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, notifications=False, - authenticate_user=None): +def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, + notifications=False, authenticate_user=None): from media.sonarr import Sonarr from media.trakt import Trakt from helpers import misc as misc_helper @@ -369,8 +369,8 @@ def movie(movie_id, folder=None, no_search=False): @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config.') -def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, notifications=False, - authenticate_user=None): +def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, + notifications=False, authenticate_user=None): from media.radarr import Radarr from media.trakt import Trakt from helpers import misc as misc_helper @@ -517,7 +517,7 @@ def callback_notify(data): return -def automatic_shows(add_delay=2.5, no_search=False, notifications=False): +def automatic_shows(add_delay=2.5, sort='votes', no_search=False, notifications=False): from media.trakt import Trakt total_shows_added = 0 @@ -541,7 +541,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): @@ -553,7 +553,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user) elif list_type.lower() == 'lists': for list, v in value.items(): @@ -566,7 +566,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user) if added_shows is None: @@ -588,7 +588,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): return -def automatic_movies(add_delay=2.5, no_search=False, notifications=False): +def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications=False): from media.trakt import Trakt total_movies_added = 0 @@ -612,7 +612,7 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): @@ -624,7 +624,7 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user) elif list_type.lower() == 'lists': for list, v in value.items(): @@ -637,7 +637,7 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run shows added_movies = movies.callback(list_type=list, add_limit=limit, - add_delay=add_delay, no_search=no_search, + add_delay=add_delay, sort=sort, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user) if added_movies is None: @@ -662,10 +662,12 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): @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('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']), + help='Sort list to process.') @click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.') @click.option('--run-now', is_flag=True, help="Do a first run immediately without waiting.") @click.option('--no-notifications', is_flag=True, help="Disable notifications.") -def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): +def run(add_delay=2.5, sort='votes', no_search=False, run_now=False, no_notifications=False): log.info("Automatic mode is now running...") # Add tasks to schedule and do first run if enabled @@ -673,6 +675,7 @@ def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): movie_schedule = schedule.every(cfg.automatic.movies.interval).hours.do( automatic_movies, add_delay, + sort, no_search, not no_notifications ) @@ -686,6 +689,7 @@ def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): shows_schedule = schedule.every(cfg.automatic.shows.interval).hours.do( automatic_shows, add_delay, + sort, no_search, not no_notifications )