Skip to content

Commit

Permalink
Merge pull request #745 from fouadchamoun/feat/trakt-user-recommendat…
Browse files Browse the repository at this point in the history
…ions

feat(trakt): add trakt_recommended_personal builder
  • Loading branch information
meisnate12 authored Mar 5, 2022
2 parents ee5ad8b + 598dea6 commit 46c02f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"trakt_list", "trakt_watchlist", "trakt_collection", "trakt_trending", "trakt_popular", "trakt_boxoffice",
"trakt_collected_daily", "trakt_collected_weekly", "trakt_collected_monthly", "trakt_collected_yearly", "trakt_collected_all",
"flixpatrol_url", "flixpatrol_demographics", "flixpatrol_popular", "flixpatrol_top",
"trakt_recommended_daily", "trakt_recommended_weekly", "trakt_recommended_monthly", "trakt_recommended_yearly", "trakt_recommended_all",
"trakt_recommended_personal", "trakt_recommended_daily", "trakt_recommended_weekly", "trakt_recommended_monthly", "trakt_recommended_yearly", "trakt_recommended_all",
"trakt_watched_daily", "trakt_watched_weekly", "trakt_watched_monthly", "trakt_watched_yearly", "trakt_watched_all",
"tautulli_popular", "tautulli_watched", "mdblist_list", "letterboxd_list", "icheckmovies_list",
"anilist_top_rated", "anilist_popular", "anilist_trending", "anilist_search",
Expand Down
15 changes: 14 additions & 1 deletion modules/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
base_url = "https://api.trakt.tv"
builders = [
"trakt_collected_daily", "trakt_collected_weekly", "trakt_collected_monthly", "trakt_collected_yearly", "trakt_collected_all",
"trakt_recommended_daily", "trakt_recommended_weekly", "trakt_recommended_monthly", "trakt_recommended_yearly", "trakt_recommended_all",
"trakt_recommended_personal", "trakt_recommended_daily", "trakt_recommended_weekly", "trakt_recommended_monthly", "trakt_recommended_yearly", "trakt_recommended_all",
"trakt_watched_daily", "trakt_watched_weekly", "trakt_watched_monthly", "trakt_watched_yearly", "trakt_watched_all",
"trakt_collection", "trakt_list", "trakt_list_details", "trakt_popular", "trakt_trending", "trakt_watchlist", "trakt_boxoffice"
]
Expand Down Expand Up @@ -226,6 +226,16 @@ def _user_items(self, list_type, data, is_movie):
raise Failed(f"Trakt Error: {data}'s {list_type.capitalize()} is empty")
return self._parse(items, item_type="movie" if is_movie else "show")

def _user_recommendations(self, amount, is_movie):
media_type = "Movie" if is_movie else "Show"
try:
items = self._request(f"/recommendations/{'movies' if is_movie else 'shows'}/?limit={amount}")
except Failed:
raise Failed(f"Trakt Error: failed to fetch {media_type} Recommendations")
if len(items) == 0:
raise Failed(f"Trakt Error: no {media_type} Recommendations were found")
return self._parse(items, item_type="movie" if is_movie else "show")

def _pagenation(self, pagenation, amount, is_movie):
items = self._request(f"/{'movies' if is_movie else 'shows'}/{pagenation}?limit={amount}")
return self._parse(items, typeless=pagenation == "popular", item_type="movie" if is_movie else "show")
Expand Down Expand Up @@ -265,6 +275,9 @@ def get_trakt_ids(self, method, data, is_movie):
elif method == "trakt_list":
logger.info(f"Processing {pretty}: {data}")
return self._user_list(data)
elif method == "trakt_recommended_personal":
logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}")
return self._user_recommendations(data, is_movie)
elif method in builders:
logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}")
terms = method.split("_")
Expand Down

0 comments on commit 46c02f1

Please sign in to comment.