Merge pull request #35 from l3uddz/feat/watched-played

Feat/watched played
pull/54/head
James 7 years ago committed by desimaniac
commit 9fb2637665

@ -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]

@ -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
@ -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',

@ -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:
@ -532,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:
@ -620,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:
@ -735,6 +754,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:

Loading…
Cancel
Save