From 26c3d6b823ed916938b08feff9acb7ae29f94657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 17:50:12 +0200 Subject: [PATCH 01/11] Add plex guid provider abstract class --- plextraktsync/plex/guid/provider/Abstract.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 plextraktsync/plex/guid/provider/Abstract.py diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py new file mode 100644 index 0000000000..a02804ec39 --- /dev/null +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -0,0 +1,5 @@ +from __future__ import annotations + + +class Abstract: + pass From c35e299b6c5892043d53c2f7842334719117547b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 17:54:48 +0200 Subject: [PATCH 02/11] Add construct for plex provider abstract --- plextraktsync/plex/guid/provider/Abstract.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py index a02804ec39..d925f90567 100644 --- a/plextraktsync/plex/guid/provider/Abstract.py +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -1,5 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from plextraktsync.plex.guid.PlexGuid import PlexGuid + class Abstract: - pass + def __init__(self, guid: PlexGuid): + self.guid = guid From 70117eab319abe14599aac5e5af0306acc8d1d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 17:57:38 +0200 Subject: [PATCH 03/11] Implement default title for Abstract --- plextraktsync/plex/guid/provider/Abstract.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py index d925f90567..0c7b41436b 100644 --- a/plextraktsync/plex/guid/provider/Abstract.py +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -1,5 +1,6 @@ from __future__ import annotations +from functools import cached_property from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -9,3 +10,7 @@ class Abstract: def __init__(self, guid: PlexGuid): self.guid = guid + + @cached_property + def title(self): + return f"{self.guid.provider}:{self.guid.type}:{self.guid.id}" From f89e6e6d5176ca9fe34726965aa98622fde5ca49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:01:57 +0200 Subject: [PATCH 04/11] Implement default link property for abstract --- plextraktsync/plex/guid/provider/Abstract.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py index 0c7b41436b..90bb28f767 100644 --- a/plextraktsync/plex/guid/provider/Abstract.py +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -14,3 +14,7 @@ def __init__(self, guid: PlexGuid): @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 From 7073c0898ef0dff52926f44b85a41c6b0d9ce1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 17:52:13 +0200 Subject: [PATCH 05/11] Implement markup for abstract guid provider --- plextraktsync/plex/guid/provider/Abstract.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plextraktsync/plex/guid/provider/Abstract.py b/plextraktsync/plex/guid/provider/Abstract.py index 90bb28f767..081f337f59 100644 --- a/plextraktsync/plex/guid/provider/Abstract.py +++ b/plextraktsync/plex/guid/provider/Abstract.py @@ -3,11 +3,13 @@ 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: +class Abstract(RichMarkup): def __init__(self, guid: PlexGuid): self.guid = guid @@ -18,3 +20,10 @@ def title(self): @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) From 4763ebcb4cadd592f50dd598240e007a07999a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:01:27 +0200 Subject: [PATCH 06/11] Update IMDB to extend from Abstract --- plextraktsync/plex/guid/provider/IMDB.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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}" From 95a3dc09970939df183d8351dbfc5815f3ef4c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:05:17 +0200 Subject: [PATCH 07/11] Update Local to extend from Abstract --- plextraktsync/plex/guid/provider/Local.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) 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 From 84551f251ce62155929e888ac71a658626a4350e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:05:49 +0200 Subject: [PATCH 08/11] Update Mbid to extend from Abstract --- plextraktsync/plex/guid/provider/Mbid.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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}" From 7314857d19c2ad91ec11d225615997ac5de21d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:06:27 +0200 Subject: [PATCH 09/11] Update TMDB to extend from Abstract --- plextraktsync/plex/guid/provider/TMDB.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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") From bc72f4c07d26d3943c497f9ec03fed0064d3d85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:06:59 +0200 Subject: [PATCH 10/11] Update TVDB to extend from Abstract --- plextraktsync/plex/guid/provider/TVDB.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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}" From f48fecbe0912c625f4a728ea11d9596cafec4073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 18:07:30 +0200 Subject: [PATCH 11/11] Update Youtube to extend from Abstract --- plextraktsync/plex/guid/provider/Youtube.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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}"