From d879566a6e5e24972a9d899c8fc6758304e253b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:39:13 +0300 Subject: [PATCH 1/4] Add SyncPluginManager to SyncPluginInterface.init --- plextraktsync/sync/plugin/SyncPluginInterface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plextraktsync/sync/plugin/SyncPluginInterface.py b/plextraktsync/sync/plugin/SyncPluginInterface.py index 1b69bd8bf3..543f584eca 100644 --- a/plextraktsync/sync/plugin/SyncPluginInterface.py +++ b/plextraktsync/sync/plugin/SyncPluginInterface.py @@ -7,6 +7,7 @@ if TYPE_CHECKING: from plextraktsync.media.Media import Media from plextraktsync.plan.Walker import Walker + from plextraktsync.sync.plugin import SyncPluginManager from plextraktsync.sync.Sync import Sync from plextraktsync.trakt.TraktUserListCollection import \ TraktUserListCollection @@ -16,7 +17,7 @@ class SyncPluginInterface: """A hook specification namespace.""" @hookspec - def init(self, sync: Sync, trakt_lists: TraktUserListCollection, is_partial: bool, dry_run: bool): + def init(self, pm: SyncPluginManager, sync: Sync, trakt_lists: TraktUserListCollection, is_partial: bool, dry_run: bool): """Hook called at sync process initialization""" @hookspec From 816f1d95d8654a0f3fd7e7b12e052973eaa89f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:39:29 +0300 Subject: [PATCH 2/4] Add unregister to SyncPluginManager --- plextraktsync/sync/plugin/SyncPluginManager.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plextraktsync/sync/plugin/SyncPluginManager.py b/plextraktsync/sync/plugin/SyncPluginManager.py index 0c22a8820e..a278c01b2c 100644 --- a/plextraktsync/sync/plugin/SyncPluginManager.py +++ b/plextraktsync/sync/plugin/SyncPluginManager.py @@ -27,6 +27,10 @@ def pm(self): def hook(self): return self.pm.hook + @cached_property + def unregister(self): + return self.pm.unregister + @property def plugins(self): from ..AddCollectionPlugin import AddCollectionPlugin From 198e5e04d06f6960985db25e3933bfabbc8ac4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:39:45 +0300 Subject: [PATCH 3/4] Pass pm to pm.hook.init --- 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 b1e536146f..228ec6efe1 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -30,7 +30,7 @@ def sync(self, walker: Walker, dry_run=False): pm = SyncPluginManager() pm.register_plugins(self) - pm.hook.init(sync=self, trakt_lists=trakt_lists, is_partial=is_partial, dry_run=dry_run) + pm.hook.init(sync=self, pm=pm, trakt_lists=trakt_lists, is_partial=is_partial, dry_run=dry_run) if self.config.need_library_walk: for movie in walker.find_movies(): From 07c9b742d612159df27b6286263498d916ff6419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:40:16 +0300 Subject: [PATCH 4/4] ClearCollectedPlugin: unregister if in dry-run mode --- plextraktsync/sync/ClearCollectedPlugin.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/plextraktsync/sync/ClearCollectedPlugin.py b/plextraktsync/sync/ClearCollectedPlugin.py index 2a70f0961b..5315861877 100644 --- a/plextraktsync/sync/ClearCollectedPlugin.py +++ b/plextraktsync/sync/ClearCollectedPlugin.py @@ -8,6 +8,7 @@ if TYPE_CHECKING: from plextraktsync.config.SyncConfig import SyncConfig + from plextraktsync.sync.plugin import SyncPluginManager from plextraktsync.sync.Sync import Sync from plextraktsync.trakt.TraktApi import TraktApi from plextraktsync.trakt.types import TraktMedia @@ -20,7 +21,6 @@ def __init__(self, trakt: TraktApi): self.trakt = trakt self.episode_trakt_ids = set() self.movie_trakt_ids = set() - self.is_partial = None @staticmethod def enabled(config: SyncConfig): @@ -31,24 +31,20 @@ def factory(cls, sync: Sync): return cls(sync.trakt) @hookimpl - def init(self, is_partial: bool): - self.is_partial = is_partial - if is_partial: - self.logger.warning("Running partial library sync. Clear collected will be disabled.") + def init(self, pm: SyncPluginManager, is_partial: bool): + if not is_partial: + return + + self.logger.warning("Disabling Clear Collected: Running partial library sync") + pm.unregister(self) @hookimpl def fini(self, dry_run: bool): - if self.is_partial: - return - self.clear_collected(self.trakt.movie_collection, self.movie_trakt_ids, dry_run=dry_run) self.clear_collected(self.trakt.episodes_collection, self.episode_trakt_ids, dry_run=dry_run) @hookimpl def walk_movie(self, movie: Media): - if self.is_partial: - return - self.movie_trakt_ids.add(movie.trakt_id) def clear_collected(self, existing_items: Iterable[TraktMedia], keep_ids: set[int], dry_run):