From a54a0cffe2cea29333cf346dba4e5db923a313f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 10 Mar 2024 23:11:31 +0200 Subject: [PATCH 01/27] Add simplified type fort SyncConfig.config --- plextraktsync/config/SyncConfig.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/config/SyncConfig.py b/plextraktsync/config/SyncConfig.py index bcad138c22..2174d5caa0 100644 --- a/plextraktsync/config/SyncConfig.py +++ b/plextraktsync/config/SyncConfig.py @@ -4,11 +4,15 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: + from typing import Any + from plextraktsync.config.Config import Config from plextraktsync.config.PlexServerConfig import PlexServerConfig class SyncConfig: + config: dict[str, Any] + def __init__(self, config: Config, server_config: PlexServerConfig): self.config = dict(config["sync"]) self.server_config = server_config.sync_config From 8830328530750ccbab9cbe65de8c871e1b7b14f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 10 Mar 2024 23:07:21 +0200 Subject: [PATCH 02/27] Add liked_list top level default config --- plextraktsync/config.default.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plextraktsync/config.default.yml b/plextraktsync/config.default.yml index 0459d6956c..2b678c0a72 100644 --- a/plextraktsync/config.default.yml +++ b/plextraktsync/config.default.yml @@ -76,6 +76,11 @@ sync: # Sync Play Progress from Trakt to Plex playback_status: false +# Configuration for liked lists +liked_lists: + # Whether to keep watched items in the list + keep_watched: true + # settings for 'watch' command watch: add_collection: false From 27fe892243f04af87a209015851919b77c4c18f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:47:32 +0300 Subject: [PATCH 03/27] Add example liked list overrides to default config --- plextraktsync/config.default.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plextraktsync/config.default.yml b/plextraktsync/config.default.yml index 2b678c0a72..5614d89927 100644 --- a/plextraktsync/config.default.yml +++ b/plextraktsync/config.default.yml @@ -81,6 +81,11 @@ liked_lists: # Whether to keep watched items in the list keep_watched: true +# Configuration override for specific lists +#liked_list: +# "Saw Collection": +# keep_watched: true + # settings for 'watch' command watch: add_collection: false From 0b5ce50fe6b2b65c25d4530356d2222eb5f5cc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 23 Feb 2024 17:19:11 +0200 Subject: [PATCH 04/27] Add liked_lists_keep_watched SyncConfig property --- plextraktsync/config/SyncConfig.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plextraktsync/config/SyncConfig.py b/plextraktsync/config/SyncConfig.py index 2174d5caa0..f18342f9e4 100644 --- a/plextraktsync/config/SyncConfig.py +++ b/plextraktsync/config/SyncConfig.py @@ -15,6 +15,7 @@ class SyncConfig: def __init__(self, config: Config, server_config: PlexServerConfig): self.config = dict(config["sync"]) + self.liked_lists = config["liked_lists"] self.server_config = server_config.sync_config def __getitem__(self, key): @@ -65,6 +66,10 @@ def sync_watched_status(self): self.trakt_to_plex["watched_status"] or self.plex_to_trakt["watched_status"] ) + @property + def liked_lists_keep_watched(self): + return self.liked_lists["keep_watched"] + @cached_property def sync_playback_status(self): return self["trakt_to_plex"]["playback_status"] From a8ac4a1fb7f66daf53e33484f31d76c0f2391b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 23 Feb 2024 17:19:37 +0200 Subject: [PATCH 05/27] Add keep_watched property to TraktUserListCollection --- plextraktsync/trakt/TraktUserListCollection.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index 8de23d0c8e..9f24a6567b 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -14,6 +14,10 @@ class TraktUserListCollection(UserList): logger = logging.getLogger(__name__) + def __init__(self, keep_watched=True): + super().__init__() + self.keep_watched = keep_watched + @property def is_empty(self): return not len(self) From 6064b87aa141854190646c06171cb8c042ff3c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 23 Feb 2024 17:20:03 +0200 Subject: [PATCH 06/27] Configure keep_watched for TraktUserListCollection --- plextraktsync/sync/Sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/sync/Sync.py b/plextraktsync/sync/Sync.py index 14961659bd..4a6bd5b2be 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -24,7 +24,7 @@ def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi): @cached_property def trakt_lists(self): - return TraktUserListCollection() + return TraktUserListCollection(self.config.liked_lists_keep_watched) @cached_property def pm(self): From 3ff8c6b878995c52ca35ac1210a1a643e9f32288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 23 Feb 2024 17:21:17 +0200 Subject: [PATCH 07/27] Filter liked list items with keep_watched. XXX --- plextraktsync/trakt/TraktUserList.py | 12 +++++++++--- plextraktsync/trakt/TraktUserListCollection.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index d21de74261..92becfc88a 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -118,8 +118,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 @@ -128,7 +127,14 @@ 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 9f24a6567b..f6846a0d5d 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -27,6 +27,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) @@ -43,3 +45,13 @@ def add_list(self, list_id: int, list_name: str): tl = TraktUserList.from_trakt_list(list_id, list_name) self.append(tl) return tl + + def sync(self): + for tl in self: + 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}, + ) From 26f37c9a1fc5db9c48954b80fd6280a22c977c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 30 Apr 2024 21:00:05 +0300 Subject: [PATCH 08/27] Add keep_watched to TraktListsPlugin --- plextraktsync/sync/TraktListsPlugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index a670ea0e7a..122a5a940e 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -17,7 +17,8 @@ class TraktListsPlugin: logger = logging.getLogger(__name__) - def __init__(self): + def __init__(self, keep_watched: bool): + self.keep_watched = keep_watched self.trakt_lists = None @staticmethod @@ -32,8 +33,8 @@ def enabled(config): ) @classmethod - def factory(cls, sync): - return cls() + def factory(cls, sync: Sync): + return cls(sync.config.liked_lists_keep_watched) @hookimpl(trylast=True) def init(self, pm: SyncPluginManager, sync: Sync): From ca89cdf7651232e12b59c815420658840c7eb9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 30 Apr 2024 21:00:25 +0300 Subject: [PATCH 09/27] Check keep_watched in TraktListsPlugin --- plextraktsync/sync/TraktListsPlugin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 122a5a940e..2a13896a2f 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -63,8 +63,14 @@ async def fini(self, dry_run: bool): @hookimpl async def walk_movie(self, movie: Media): + if not self.keep_watched and movie.plex.is_watched: + return + self.trakt_lists.add_to_lists(movie) @hookimpl async def walk_episode(self, episode: Media): + if not self.keep_watched and episode.plex.is_watched: + return + self.trakt_lists.add_to_lists(episode) From a632e537d389a2014340019d6261741797bac633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 30 Apr 2024 21:01:15 +0300 Subject: [PATCH 10/27] tl.plex_items_sorted is method --- plextraktsync/sync/TraktListsPlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 2a13896a2f..fe9a65c00d 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -53,7 +53,7 @@ async def fini(self, dry_run: bool): with measure_time("Updated Trakt Lists"): for tl in self.trakt_lists: - 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( From 3b77aca0921030a6eb6a4144e33180c012442f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 30 Apr 2024 21:02:26 +0300 Subject: [PATCH 11/27] Cleanup superfluous sync from TraktUserListCollection --- plextraktsync/trakt/TraktUserListCollection.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index f6846a0d5d..fdee8e5c7d 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -45,13 +45,3 @@ def add_list(self, list_id: int, list_name: str): tl = TraktUserList.from_trakt_list(list_id, list_name) self.append(tl) return tl - - def sync(self): - for tl in self: - 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}, - ) From ca94424c7b1db057b44031afe8e55da39749dc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:19:23 +0300 Subject: [PATCH 12/27] Cleanup keep_watched from TraktUserListCollection --- plextraktsync/sync/Sync.py | 2 +- plextraktsync/trakt/TraktUserListCollection.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plextraktsync/sync/Sync.py b/plextraktsync/sync/Sync.py index 4a6bd5b2be..14961659bd 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -24,7 +24,7 @@ def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi): @cached_property def trakt_lists(self): - return TraktUserListCollection(self.config.liked_lists_keep_watched) + return TraktUserListCollection() @cached_property def pm(self): diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index fdee8e5c7d..8de23d0c8e 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -14,10 +14,6 @@ class TraktUserListCollection(UserList): logger = logging.getLogger(__name__) - def __init__(self, keep_watched=True): - super().__init__() - self.keep_watched = keep_watched - @property def is_empty(self): return not len(self) @@ -27,8 +23,6 @@ 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) From 155fd07e53afda40bc70bd48ddee790524e101da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:32:30 +0300 Subject: [PATCH 13/27] Add trakt_lists_config to TraktListsPlugin --- plextraktsync/sync/TraktListsPlugin.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index fe9a65c00d..23a8c33f67 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -17,9 +17,10 @@ class TraktListsPlugin: logger = logging.getLogger(__name__) - def __init__(self, keep_watched: bool): + def __init__(self, keep_watched: bool, trakt_lists_config=None): self.keep_watched = keep_watched self.trakt_lists = None + self.trakt_lists_config = trakt_lists_config or {} @staticmethod def enabled(config): @@ -34,7 +35,10 @@ def enabled(config): @classmethod def factory(cls, sync: Sync): - return cls(sync.config.liked_lists_keep_watched) + return cls( + sync.config.liked_lists_keep_watched, + sync.config.liked_lists, + ) @hookimpl(trylast=True) def init(self, pm: SyncPluginManager, sync: Sync): From 7dc00085a155051060d5ed9fea50e441b45421bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:33:07 +0300 Subject: [PATCH 14/27] Add list_keep_watched method --- plextraktsync/sync/TraktListsPlugin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 23a8c33f67..c864f36e77 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -7,6 +7,7 @@ from plextraktsync.plugin import hookimpl if TYPE_CHECKING: + from ..trakt.TraktUserList import TraktUserList from .plugin.SyncPluginInterface import Media, Sync, SyncPluginManager @@ -65,6 +66,12 @@ async def fini(self, dry_run: bool): extra={"markup": True}, ) + def list_keep_watched(self, tl: TraktUserList): + config = self.trakt_lists_config.get(tl.name) + if config is None: + return self.keep_watched + return config.get("keep_watched", self.keep_watched) + @hookimpl async def walk_movie(self, movie: Media): if not self.keep_watched and movie.plex.is_watched: From a87720b8994941e6f7058e6fb7b51fc158831e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:33:23 +0300 Subject: [PATCH 15/27] Check per list keep_watched setting --- plextraktsync/sync/TraktListsPlugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index c864f36e77..a395b0c6bf 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -58,7 +58,8 @@ async def fini(self, dry_run: bool): with measure_time("Updated Trakt Lists"): for tl in self.trakt_lists: - updated = tl.plex_list.update(tl.plex_items_sorted(self.keep_watched)) + items = tl.plex_items_sorted(self.list_keep_watched(tl)) + updated = tl.plex_list.update(items) if not updated: continue self.logger.info( From f93e87f3f09fcc5824d113323b0594df4e5acf34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 00:35:30 +0300 Subject: [PATCH 16/27] Load overrides from overrides section --- plextraktsync/sync/TraktListsPlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index a395b0c6bf..67c8cac52b 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -38,7 +38,7 @@ def enabled(config): def factory(cls, sync: Sync): return cls( sync.config.liked_lists_keep_watched, - sync.config.liked_lists, + sync.config.liked_lists.get("overrides", {}), ) @hookimpl(trylast=True) From e6b995e2ac87bddbfdfd65bfc7c1a809fe122b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:47:40 +0300 Subject: [PATCH 17/27] Add liked_lists_overrides SyncConfig --- plextraktsync/config/SyncConfig.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/config/SyncConfig.py b/plextraktsync/config/SyncConfig.py index f18342f9e4..09e92b3b4a 100644 --- a/plextraktsync/config/SyncConfig.py +++ b/plextraktsync/config/SyncConfig.py @@ -70,6 +70,10 @@ def sync_watched_status(self): def liked_lists_keep_watched(self): return self.liked_lists["keep_watched"] + @property + def liked_lists_overrides(self): + return self.liked_lists.get("overrides", {}) + @cached_property def sync_playback_status(self): return self["trakt_to_plex"]["playback_status"] From 7d8899137181aaa0a98ec4916857336f676f9906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:48:17 +0300 Subject: [PATCH 18/27] Use liked_lists_overrides config --- plextraktsync/sync/TraktListsPlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 67c8cac52b..4ecb9c9850 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -38,7 +38,7 @@ def enabled(config): def factory(cls, sync: Sync): return cls( sync.config.liked_lists_keep_watched, - sync.config.liked_lists.get("overrides", {}), + sync.config.liked_lists_overrides, ) @hookimpl(trylast=True) From abd6c7b39ebe9a929c555e58ae426e23b98980d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:51:04 +0300 Subject: [PATCH 19/27] Add keep_watched, trakt_lists_overrides to TraktUserListCollection --- plextraktsync/sync/Sync.py | 5 ++++- plextraktsync/trakt/TraktUserListCollection.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plextraktsync/sync/Sync.py b/plextraktsync/sync/Sync.py index 14961659bd..9c36b0c58a 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -24,7 +24,10 @@ def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi): @cached_property def trakt_lists(self): - return TraktUserListCollection() + return TraktUserListCollection( + self.config.liked_lists_keep_watched, + self.config.liked_lists_overrides, + ) @cached_property def pm(self): diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index 8de23d0c8e..3c73122b71 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -14,6 +14,11 @@ class TraktUserListCollection(UserList): logger = logging.getLogger(__name__) + def __init__(self, keep_watched: bool, trakt_lists_overrides: dict): + super().__init__() + self.keep_watched = keep_watched + self.trakt_lists_overrides = trakt_lists_overrides + @property def is_empty(self): return not len(self) From dac207ad95a8c1df385b5c4e7700aba4e7b3db36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:53:47 +0300 Subject: [PATCH 20/27] Add keep_watched to TraktUserList --- plextraktsync/trakt/TraktUserList.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 92becfc88a..def1e8cece 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -23,12 +23,14 @@ def __init__( trakt_id: int = None, name: str = None, items=None, + keep_watched: bool = None, ): self.trakt_id = trakt_id self.name = name self._items = items self.description = None self.plex_items = [] + self.keep_watched = keep_watched def __iter__(self): return iter(self.items) From 52d6feee0ed12c639d0aedf3e6a0a396382e5762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:54:58 +0300 Subject: [PATCH 21/27] Add keep watched from config to TraktUserList --- plextraktsync/trakt/TraktUserList.py | 4 ++-- plextraktsync/trakt/TraktUserListCollection.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index def1e8cece..1dbef2eaaa 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -66,8 +66,8 @@ def load_items(self): return pl.description, self.build_dict(pl) @classmethod - def from_trakt_list(cls, list_id: int, list_name: str): - return cls(trakt_id=list_id, name=list_name) + def from_trakt_list(cls, list_id: int, list_name: str, keep_watched: bool): + return cls(trakt_id=list_id, name=list_name, keep_watched=keep_watched) @classmethod def from_watchlist(cls, items: list[TraktPlayable]): diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index 3c73122b71..73871ba794 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -41,6 +41,8 @@ def add_watchlist(self, items: list[TraktPlayable]): return tl def add_list(self, list_id: int, list_name: str): - tl = TraktUserList.from_trakt_list(list_id, list_name) + list_config = self.trakt_lists_overrides.get(list_name, {}) + keep_watched = list_config.get("keep_watched", self.keep_watched) + tl = TraktUserList.from_trakt_list(list_id, list_name, keep_watched) self.append(tl) return tl From da6613e175ea4b99ef52b06d8e73c0a9d51a22a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 07:58:59 +0300 Subject: [PATCH 22/27] Use keep_watched from list property --- plextraktsync/trakt/TraktUserList.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 1dbef2eaaa..72d150c152 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -120,7 +120,7 @@ def add(self, m: Media): def title_link(self): return self.plex_list.title_link - def plex_items_sorted(self, keep_watched=True): + def plex_items_sorted(self): """ Returns items sorted by trakt rank @@ -132,7 +132,7 @@ def plex_items_sorted(self, keep_watched=True): 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 self.keep_watched or (not self.keep_watched and not p.is_watched) ] if len(plex_items) == 0: return [] From e2617ed10da302e5f4998203a4229343f3649399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 08:19:51 +0300 Subject: [PATCH 23/27] Undo keep_watched check in the plugin --- plextraktsync/sync/TraktListsPlugin.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 4ecb9c9850..776ce27f3c 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -7,7 +7,6 @@ from plextraktsync.plugin import hookimpl if TYPE_CHECKING: - from ..trakt.TraktUserList import TraktUserList from .plugin.SyncPluginInterface import Media, Sync, SyncPluginManager @@ -18,10 +17,9 @@ class TraktListsPlugin: logger = logging.getLogger(__name__) - def __init__(self, keep_watched: bool, trakt_lists_config=None): + def __init__(self, keep_watched: bool): self.keep_watched = keep_watched self.trakt_lists = None - self.trakt_lists_config = trakt_lists_config or {} @staticmethod def enabled(config): @@ -38,7 +36,6 @@ def enabled(config): def factory(cls, sync: Sync): return cls( sync.config.liked_lists_keep_watched, - sync.config.liked_lists_overrides, ) @hookimpl(trylast=True) @@ -58,7 +55,7 @@ async def fini(self, dry_run: bool): with measure_time("Updated Trakt Lists"): for tl in self.trakt_lists: - items = tl.plex_items_sorted(self.list_keep_watched(tl)) + items = tl.plex_items_sorted() updated = tl.plex_list.update(items) if not updated: continue @@ -67,22 +64,10 @@ async def fini(self, dry_run: bool): extra={"markup": True}, ) - def list_keep_watched(self, tl: TraktUserList): - config = self.trakt_lists_config.get(tl.name) - if config is None: - return self.keep_watched - return config.get("keep_watched", self.keep_watched) - @hookimpl async def walk_movie(self, movie: Media): - if not self.keep_watched and movie.plex.is_watched: - return - self.trakt_lists.add_to_lists(movie) @hookimpl async def walk_episode(self, episode: Media): - if not self.keep_watched and episode.plex.is_watched: - return - self.trakt_lists.add_to_lists(episode) From 34326a9dcd040db11eb4bc42e762c1b00bd2674b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 08:21:24 +0300 Subject: [PATCH 24/27] Cleanup keep_watched from plugin --- plextraktsync/sync/TraktListsPlugin.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 776ce27f3c..4edab822ba 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -17,8 +17,7 @@ class TraktListsPlugin: logger = logging.getLogger(__name__) - def __init__(self, keep_watched: bool): - self.keep_watched = keep_watched + def __init__(self): self.trakt_lists = None @staticmethod @@ -33,10 +32,8 @@ def enabled(config): ) @classmethod - def factory(cls, sync: Sync): - return cls( - sync.config.liked_lists_keep_watched, - ) + def factory(cls, sync): + return cls() @hookimpl(trylast=True) def init(self, pm: SyncPluginManager, sync: Sync): From 0ad29b4cf774866d9261515ad6a35336fc0f92f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 08:24:08 +0300 Subject: [PATCH 25/27] Skip adding watched items --- plextraktsync/trakt/TraktUserList.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 72d150c152..05a43ce67f 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -100,6 +100,10 @@ def add(self, m: Media): # Already in the list return + if not self.keep_watched and m.plex.is_watched: + # Skip adding watched items + return + self.logger.info( f"Adding {m.title_link} ({m.plex_key}) to Plex list {self.title_link}", extra={"markup": True}, From 788b26fa25916ced56e741f5dfa45b228590e433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 May 2024 08:30:06 +0300 Subject: [PATCH 26/27] Use liked_list for overrides --- plextraktsync/config/SyncConfig.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plextraktsync/config/SyncConfig.py b/plextraktsync/config/SyncConfig.py index 09e92b3b4a..df6fe8a735 100644 --- a/plextraktsync/config/SyncConfig.py +++ b/plextraktsync/config/SyncConfig.py @@ -16,6 +16,7 @@ class SyncConfig: def __init__(self, config: Config, server_config: PlexServerConfig): self.config = dict(config["sync"]) self.liked_lists = config["liked_lists"] + self.liked_lists_overrides = config["liked_list"] or {} self.server_config = server_config.sync_config def __getitem__(self, key): @@ -70,10 +71,6 @@ def sync_watched_status(self): def liked_lists_keep_watched(self): return self.liked_lists["keep_watched"] - @property - def liked_lists_overrides(self): - return self.liked_lists.get("overrides", {}) - @cached_property def sync_playback_status(self): return self["trakt_to_plex"]["playback_status"] From b0664a3b51bf2a24d6a38ba2c21328e266322b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Jun 2024 19:48:42 +0300 Subject: [PATCH 27/27] Keep plex_items_sorted as property --- plextraktsync/sync/TraktListsPlugin.py | 3 +-- plextraktsync/trakt/TraktUserList.py | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py index 4edab822ba..a670ea0e7a 100644 --- a/plextraktsync/sync/TraktListsPlugin.py +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -52,8 +52,7 @@ async def fini(self, dry_run: bool): with measure_time("Updated Trakt Lists"): for tl in self.trakt_lists: - items = tl.plex_items_sorted() - updated = tl.plex_list.update(items) + updated = tl.plex_list.update(tl.plex_items_sorted) if not updated: continue self.logger.info( diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 05a43ce67f..40001e37ef 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -124,6 +124,7 @@ def add(self, m: Media): def title_link(self): return self.plex_list.title_link + @property def plex_items_sorted(self): """ Returns items sorted by trakt rank