From bdae2146f55c2217f1be7b148ffe88370c5d3b7b Mon Sep 17 00:00:00 2001 From: Zeroquinc Date: Sat, 22 Jun 2024 22:15:08 +0200 Subject: [PATCH] feature: add trakt url to API --- api/trakt/models/episode.py | 3 +++ api/trakt/models/favorite.py | 2 ++ api/trakt/models/movie.py | 1 + api/trakt/models/rating.py | 2 ++ api/trakt/models/season.py | 2 ++ api/trakt/models/show.py | 1 + src/trakt/functions.py | 4 ++-- 7 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/trakt/models/episode.py b/api/trakt/models/episode.py index cb21f51..7bba5eb 100644 --- a/api/trakt/models/episode.py +++ b/api/trakt/models/episode.py @@ -4,6 +4,8 @@ class Episode: def __init__(self, data): self.title = data['episode']['title'] self.show_title = data['show']['title'] + self.season_number = data['episode']['season'] + self.episode_number = data['episode']['number'] self.season_id = "{:02}".format(data['episode']['season']) # Format as two-digit number self.episode_id = "{:02}".format(data['episode']['number']) # Format as two-digit number self.year = data['show']['year'] @@ -12,4 +14,5 @@ def __init__(self, data): self.imdb_id = data['show']['ids']['imdb'] self.tmdb_id = data['show']['ids']['tmdb'] self.tvdb_id = data['show']['ids']['tvdb'] + self.url = f"https://trakt.tv/shows/{self.slug}/seasons/{self.season_number}/episodes/{self.episode_number}" self.poster = TMDb.show_poster_path(self.tvdb_id) \ No newline at end of file diff --git a/api/trakt/models/favorite.py b/api/trakt/models/favorite.py index ef9760a..a397cf5 100644 --- a/api/trakt/models/favorite.py +++ b/api/trakt/models/favorite.py @@ -20,6 +20,7 @@ def __init__(self, data): self.tvdb_id = None self.poster = None self.slug = None + self.url = None media = create_media(data) self.set_media_attributes(media) @@ -27,6 +28,7 @@ def set_media_attributes(self, media): self.title = media.title self.year = media.year self.poster = media.poster + self.url = media.url if isinstance(media, (Episode, Season)): self.show_title = media.show_title diff --git a/api/trakt/models/movie.py b/api/trakt/models/movie.py index aa390d5..101cc87 100644 --- a/api/trakt/models/movie.py +++ b/api/trakt/models/movie.py @@ -8,4 +8,5 @@ def __init__(self, data): self.trakt_id = data['movie']['ids']['trakt'] self.imdb_id = data['movie']['ids']['imdb'] self.tmdb_id = data['movie']['ids']['tmdb'] + self.url = f"https://trakt.tv/movies/{self.slug}" self.poster = TMDb.movie_poster_path(self.tmdb_id) \ No newline at end of file diff --git a/api/trakt/models/rating.py b/api/trakt/models/rating.py index 64807a4..7ff0668 100644 --- a/api/trakt/models/rating.py +++ b/api/trakt/models/rating.py @@ -22,6 +22,7 @@ def __init__(self, data): self.tvdb_id = None self.poster = None self.slug = None + self.url = None media = create_media(data) self.set_media_attributes(media) @@ -29,6 +30,7 @@ def set_media_attributes(self, media): self.title = media.title self.year = media.year self.poster = media.poster + self.url = media.url if isinstance(media, (Episode, Season)): self.show_title = media.show_title diff --git a/api/trakt/models/season.py b/api/trakt/models/season.py index 57b6d7a..060e1d3 100644 --- a/api/trakt/models/season.py +++ b/api/trakt/models/season.py @@ -4,6 +4,7 @@ class Season: def __init__(self, data): self.title = data['show']['title'] self.show_title = data['show']['title'] + self.season_number = data['season']['number'] self.season_id = "{:02}".format(data['season']['number']) # Format as two-digit number self.year = data['show']['year'] self.slug = data['show']['ids']['slug'] @@ -11,4 +12,5 @@ def __init__(self, data): self.imdb_id = data['show']['ids']['imdb'] self.tmdb_id = data['show']['ids']['tmdb'] self.tvdb_id = data['show']['ids']['tvdb'] + self.url = f"https://trakt.tv/shows/{self.slug}/seasons/{self.season_number}" self.poster = TMDb.show_poster_path(self.tvdb_id) \ No newline at end of file diff --git a/api/trakt/models/show.py b/api/trakt/models/show.py index 5ae7c2a..54218c3 100644 --- a/api/trakt/models/show.py +++ b/api/trakt/models/show.py @@ -10,4 +10,5 @@ def __init__(self, data): self.imdb_id = show_data['ids']['imdb'] self.tmdb_id = show_data['ids']['tmdb'] self.tvdb_id = show_data['ids']['tvdb'] + self.url = f"https://trakt.tv/shows/{self.slug}" self.poster = TMDb.show_poster_path(self.tvdb_id) \ No newline at end of file diff --git a/src/trakt/functions.py b/src/trakt/functions.py index 376d6cf..9cd56e7 100644 --- a/src/trakt/functions.py +++ b/src/trakt/functions.py @@ -29,7 +29,7 @@ async def process_rating(rating): description = f"{username} rated this {rating.type} {rating.rated} :star:" author = author_formats[rating.type] title = title_formats[rating.type] - embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000) + embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000, url=rating.url) embed_builder.set_thumbnail(url=rating.poster) embed_builder.set_author(name=author, icon_url=TRAKT_ICON) @@ -63,7 +63,7 @@ async def process_favorite(favorite): description = f"{username} favorited this {favorite.type}" author = author_formats[favorite.type] title = title_formats[favorite.type] - embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000) + embed_builder = EmbedBuilder(title=title, description=description, color=0xFF0000, url=favorite.url) embed_builder.set_thumbnail(url=favorite.poster) embed_builder.set_author(name=author, icon_url=TRAKT_ICON)