-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2128 from glensc/PlexGuidProviderAbstract
Refactor: Move common provider to abstract class
- Loading branch information
Showing
7 changed files
with
53 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |