From 598dea6847c589d65b0cb789d62f52380f8fd6d2 Mon Sep 17 00:00:00 2001 From: Fouad Chamoun Date: Fri, 4 Mar 2022 12:15:32 +0100 Subject: [PATCH] feat(trakt): add trakt_recommended_personal builder --- modules/builder.py | 2 +- modules/trakt.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 68aaf250..dba51b4c 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -172,7 +172,7 @@ custom_sort_builders = [ "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", diff --git a/modules/trakt.py b/modules/trakt.py index 16b7f359..9710f8ae 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -10,7 +10,7 @@ redirect_uri_encoded = redirect_uri.replace(":", "%3A") 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" ] @@ -226,6 +226,16 @@ class Trakt: 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") @@ -265,6 +275,9 @@ class Trakt: 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("_")