Skip to content

Commit

Permalink
Merge pull request #2135 from glensc/tmdb-refactor
Browse files Browse the repository at this point in the history
Refactor tmdb provider similar code
  • Loading branch information
glensc authored Jan 2, 2025
2 parents fe92612 + 9ed71e8 commit a3a35e1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions plextraktsync/plex/guid/provider/TMDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ class TMDB(Abstract):

@cached_property
def link(self):
if self.guid.type == "season":
return f"{self.url}/tv/{self.show_guid.id}/season/{self.season_number}"
url = f"{self.url}/{self.type}"
type = self.guid.type

if self.guid.type == "episode":
return f"{self.url}/tv/{self.show_guid.id}/season/{self.season_number}/episode/{self.episode_number}"
if type in ["show", "season", "episode"]:
url += f"/{self.show_guid.id}"

return f"{self.url}/{self.type}/{self.guid.id}"
if type in ["season", "episode"]:
url += f"/season/{self.season_number}"

if type == "episode":
url += f"/episode/{self.episode_number}"

if type == "movie":
url += f"/{self.guid.id}"

return url

@property
def show_guid(self):
return next(guid for guid in self.guid.pm.show.guids if guid.provider == "tmdb")
pm = self.guid.pm
guids = pm.guids if self.guid.type == "show" else pm.show.guids
return next(guid for guid in guids if guid.provider == "tmdb")

@property
def season_number(self):
Expand All @@ -32,10 +43,9 @@ def episode_number(self):

@property
def type(self):
try:
return {
"show": "tv",
"movie": "movie",
}[self.guid.type]
except IndexError:
return ""
return {
"show": "tv",
"season": "tv",
"episode": "tv",
"movie": "movie",
}[self.guid.type]

0 comments on commit a3a35e1

Please sign in to comment.