Skip to content

Commit

Permalink
ClearCollectedPlugin: unregister if in dry-run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 28, 2024
1 parent e61640a commit 1dab1eb
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions plextraktsync/sync/ClearCollectedPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 1dab1eb

Please sign in to comment.