Skip to content

Commit

Permalink
Merge pull request #2128 from glensc/PlexGuidProviderAbstract
Browse files Browse the repository at this point in the history
Refactor: Move common provider to abstract class
  • Loading branch information
glensc authored Jan 1, 2025
2 parents cb97e2e + f48fecb commit f3a6f38
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 72 deletions.
29 changes: 29 additions & 0 deletions plextraktsync/plex/guid/provider/Abstract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING

from plextraktsync.rich.RichMarkup import RichMarkup

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid


class Abstract(RichMarkup):
def __init__(self, guid: PlexGuid):
self.guid = guid

@cached_property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"

@cached_property
def link(self) -> str | None:
return None

@cached_property
def markup(self):
if not self.link:
return self.markup_title(self.title)

return self.markup_link(self.link, self.title)
16 changes: 4 additions & 12 deletions plextraktsync/plex/guid/provider/IMDB.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid
from .Abstract import Abstract


class IMDB:
def __init__(self, guid: PlexGuid):
self.guid = guid

@property
class IMDB(Abstract):
@cached_property
def link(self):
return f"https://www.imdb.com/title/{self.guid.id}/"

@property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"
18 changes: 3 additions & 15 deletions plextraktsync/plex/guid/provider/Local.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from .Abstract import Abstract

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid


class Local:
def __init__(self, guid: PlexGuid):
self.guid = guid

@property
def link(self):
return None

@property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"
class Local(Abstract):
pass
16 changes: 4 additions & 12 deletions plextraktsync/plex/guid/provider/Mbid.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid
from .Abstract import Abstract


class Mbid:
def __init__(self, guid: PlexGuid):
self.guid = guid

@property
class Mbid(Abstract):
@cached_property
def link(self):
if self.guid.type == "artist":
return f"https://musicbrainz.org/artist/{self.guid.id}"
if self.guid.type == "album":
return f"https://musicbrainz.org/release/{self.guid.id}"

@property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"
16 changes: 4 additions & 12 deletions plextraktsync/plex/guid/provider/TMDB.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid
from .Abstract import Abstract


class TMDB:
class TMDB(Abstract):
url = "https://www.themoviedb.org"

def __init__(self, guid: PlexGuid):
self.guid = guid

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

return f"{self.url}/{self.type}/{self.guid.id}"

@property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"

@property
def show_guid(self):
return next(guid for guid in self.guid.pm.show.guids if guid.provider == "tmdb")
Expand Down
16 changes: 4 additions & 12 deletions plextraktsync/plex/guid/provider/TVDB.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid
from .Abstract import Abstract


class TVDB:
def __init__(self, guid: PlexGuid):
self.guid = guid

@property
class TVDB(Abstract):
@cached_property
def link(self):
return f"https://www.thetvdb.com/dereferrer/{self.guid.type}/{self.guid.id}"

@property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}"
14 changes: 5 additions & 9 deletions plextraktsync/plex/guid/provider/Youtube.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
from plextraktsync.plex.guid.PlexGuid import PlexGuid
from .Abstract import Abstract


class Youtube:
def __init__(self, guid: PlexGuid):
self.guid = guid

class Youtube(Abstract):
@property
def id(self):
return self.guid.id.split("|")[1]

@property
@cached_property
def link(self):
return f"https://www.youtube.com/watch?v={self.id}"

@property
@cached_property
def title(self):
return f"{self.guid.provider}:{self.guid.type}:{self.id}"

0 comments on commit f3a6f38

Please sign in to comment.