diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 1121da7139..967acd8cb6 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -110,8 +110,7 @@ def add(self, m: Media): def title_link(self): return self.plex_list.title_link - @property - def plex_items_sorted(self): + def plex_items_sorted(self, keep_watched=True): """ Returns items sorted by trakt rank @@ -120,7 +119,10 @@ def plex_items_sorted(self): if len(self.plex_items) == 0: return [] - plex_items = [(r, p.item) for (r, p) in self.plex_items] + plex_items = [(r, p.item) for (r, p) in self.plex_items if keep_watched or (not keep_watched and not p.is_watched)] + if len(plex_items) == 0: + return [] + _, items = zip(*sorted(dict(reversed(plex_items)).items())) return items diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index 05d6c2c528..2768a5e567 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -22,6 +22,8 @@ def add_to_lists(self, m: Media): # https://support.plex.tv/articles/multiple-editions/#:~:text=Do%20Multiple%20Editions%20work%20with%20watch%20state%20syncing%3F if m.plex.edition_title is not None: return + if not self.keep_watched and m.plex.is_watched: + return for tl in self: tl.add(m) @@ -41,7 +43,7 @@ def add_list(self, list_id: int, list_name: str): def sync(self): for tl in self: - updated = tl.plex_list.update(tl.plex_items_sorted) + updated = tl.plex_list.update(tl.plex_items_sorted(self.keep_watched)) if not updated: continue self.logger.info(f"Plex list {tl.title_link} ({len(tl.plex_items)} items) updated", extra={"markup": True})