Skip to content

Commit

Permalink
Merge pull request #24 from zeroquinc:trakt-url
Browse files Browse the repository at this point in the history
feature: add trakt url to API
  • Loading branch information
zeroquinc authored Jun 22, 2024
2 parents 5eeecb9 + bdae214 commit 0dd10f7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/trakt/models/episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)
2 changes: 2 additions & 0 deletions api/trakt/models/favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ 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)

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
Expand Down
1 change: 1 addition & 0 deletions api/trakt/models/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions api/trakt/models/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ 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)

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
Expand Down
2 changes: 2 additions & 0 deletions api/trakt/models/season.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ 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']
self.trakt_id = data['show']['ids']['trakt']
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)
1 change: 1 addition & 0 deletions api/trakt/models/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/trakt/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0dd10f7

Please sign in to comment.