add person list type, must be used in conjunction with --actor / -a parameter

pull/43/head
James 7 years ago committed by desimaniac
parent 3dd751fd1c
commit 6c1332e4d5

@ -85,13 +85,21 @@ class Trakt:
if req.status_code == 200: if req.status_code == 200:
resp_json = req.json() resp_json = req.json()
if type_name == 'person' and 'cast' in resp_json:
for item in resp_json: # handle person results
if item not in processed: for item in resp_json['cast']:
if object_name.rstrip('s') not in item and 'title' in item: if item not in processed:
processed.append({object_name.rstrip('s'): item}) if object_name.rstrip('s') not in item and 'title' in item:
else: processed.append({object_name.rstrip('s'): item})
processed.append(item) else:
processed.append(item)
else:
for item in resp_json:
if item not in processed:
if object_name.rstrip('s') not in item and 'title' in item:
processed.append({object_name.rstrip('s'): item})
else:
processed.append(item)
# check if we have fetched the last page, break if so # check if we have fetched the last page, break if so
if total_pages == 0: if total_pages == 0:
@ -356,6 +364,16 @@ class Trakt:
genres=genres genres=genres
) )
def get_person_shows(self, person, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/people/%s/shows' % person,
limit=limit,
languages=languages,
object_name='shows',
type_name='person',
genres=genres
)
def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None): def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type), url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type),
@ -451,6 +469,16 @@ class Trakt:
genres=genres genres=genres
) )
def get_person_movies(self, person, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/people/%s/movies' % person,
limit=limit,
languages=languages,
object_name='movies',
type_name='person',
genres=genres
)
def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None): def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type), url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type),

@ -172,14 +172,15 @@ def show(show_id, folder=None, no_search=False):
@app.command(help='Add multiple shows to Sonarr.') @app.command(help='Add multiple shows to Sonarr.')
@click.option('--list-type', '-t', @click.option('--list-type', '-t',
help='Trakt list to process. For example, anticipated, trending, popular, watched, played, watchlist ' help='Trakt list to process. For example, anticipated, trending, popular, person, watched, played, '
'or any URL to a list', required=True) '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-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('--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']), @click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.') help='Sort list to process.')
@click.option('--genre', '-g', default=None, help='Only add shows from this genre to Sonarr.') @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('--folder', '-f', default=None, help='Add shows with this root folder to Sonarr.')
@click.option('--actor', '-a', default=None, help='Only add movies from this actor to Radarr.')
@click.option('--no-search', is_flag=True, help='Disable search when adding shows 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('--notifications', is_flag=True, help='Send notifications.')
@click.option('--authenticate-user', @click.option('--authenticate-user',
@ -187,7 +188,7 @@ def show(show_id, folder=None, no_search=False):
@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.') @click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
@click.option('--remove-rejected-from-recommended', is_flag=True, @click.option('--remove-rejected-from-recommended', is_flag=True,
help='Removes rejected/existing shows from recommended.') help='Removes rejected/existing shows from recommended.')
def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, actor=None, no_search=False,
notifications=False, authenticate_user=None, ignore_blacklist=False, remove_rejected_from_recommended=False): notifications=False, authenticate_user=None, ignore_blacklist=False, remove_rejected_from_recommended=False):
from media.sonarr import Sonarr from media.sonarr import Sonarr
from media.trakt import Trakt from media.trakt import Trakt
@ -224,6 +225,12 @@ 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) trakt_objects_list = trakt.get_trending_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'popular': elif list_type.lower() == 'popular':
trakt_objects_list = trakt.get_popular_shows(genres=genre, languages=cfg.filters.shows.allowed_languages) trakt_objects_list = trakt.get_popular_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'person':
if not actor:
log.error("You must specify an actor with the --actor / -a parameter when using the person list type!")
return None
trakt_objects_list = trakt.get_person_shows(person=actor, genres=genre,
languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'recommended': elif list_type.lower() == 'recommended':
trakt_objects_list = trakt.get_recommended_shows(authenticate_user, genres=genre, trakt_objects_list = trakt.get_recommended_shows(authenticate_user, genres=genre,
languages=cfg.filters.shows.allowed_languages) languages=cfg.filters.shows.allowed_languages)
@ -379,15 +386,15 @@ def movie(movie_id, folder=None, no_search=False):
@app.command(help='Add multiple movies to Radarr.') @app.command(help='Add multiple movies to Radarr.')
@click.option('--list-type', '-t', @click.option('--list-type', '-t',
help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, watched, played, ' help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, person, watched, '
'watchlist or any URL to a list', 'played, watchlist or any URL to a list', required=True)
required=True)
@click.option('--add-limit', '-l', default=0, help='Limit number of movies added to Radarr.', show_default=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('--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']), @click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.') help='Sort list to process.')
@click.option('--genre', '-g', default=None, help='Only add movies from this genre to Radarr.') @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('--folder', '-f', default=None, help='Add movies with this root folder to Radarr.')
@click.option('--actor', '-a', default=None, help='Only add movies from this actor to Radarr.')
@click.option('--no-search', is_flag=True, help='Disable search when adding movies 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('--notifications', is_flag=True, help='Send notifications.')
@click.option('--authenticate-user', @click.option('--authenticate-user',
@ -395,7 +402,7 @@ def movie(movie_id, folder=None, no_search=False):
@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.') @click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
@click.option('--remove-rejected-from-recommended', is_flag=True, @click.option('--remove-rejected-from-recommended', is_flag=True,
help='Removes rejected/existing movies from recommended.') help='Removes rejected/existing movies from recommended.')
def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False, def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, actor=None, no_search=False,
notifications=False, authenticate_user=None, ignore_blacklist=False, remove_rejected_from_recommended=False): notifications=False, authenticate_user=None, ignore_blacklist=False, remove_rejected_from_recommended=False):
from media.radarr import Radarr from media.radarr import Radarr
from media.trakt import Trakt from media.trakt import Trakt
@ -433,6 +440,13 @@ 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) trakt_objects_list = trakt.get_popular_movies(genres=genre, languages=cfg.filters.movies.allowed_languages)
elif list_type.lower() == 'boxoffice': elif list_type.lower() == 'boxoffice':
trakt_objects_list = trakt.get_boxoffice_movies() trakt_objects_list = trakt.get_boxoffice_movies()
elif list_type.lower() == 'person':
if not actor:
log.error("You must specify an actor with the --actor / -a parameter when using the person list type!")
return None
trakt_objects_list = trakt.get_person_movies(person=actor, genres=genre,
languages=cfg.filters.movies.allowed_languages)
elif list_type.lower() == 'recommended': elif list_type.lower() == 'recommended':
trakt_objects_list = trakt.get_recommended_movies(authenticate_user, genres=genre, trakt_objects_list = trakt.get_recommended_movies(authenticate_user, genres=genre,
languages=cfg.filters.movies.allowed_languages) languages=cfg.filters.movies.allowed_languages)

Loading…
Cancel
Save