Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Unregister TraktListsPlugin if no lists to update #1917

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions plextraktsync/sync/TraktListsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from plextraktsync.plugin import hookimpl

if TYPE_CHECKING:
from .plugin.SyncPluginInterface import Media, TraktUserListCollection
from .plugin.SyncPluginInterface import (Media, SyncPluginManager,
TraktUserListCollection)


class TraktListsPlugin:
Expand All @@ -18,39 +19,36 @@ class TraktListsPlugin:

def __init__(self):
self.trakt_lists = None
self.add_to_lists = None

@staticmethod
def enabled(config):
# Use True for now, would need to keep in sync with other plugins
# Check for need is performed in init()
return True

@classmethod
def factory(cls, sync):
return cls()

@hookimpl(trylast=True)
def init(self, trakt_lists: TraktUserListCollection):
def init(self, pm: SyncPluginManager, trakt_lists: TraktUserListCollection):
self.trakt_lists = trakt_lists
# Skip updating lists if it's empty
self.add_to_lists = not trakt_lists.is_empty
if trakt_lists.is_empty:
self.logger.warning("Disabling TraktListsPlugin: No lists to process")
pm.unregister(self)

@hookimpl
def fini(self, dry_run: bool):
if dry_run or self.trakt_lists.is_empty:
if dry_run:
return

with measure_time("Updated liked list"):
self.trakt_lists.sync()

@hookimpl
def walk_movie(self, movie: Media):
if not self.add_to_lists:
return
self.trakt_lists.add_to_lists(movie)

@hookimpl
def walk_episode(self, episode: Media):
if not self.add_to_lists:
return
self.trakt_lists.add_to_lists(episode)
Loading