added trakt popular, recommended, played, watched, and collected

pull/102/head
meisnate12 4 years ago
parent 706b2c33c8
commit 1db527df57

@ -545,10 +545,10 @@ class CollectionBuilder:
else: else:
raise Failed(f"Collection Error: {m} attribute is not a dictionary: {data[m]}") raise Failed(f"Collection Error: {m} attribute is not a dictionary: {data[m]}")
elif method_name in util.count_lists: elif method_name in util.count_lists:
list_count = util.regex_first_int(data[m], "List Size", default=20) list_count = util.regex_first_int(data[m], "List Size", default=10)
if list_count < 1: if list_count < 1:
logger.warning(f"Collection Warning: {method_name} must be an integer greater then 0 defaulting to 20") logger.warning(f"Collection Warning: {method_name} must be an integer greater then 0 defaulting to 10")
list_count = 20 list_count = 10
self.methods.append((method_name, [list_count])) self.methods.append((method_name, [list_count]))
elif "tvdb" in method_name: elif "tvdb" in method_name:
values = util.get_list(data[m]) values = util.get_list(data[m])

@ -13,6 +13,7 @@ logger = logging.getLogger("Plex Meta Manager")
class TraktAPI: class TraktAPI:
def __init__(self, params, authorization=None): def __init__(self, params, authorization=None):
self.base_url = "https://api.trakt.tv"
self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob" self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
self.aliases = { self.aliases = {
"trakt_trending": "Trakt Trending", "trakt_trending": "Trakt Trending",
@ -93,10 +94,6 @@ class TraktAPI:
return lookup.get_key(to_source) if to_source == "imdb" else int(lookup.get_key(to_source)) return lookup.get_key(to_source) if to_source == "imdb" else int(lookup.get_key(to_source))
raise Failed(f"No {to_source.upper().replace('B', 'b')} ID found for {from_source.upper().replace('B', 'b')} ID {external_id}") raise Failed(f"No {to_source.upper().replace('B', 'b')} ID found for {from_source.upper().replace('B', 'b')} ID {external_id}")
@retry(stop_max_attempt_number=6, wait_fixed=10000)
def trending(self, amount, is_movie):
return Trakt["movies" if is_movie else "shows"].trending(per_page=amount)
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed)
def watchlist(self, data, is_movie): def watchlist(self, data, is_movie):
items = Trakt[f"users/{data}/watchlist"].movies() if is_movie else Trakt[f"users/{data}/watchlist"].shows() items = Trakt[f"users/{data}/watchlist"].movies() if is_movie else Trakt[f"users/{data}/watchlist"].shows()
@ -110,6 +107,15 @@ class TraktAPI:
if trakt_list is None: raise Failed("Trakt Error: No List found") if trakt_list is None: raise Failed("Trakt Error: No List found")
else: return trakt_list else: return trakt_list
@retry(stop_max_attempt_number=6, wait_fixed=10000)
def send_request(self, url):
return requests.get(url, headers={"Content-Type": "application/json", "trakt-api-version": "2", "trakt-api-key": self.client_id}).json()
def get_pagenation(self, pagenation, amount, is_movie):
items = self.send_request(f"{self.base_url}/{'movies' if is_movie else 'shows'}/{pagenation}?limit={amount}")
if is_movie: return [item["ids"]["tmdb" if is_movie else "tvdb"] for item in items], []
else: return [], [item["ids"]["tmdb" if is_movie else "tvdb"] for item in items]
def validate_trakt_list(self, values): def validate_trakt_list(self, values):
trakt_values = [] trakt_values = []
for value in values: for value in values:
@ -139,23 +145,24 @@ class TraktAPI:
logger.debug(f"Data: {data}") logger.debug(f"Data: {data}")
pretty = self.aliases[method] if method in self.aliases else method pretty = self.aliases[method] if method in self.aliases else method
media_type = "Movie" if is_movie else "Show" media_type = "Movie" if is_movie else "Show"
if method == "trakt_trending": if method in ["trakt_trending", "trakt_popular", "trakt_recommended", "trakt_played", "trakt_watched", "trakt_collected"]:
trakt_items = self.trending(int(data), is_movie) movie_ids, show_ids = self.get_pagenation(method[6:], data, is_movie)
if status_message: if status_message:
logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}") logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}")
else: else:
show_ids = []
movie_ids = []
if method == "trakt_watchlist": trakt_items = self.watchlist(data, is_movie) if method == "trakt_watchlist": trakt_items = self.watchlist(data, is_movie)
elif method == "trakt_list": trakt_items = self.standard_list(data).items() elif method == "trakt_list": trakt_items = self.standard_list(data).items()
else: raise Failed(f"Trakt Error: Method {method} not supported") else: raise Failed(f"Trakt Error: Method {method} not supported")
if status_message: logger.info(f"Processing {pretty}: {data}") if status_message: logger.info(f"Processing {pretty}: {data}")
show_ids = [] for trakt_item in trakt_items:
movie_ids = [] if isinstance(trakt_item, Movie): movie_ids.append(int(trakt_item.get_key("tmdb")))
for trakt_item in trakt_items: elif isinstance(trakt_item, Show) and trakt_item.pk[1] not in show_ids: show_ids.append(int(trakt_item.pk[1]))
if isinstance(trakt_item, Movie): movie_ids.append(int(trakt_item.get_key("tmdb"))) elif (isinstance(trakt_item, (Season, Episode))) and trakt_item.show.pk[1] not in show_ids: show_ids.append(int(trakt_item.show.pk[1]))
elif isinstance(trakt_item, Show) and trakt_item.pk[1] not in show_ids: show_ids.append(int(trakt_item.pk[1])) if status_message:
elif (isinstance(trakt_item, (Season, Episode))) and trakt_item.show.pk[1] not in show_ids: show_ids.append(int(trakt_item.show.pk[1])) logger.debug(f"Trakt {media_type} Found: {trakt_items}")
if status_message: if status_message:
logger.debug(f"Trakt {media_type} Found: {trakt_items}")
logger.debug(f"TMDb IDs Found: {movie_ids}") logger.debug(f"TMDb IDs Found: {movie_ids}")
logger.debug(f"TVDb IDs Found: {show_ids}") logger.debug(f"TVDb IDs Found: {show_ids}")
return movie_ids, show_ids return movie_ids, show_ids

