diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 4c732d9aab..d987957859 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -3,6 +3,9 @@ from functools import cached_property from typing import TYPE_CHECKING +from plexapi.library import LibrarySection +from plexapi.myplex import Section + from plextraktsync.decorators.flatten import flatten_dict from plextraktsync.factory import logging from plextraktsync.media.Media import Media @@ -18,8 +21,8 @@ class PlexPlaylist(RichMarkup): logger = logging.getLogger(__name__) - def __init__(self, server: PlexServer, name: str): - self.server = server + def __init__(self, section: LibrarySection, name: str): + self.section = section self.name = name def __iter__(self): @@ -32,13 +35,13 @@ def __contains__(self, m: Media): return m.plex_key in self.items @cached_property - def playlist(self) -> Playlist | None: + def playlist(self): try: - playlists = self.server.playlists(title=self.name, title__iexact=self.name) - playlist: Playlist = playlists[0] + playlists = self.section.collections(title=self.name, title__iexact=self.name) + playlist = playlists[0] if len(playlists) > 1: - self.logger.warning(f"Found multiple playlists ({len(playlists)}) with same name: '{self.name}', " - f"Using first playlist with id {playlist.ratingKey}") + self.logger.warning(f"Found multiple collections ({len(playlists)}) with same name: '{self.name}', " + f"Using first collection with id {playlist.ratingKey}") self.logger.debug(f"Loaded plex list: '{self.name}'") return playlist except IndexError: @@ -53,7 +56,7 @@ def items(self) -> dict[int, PlexMedia]: for m in self.playlist.items(): yield m.ratingKey, m - def update(self, items: list[PlexMedia], description=None) -> bool: + def update(self, section, items: list[PlexMedia], description=None) -> bool: """ Updates playlist (creates if name missing) replacing contents with items[] """ @@ -62,7 +65,7 @@ def update(self, items: list[PlexMedia], description=None) -> bool: # Force reload del self.__dict__["playlist"] del self.__dict__["items"] - playlist = self.server.createPlaylist(self.name, items=items) + playlist = self.section.createCollection(self.name, section=section, items=items) self.logger.info(f"Created plex playlist {self.title_link} with {len(items)} items", extra={"markup": True}) # Skip if playlist could not be made/retrieved diff --git a/plextraktsync/plex/PlexPlaylistCollection.py b/plextraktsync/plex/PlexPlaylistCollection.py index 987242bab5..2af6367627 100644 --- a/plextraktsync/plex/PlexPlaylistCollection.py +++ b/plextraktsync/plex/PlexPlaylistCollection.py @@ -6,15 +6,15 @@ from plextraktsync.plex.PlexPlaylist import PlexPlaylist if TYPE_CHECKING: - from plexapi.server import PlexServer + from plexapi.library import LibrarySection class PlexPlaylistCollection(UserDict): - def __init__(self, server: PlexServer): + def __init__(self, section: LibrarySection): super().__init__() - self.server = server + self.section = section def __missing__(self, name: str): - self[name] = playlist = PlexPlaylist(self.server, name) + self[name] = playlist = PlexPlaylist(self.section, name) return playlist diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 92b7ff8fcb..7a0b7e03d9 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -73,7 +73,10 @@ def from_watchlist(cls, items: list[TraktPlayable]): @cached_property def plex_lists(self): - return factory.plex_lists + from plextraktsync.plex.PlexPlaylistCollection import \ + PlexPlaylistCollection + + return PlexPlaylistCollection(self.section) @cached_property def plex_list(self):