-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1912 from glensc/trakt_lists-plugin
Refactor: Move trakt lists logic to TraktListsPlugin plugin
- Loading branch information
Showing
3 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters