Bring back media.show property mistakenly removed in
MODIFY
plextraktsync/commands/watch.py
plextraktsync/commands/watch.py
@@ -133,6 +133,12 @@ def find_by_key(self, key: str, reload=False):
if not m:
return None
+ # setup show property for trakt watched status
+ if m.is_episode:
+ ps = self.plex.fetch_item(m.plex.item.grandparentRatingKey)
+ ms = self.mf.resolve_any(ps)
+ m.show = ms
+
return m
def on_error(self, error: Error):

MODIFY
plextraktsync/media.py
plextraktsync/media.py
@@ -23,11 +23,14 @@ def __init__(
trakt,
plex_api: PlexApi = None,
trakt_api: TraktApi = None,
+ mf: MediaFactory = None,
):
self.plex_api = plex_api
self.trakt_api = trakt_api
+ self.mf = mf
self.plex = plex
self.trakt = trakt
+ self._show = None
@cached_property
def media_type(self):
@@ -53,9 +56,25 @@ def plex_url(self):
def trakt_url(self):
return f"https://trakt.tv/{self.media_type}/{self.trakt_id}"
+ @property
+ def show(self) -> Optional[Media]:
+ if self._show is None and self.mf:
+ ps = self.plex_api.fetch_item(self.plex.item.grandparentRatingKey)
+ ms = self.mf.resolve_any(ps)
+ self._show = ms
+
+ return self._show
+
+ @show.setter
+ def show(self, show):
+ self._show = show
+
@property
def show_trakt_id(self):
- return getattr(self.trakt, "show_id", None)
+ show_id = getattr(self.trakt, "show_id", None)
+ if show_id:
+ return show_id
+ return self.show.trakt_id
@cached_property
def show_reset_at(self):
@@ -242,7 +261,7 @@ def resolve_trakt(self, tm: TraktItem) -> Media:
return self.make_media(pm, tm.item)
def make_media(self, plex, trakt):
- return Media(plex, trakt, plex_api=self.plex, trakt_api=self.trakt)
+ return Media(plex, trakt, plex_api=self.plex, trakt_api=self.trakt, mf=self)
def _guid_match(self, candidates: List[PlexLibraryItem], tm: TraktItem) -> Optional[PlexLibraryItem]:
if candidates:

MODIFY
plextraktsync/walker.py
plextraktsync/walker.py
@@ -284,6 +284,7 @@ def get_plex_episodes(self, episodes):
if not me:
continue
+ me.show = show
yield me
def media_from_sections(self, sections: List[PlexLibrarySection]):
@@ -308,6 +309,7 @@ def episode_from_show(self, show: Media):
if not me:
continue
+ me.show = show
yield me
def progressbar(self, iterable, **kwargs):

Bring back media.show property mistakenly removed in 1eaf574 (#1152)