@ -23,17 +23,17 @@ separating_character = "="
screen_width = 100 screen_width = 100
method_alias = { method_alias = {
"actors": "actor", "role": "actor", "roles": "actor", "actors": "actor", "role": "actor", "roles": "actor",
"content_ratings": "content_rating", "contentRating": "content_rating", "contentRatings": "content_rating", "content_ratings": "content_rating", "contentRating": "content_rating", "contentRatings": "content_rating",
"countries": "country", "countries": "country",
"decades": "decade", "decades": "decade",
"directors": "director", "directors": "director",
"genres": "genre", "genres": "genre",
"studios": "studio", "network": "studio", "networks": "studio", "studios": "studio", "network": "studio", "networks": "studio",
"producers": "producer", "producers": "producer",
"writers": "writer", "writers": "writer",
"years": "year" "years": "year"
} }
filter_alias = { filter_alias = {
"actor": "actors", "actor": "actors",
"audio_language": "audio_language", "audio_language": "audio_language",
@ -145,9 +145,14 @@ pretty_names = {
"tmdb_trending_weekly": "TMDb Trending Weekly", "tmdb_trending_weekly": "TMDb Trending Weekly",
"tmdb_writer": "TMDb Writer", "tmdb_writer": "TMDb Writer",
"tmdb_writer_details": "TMDb Writer", "tmdb_writer_details": "TMDb Writer",
"trakt_collected": "Trakt Collected",
"trakt_list": "Trakt List", "trakt_list": "Trakt List",
"trakt_list_details": "Trakt List", "trakt_list_details": "Trakt List",
"trakt_played": "Trakt Played",
"trakt_popular": "Trakt Popular",
"trakt_recommended": "Trakt Recommended",
"trakt_trending": "Trakt Trending", "trakt_trending": "Trakt Trending",
"trakt_watched": "Trakt Watched",
"trakt_watchlist": "Trakt Watchlist", "trakt_watchlist": "Trakt Watchlist",
"tvdb_list": "TVDb List", "tvdb_list": "TVDb List",
"tvdb_list_details": "TVDb List", "tvdb_list_details": "TVDb List",
@ -266,9 +271,14 @@ all_lists = [
"tmdb_trending_weekly", "tmdb_trending_weekly",
"tmdb_writer", "tmdb_writer",
"tmdb_writer_details", "tmdb_writer_details",
"trakt_collected",
"trakt_list", "trakt_list",
"trakt_list_details", "trakt_list_details",
"trakt_played",
"trakt_popular",
"trakt_recommended",
"trakt_trending", "trakt_trending",
"trakt_watched",
"trakt_watchlist", "trakt_watchlist",
"tvdb_list", "tvdb_list",
"tvdb_list_details", "tvdb_list_details",
@ -364,7 +374,12 @@ count_lists = [
"tmdb_now_playing", "tmdb_now_playing",
"tmdb_trending_daily", "tmdb_trending_daily",
"tmdb_trending_weekly", "tmdb_trending_weekly",
"trakt_trending" "trakt_trending",
"trakt_popular",
"trakt_recommended",
"trakt_played",
"trakt_watched",
"trakt_collected"
] ]
tmdb_lists = [ tmdb_lists = [
"tmdb_actor", "tmdb_actor",

Loading…
Cancel
Save