From 9473e94037f4ebd80adaa3ddf4b7182b4e0bc515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:10:38 +0300 Subject: [PATCH 1/3] Add TraktListsPlugin plugin --- plextraktsync/sync/TraktListsPlugin.py | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 plextraktsync/sync/TraktListsPlugin.py diff --git a/plextraktsync/sync/TraktListsPlugin.py b/plextraktsync/sync/TraktListsPlugin.py new file mode 100644 index 0000000000..b19d16f4a6 --- /dev/null +++ b/plextraktsync/sync/TraktListsPlugin.py @@ -0,0 +1,60 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from plextraktsync.decorators.measure_time import measure_time +from plextraktsync.factory import logging +from plextraktsync.plugin import hookimpl + +if TYPE_CHECKING: + from plextraktsync.config.SyncConfig import SyncConfig + from plextraktsync.media.Media import Media + from plextraktsync.sync.Sync import Sync + from plextraktsync.trakt.TraktUserListCollection import \ + TraktUserListCollection + + +class TraktListsPlugin: + """ + Plugin handling syncing of Trakt lists. + """ + logger = logging.getLogger(__name__) + + def __init__(self): + self.trakt_lists = None + self.add_to_lists = None + + @staticmethod + def enabled(config: SyncConfig): + # Use True for now, would need to keep in sync with other plugins + return True + + @classmethod + def factory(cls, sync: Sync): + return cls() + + @hookimpl(trylast=True) + def init(self, trakt_lists: TraktUserListCollection): + self.trakt_lists = trakt_lists + # Skip updating lists if it's empty + self.add_to_lists = not trakt_lists.is_empty + + @hookimpl + def fini(self, dry_run: bool): + if dry_run or self.trakt_lists.is_empty: + 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) From e2274445e335345afc72e5dc2b4ac3b0f9eb9088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:17:44 +0300 Subject: [PATCH 2/3] Register TraktListsPlugin plugin --- plextraktsync/sync/plugin/SyncPluginManager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plextraktsync/sync/plugin/SyncPluginManager.py b/plextraktsync/sync/plugin/SyncPluginManager.py index c7531c52d0..0c22a8820e 100644 --- a/plextraktsync/sync/plugin/SyncPluginManager.py +++ b/plextraktsync/sync/plugin/SyncPluginManager.py @@ -34,6 +34,7 @@ def plugins(self): from ..LikedListsPlugin import LikedListsPlugin from ..SyncRatingsPlugin import SyncRatingsPlugin from ..SyncWatchedPlugin import SyncWatchedPlugin + from ..TraktListsPlugin import TraktListsPlugin from ..WatchListPlugin import WatchListPlugin from ..WatchProgressPlugin import WatchProgressPlugin yield AddCollectionPlugin @@ -41,6 +42,7 @@ def plugins(self): yield LikedListsPlugin yield SyncRatingsPlugin yield SyncWatchedPlugin + yield TraktListsPlugin yield WatchListPlugin yield WatchProgressPlugin From 60917251867408315e669d2cda7a77150714834c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 28 Apr 2024 15:18:24 +0300 Subject: [PATCH 3/3] Skip trakt_lists logic from Sync class --- plextraktsync/sync/Sync.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plextraktsync/sync/Sync.py b/plextraktsync/sync/Sync.py index 20219c9f0c..e57a0277ed 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -2,7 +2,6 @@ from typing import TYPE_CHECKING -from plextraktsync.decorators.measure_time import measure_time from plextraktsync.factory import logging from plextraktsync.trakt.TraktUserListCollection import TraktUserListCollection @@ -33,22 +32,11 @@ def sync(self, walker: Walker, dry_run=False): pm.hook.init(sync=self, trakt_lists=trakt_lists, is_partial=is_partial, dry_run=dry_run) - # Skip updating lists if it's empty - add_to_lists = not trakt_lists.is_empty - if self.config.need_library_walk: for movie in walker.find_movies(): pm.hook.walk_movie(movie=movie, dry_run=dry_run) - if add_to_lists: - trakt_lists.add_to_lists(movie) for episode in walker.find_episodes(): pm.hook.walk_episode(episode=episode, dry_run=dry_run) - if add_to_lists: - trakt_lists.add_to_lists(episode) - - if not dry_run and not trakt_lists.is_empty: - with measure_time("Updated liked list"): - trakt_lists.sync() pm.hook.fini(walker=walker, trakt_lists=trakt_lists, dry_run=dry_run)