Add collecion related methods to Media class
MODIFY
plex_trakt_sync/media.py
plex_trakt_sync/media.py
@@ -11,7 +11,8 @@ class Media:
Class containing Plex and Trakt media items (Movie, Episode)
"""
- def __init__(self, plex, trakt):
+ def __init__(self, plex, trakt, trakt_api: TraktApi):
+ self.trakt_api = trakt_api
self.plex = plex
self.trakt = trakt
self.show = None
@@ -32,6 +33,21 @@ def trakt_id(self):
def show_trakt_id(self):
return self.show.trakt_id
+ @property
+ def is_movie(self):
+ return self.plex.type == "movie"
+
+ @property
+ def is_collected(self):
+ if self.is_movie:
+ return self.trakt_id in self.trakt_api.movie_collection_set
+
+ collected = self.trakt_api.collected(self.show.trakt)
+ return collected.get_completed(self.season_number, self.episode_number)
+
+ def add_to_collection(self):
+ self.trakt_api.add_to_collection(self.trakt, self.plex)
+
def __str__(self):
return str(self.plex)
@@ -73,4 +89,4 @@ def resolve(self, pm: PlexLibraryItem, tm=None):
logger.warning(f"Skipping {pm}: Not found on Trakt")
return None
- return Media(pm, tm)
+ return Media(pm, tm, trakt_api=self.trakt)

Add collecion related methods to Media class