diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 92b7ff8fcb..8de329f125 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 5f26f3cd71..c5bf6357ec 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -23,6 +23,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) @@ -42,7 +44,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})