diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py new file mode 100644 index 0000000000..081f337f59 --- /dev/null +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -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) diff --git a/plextraktsync/plex/guid/provider/IMDB.py b/plextraktsync/plex/guid/provider/IMDB.py index 0018660d41..da096995a9 100644 --- a/plextraktsync/plex/guid/provider/IMDB.py +++ b/plextraktsync/plex/guid/provider/IMDB.py @@ -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}" diff --git a/plextraktsync/plex/guid/provider/Local.py b/plextraktsync/plex/guid/provider/Local.py index 2cccbc1ba6..9727f7fd7f 100644 --- a/plextraktsync/plex/guid/provider/Local.py +++ b/plextraktsync/plex/guid/provider/Local.py @@ -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 diff --git a/plextraktsync/plex/guid/provider/Mbid.py b/plextraktsync/plex/guid/provider/Mbid.py index f9af0a5f8b..e84a524380 100644 --- a/plextraktsync/plex/guid/provider/Mbid.py +++ b/plextraktsync/plex/guid/provider/Mbid.py @@ -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}" diff --git a/plextraktsync/plex/guid/provider/TMDB.py b/plextraktsync/plex/guid/provider/TMDB.py index a024d02594..f3d8de7fdf 100644 --- a/plextraktsync/plex/guid/provider/TMDB.py +++ b/plextraktsync/plex/guid/provider/TMDB.py @@ -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") diff --git a/plextraktsync/plex/guid/provider/TVDB.py b/plextraktsync/plex/guid/provider/TVDB.py index 99c155d60e..eda5e2956f 100644 --- a/plextraktsync/plex/guid/provider/TVDB.py +++ b/plextraktsync/plex/guid/provider/TVDB.py @@ -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}" diff --git a/plextraktsync/plex/guid/provider/Youtube.py b/plextraktsync/plex/guid/provider/Youtube.py index b3f6cb60d6..7227023b27 100644 --- a/plextraktsync/plex/guid/provider/Youtube.py +++ b/plextraktsync/plex/guid/provider/Youtube.py @@ -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}"