From e1c2a1d314d3a44c5e4f6532585dc4406856ce87 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 3 Jun 2018 01:26:20 +0100 Subject: [PATCH 1/3] added watched + played list type (can use, watched_weekly/monthly/yearly/all) --- helpers/misc.py | 5 +++++ media/trakt.py | 40 ++++++++++++++++++++++++++++++++++++++++ traktarr.py | 27 ++++++++++++++++++++++----- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/helpers/misc.py b/helpers/misc.py index b217584..d0ba333 100644 --- a/helpers/misc.py +++ b/helpers/misc.py @@ -77,3 +77,8 @@ def sorted_list(original_list, list_type, sort_key, reverse=True): item[list_type][sort_key] = 0 return sorted(prepared_list, key=lambda k: k[list_type][sort_key], reverse=reverse) + + +# reference: https://stackoverflow.com/a/16712886 +def substring_after(s, delim): + return s.partition(delim)[2] diff --git a/media/trakt.py b/media/trakt.py index 69fd1af..f87232a 100644 --- a/media/trakt.py +++ b/media/trakt.py @@ -343,6 +343,26 @@ class Trakt: genres=genres ) + def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None): + return self._make_items_request( + url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type), + limit=limit, + languages=languages, + object_name='shows', + type_name='played', + genres=genres + ) + + def get_most_watched_shows(self, limit=1000, languages=None, genres=None, most_type=None): + return self._make_items_request( + url='https://api.trakt.tv/shows/watched/%s' % ('weekly' if not most_type else most_type), + limit=limit, + languages=languages, + object_name='shows', + type_name='watched', + genres=genres + ) + def get_watchlist_shows(self, authenticate_user=None, limit=1000, languages=None): return self._make_items_request( url='https://api.trakt.tv/users/{authenticate_user}/watchlist/shows', @@ -407,6 +427,26 @@ class Trakt: genres=genres ) + def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None): + return self._make_items_request( + url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type), + limit=limit, + languages=languages, + object_name='movies', + type_name='played', + genres=genres + ) + + def get_most_watched_movies(self, limit=1000, languages=None, genres=None, most_type=None): + return self._make_items_request( + url='https://api.trakt.tv/movies/watched/%s' % ('weekly' if not most_type else most_type), + limit=limit, + languages=languages, + object_name='movies', + type_name='watched', + genres=genres + ) + def get_boxoffice_movies(self, limit=1000, languages=None): return self._make_items_request( url='https://api.trakt.tv/movies/boxoffice', diff --git a/traktarr.py b/traktarr.py index dd437cb..e8f1dc5 100755 --- a/traktarr.py +++ b/traktarr.py @@ -114,7 +114,8 @@ def get_objects(pvr, type, notifications): if notifications: callback_notify({'event': 'error', 'reason': 'Failure to retrieve %s shows list' % type}) exit() - log.info("Retrieved %s shows list, shows found: %d", type, len(objects_list)) + objects_type = 'movies' if type.lower() == 'radarr' else 'shows' + log.info("Retrieved %s %s list, %s found: %d", type, objects_type, objects_type, len(objects_list)) return objects_list @@ -171,8 +172,8 @@ def show(show_id, folder=None, no_search=False): @app.command(help='Add multiple shows to Sonarr.') @click.option('--list-type', '-t', - help='Trakt list to process. For example, anticipated, trending, popular, watchlist or any URL to a list', - required=True) + help='Trakt list to process. For example, anticipated, trending, popular, watched, played, watchlist ' + 'or any URL to a list', 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']), @@ -221,6 +222,14 @@ def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folde trakt_objects_list = trakt.get_trending_shows(genres=genre, languages=cfg.filters.shows.allowed_languages) elif list_type.lower() == 'popular': trakt_objects_list = trakt.get_popular_shows(genres=genre, languages=cfg.filters.shows.allowed_languages) + elif list_type.lower().startswith('played'): + most_type = misc_helper.substring_after(list_type.lower(), "_") + trakt_objects_list = trakt.get_most_played_shows(genres=genre, languages=cfg.filters.shows.allowed_languages, + most_type=most_type if most_type else None) + elif list_type.lower().startswith('watched'): + most_type = misc_helper.substring_after(list_type.lower(), "_") + trakt_objects_list = trakt.get_most_watched_shows(genres=genre, languages=cfg.filters.shows.allowed_languages, + most_type=most_type if most_type else None) elif list_type.lower() == 'watchlist': trakt_objects_list = trakt.get_watchlist_shows(authenticate_user) else: @@ -357,8 +366,8 @@ def movie(movie_id, folder=None, no_search=False): @app.command(help='Add multiple movies to Radarr.') @click.option('--list-type', '-t', - help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, watchlist ' - 'or any URL to a list', + help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, watched, played, ' + 'watchlist or any URL to a list', 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) @@ -409,6 +418,14 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, fold trakt_objects_list = trakt.get_popular_movies(genres=genre, languages=cfg.filters.movies.allowed_languages) elif list_type.lower() == 'boxoffice': trakt_objects_list = trakt.get_boxoffice_movies() + elif list_type.lower().startswith('played'): + most_type = misc_helper.substring_after(list_type.lower(), "_") + trakt_objects_list = trakt.get_most_played_movies(genres=genre, languages=cfg.filters.movies.allowed_languages, + most_type=most_type if most_type else None) + elif list_type.lower().startswith('watched'): + most_type = misc_helper.substring_after(list_type.lower(), "_") + trakt_objects_list = trakt.get_most_watched_movies(genres=genre, languages=cfg.filters.movies.allowed_languages, + most_type=most_type if most_type else None) elif list_type.lower() == 'watchlist': trakt_objects_list = trakt.get_watchlist_movies(authenticate_user) else: From 87987cd28394e9aa44d9eb8efd39463ba569e01a Mon Sep 17 00:00:00 2001 From: Filipe Santos Date: Sun, 3 Jun 2018 12:41:24 +1200 Subject: [PATCH 2/3] Fix sleep on creating tasks --- traktarr.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/traktarr.py b/traktarr.py index e8f1dc5..3f1ecdd 100755 --- a/traktarr.py +++ b/traktarr.py @@ -737,8 +737,8 @@ def run(add_delay=2.5, sort='votes', no_search=False, run_now=False, no_notifica if run_now: movie_schedule.run() - # Sleep between tasks - time.sleep(add_delay) + # Sleep between tasks + time.sleep(add_delay) if cfg.automatic.shows.interval: shows_schedule = schedule.every(cfg.automatic.shows.interval).hours.do( @@ -752,6 +752,9 @@ def run(add_delay=2.5, sort='votes', no_search=False, run_now=False, no_notifica if run_now: shows_schedule.run() + # Sleep between tasks + time.sleep(add_delay) + # Enter running schedule while True: try: From a9c09ab17bc08dc6b338ea36c8c9c9c7628099f2 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 3 Jun 2018 01:49:03 +0100 Subject: [PATCH 3/3] enable auto mode with watched + played list types --- media/trakt.py | 2 +- traktarr.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/media/trakt.py b/media/trakt.py index f87232a..133f117 100644 --- a/media/trakt.py +++ b/media/trakt.py @@ -11,7 +11,7 @@ log = logger.get_logger(__name__) class Trakt: - non_user_lists = ['anticipated', 'trending', 'popular', 'boxoffice'] + non_user_lists = ['anticipated', 'trending', 'popular', 'boxoffice', 'watched', 'played'] def __init__(self, cfg): self.cfg = cfg diff --git a/traktarr.py b/traktarr.py index e8f1dc5..cb71193 100755 --- a/traktarr.py +++ b/traktarr.py @@ -549,7 +549,8 @@ def automatic_shows(add_delay=2.5, sort='votes', no_search=False, notifications= if list_type.lower() == 'interval': continue - if list_type.lower() in Trakt.non_user_lists: + if list_type.lower() in Trakt.non_user_lists or ( + '_' in list_type and list_type.lower().partition("_")[0] in Trakt.non_user_lists): limit = value if limit <= 0: @@ -637,7 +638,8 @@ def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications if list_type.lower() == 'interval': continue - if list_type.lower() in Trakt.non_user_lists: + if list_type.lower() in Trakt.non_user_lists or ( + '_' in list_type and list_type.lower().partition("_")[0] in Trakt.non_user_lists): limit = value if limit <= 0: