Extract PlexGuid class to own file
ADD
plextraktsync/plex/PlexGuid.py
+from __future__ import annotations
+
+from typing import Optional
+
+from plextraktsync.decorators.cached_property import cached_property
+from plextraktsync.factory import factory
+from plextraktsync.plex_api import PlexLibraryItem
+
+
+class PlexGuid:
+ def __init__(self, guid: str, type: str, pm: Optional[PlexLibraryItem] = None):
+ self.guid = guid
+ self.type = type
+ self.pm = pm
+
+ @cached_property
+ def media_type(self):
+ return f"{self.type}s"
+
+ @cached_property
+ def provider(self):
+ if self.guid_is_imdb_legacy:
+ return "imdb"
+ x = self.guid.split("://")[0]
+ x = x.replace("com.plexapp.agents.", "")
+ x = x.replace("tv.plex.agents.", "")
+ x = x.replace("themoviedb", "tmdb")
+ x = x.replace("thetvdb", "tvdb")
+ if x == "xbmcnfo":
+ CONFIG = factory.config
+ x = CONFIG["xbmc-providers"][self.media_type]
+ if x == "xbmcnfotv":
+ CONFIG = factory.config
+ x = CONFIG["xbmc-providers"]["shows"]
+
+ return x
+
+ @cached_property
+ def id(self):
+ if self.guid_is_imdb_legacy:
+ return self.guid
+ x = self.guid.split("://")[1]
+ x = x.split("?")[0]
+ return x
+
+ @cached_property
+ def is_episode(self):
+ """
+ Return true of the id is in form of <show>/<season>/<episode>
+ """
+ parts = self.id.split("/")
+ if len(parts) == 3 and all(x.isnumeric() for x in parts):
+ return True
+
+ return False
+
+ @cached_property
+ def show_id(self):
+ if not self.is_episode:
+ raise ValueError("show_id is not valid for non-episodes")
+
+ show = self.id.split("/", 1)[0]
+ if not show.isnumeric():
+ raise ValueError(f"show_id is not numeric: {show}")
+
+ return show
+
+ @cached_property
+ def guid_is_imdb_legacy(self):
+ guid = self.guid
+
+ # old item, like imdb 'tt0112253'
+ return guid[0:2] == "tt" and guid[2:].isnumeric()
+
+ def __str__(self):
+ return f"<PlexGuid:{self.guid}>"

MODIFY
plextraktsync/plex_api.py
plextraktsync/plex_api.py
from plextraktsync.factory import factory, logger
-class PlexGuid:
- def __init__(self, guid: str, type: str, pm: Optional[PlexLibraryItem] = None):
- self.guid = guid
- self.type = type
- self.pm = pm
-
- @cached_property
- def media_type(self):
- return f"{self.type}s"
-
- @cached_property
- def provider(self):
- if self.guid_is_imdb_legacy:
- return "imdb"
- x = self.guid.split("://")[0]
- x = x.replace("com.plexapp.agents.", "")
- x = x.replace("tv.plex.agents.", "")
- x = x.replace("themoviedb", "tmdb")
- x = x.replace("thetvdb", "tvdb")
- if x == "xbmcnfo":
- CONFIG = factory.config
- x = CONFIG["xbmc-providers"][self.media_type]
- if x == "xbmcnfotv":
- CONFIG = factory.config
- x = CONFIG["xbmc-providers"]["shows"]
-
- return x
-
- @cached_property
- def id(self):
- if self.guid_is_imdb_legacy:
- return self.guid
- x = self.guid.split("://")[1]
- x = x.split("?")[0]
- return x
-
- @cached_property
- def is_episode(self):
- """
- Return true of the id is in form of <show>/<season>/<episode>
- """
- parts = self.id.split("/")
- if len(parts) == 3 and all(x.isnumeric() for x in parts):
- return True
-
- return False
-
- @cached_property
- def show_id(self):
- if not self.is_episode:
- raise ValueError("show_id is not valid for non-episodes")
-
- show = self.id.split("/", 1)[0]
- if not show.isnumeric():
- raise ValueError(f"show_id is not numeric: {show}")
-
- return show
-
- @cached_property
- def guid_is_imdb_legacy(self):
- guid = self.guid
-
- # old item, like imdb 'tt0112253'
- return guid[0:2] == "tt" and guid[2:].isnumeric()
-
- def __str__(self):
- return f"<PlexGuid:{self.guid}>"
-
-
class PlexLibraryItem:
def __init__(self, item: Union[Movie, Show, Episode], plex: PlexApi = None):
self.item = item
@@ -107,6 +38,8 @@ def get_guids(self):
@cached_property
def guids(self):
+ from plextraktsync.plex.PlexGuid import PlexGuid
+
# return early if legacy agent
# accessing .guids for legacy agent
# will make another round-trip to plex server

MODIFY
plextraktsync/trakt_api.py
plextraktsync/trakt_api.py
from plextraktsync.decorators.time_limit import time_limit
from plextraktsync.factory import factory, logger, logging
from plextraktsync.path import pytrakt_file
-from plextraktsync.plex_api import PlexGuid, PlexLibraryItem
+from plextraktsync.plex.PlexGuid import PlexGuid
+from plextraktsync.plex_api import PlexLibraryItem
class ScrobblerProxy:

Extract PlexGuid class to own file