Skip to content

Commit

Permalink
Filter liked list items with keep_watched
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 24, 2024
1 parent 97fac48 commit 7cbe4e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions plextraktsync/trakt/TraktUserList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion plextraktsync/trakt/TraktUserListCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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})

0 comments on commit 7cbe4e3

Please sign in to comment.