From f784ca0d3acd4ee148ddbcad1d1a93367dc102b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 26 Feb 2024 23:58:55 +0200 Subject: [PATCH] Try to figure section automatically --- plextraktsync/plex/PlexPlaylist.py | 9 +++++++-- plextraktsync/plex/PlexPlaylistCollection.py | 7 +++++-- plextraktsync/trakt/TraktUserList.py | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 55ba7194454..ad1c4767191 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -10,18 +10,21 @@ from plextraktsync.factory import logging from plextraktsync.media.Media import Media from plextraktsync.mixin.RichMarkup import RichMarkup +from plextraktsync.plex.PlexLibraryItem import PlexLibraryItem if TYPE_CHECKING: from plexapi.playlist import Playlist from plexapi.server import PlexServer + from plextraktsync.plex.PlexApi import PlexApi from plextraktsync.plex.types import PlexMedia class PlexPlaylist(RichMarkup): logger = logging.getLogger(__name__) - def __init__(self, section: LibrarySection, name: str): + def __init__(self, plex: PlexApi, section: LibrarySection, name: str): + self.plex = plex self.section = section self.name = name @@ -65,7 +68,9 @@ def update(self, items: list[PlexMedia], description=None) -> bool: # Force reload del self.__dict__["playlist"] del self.__dict__["items"] - playlist = self.section.createCollection(self.name, section=self.section, items=items) + for item in items: + print(type(item), PlexLibraryItem(item, plex=self.plex).library.section) + playlist = self.section.createCollection(self.name, 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 2af63676275..36ae4e26d62 100644 --- a/plextraktsync/plex/PlexPlaylistCollection.py +++ b/plextraktsync/plex/PlexPlaylistCollection.py @@ -8,13 +8,16 @@ if TYPE_CHECKING: from plexapi.library import LibrarySection + from plextraktsync.plex.PlexApi import PlexApi + class PlexPlaylistCollection(UserDict): - def __init__(self, section: LibrarySection): + def __init__(self, plex: PlexApi, section: LibrarySection): super().__init__() + self.plex = plex self.section = section def __missing__(self, name: str): - self[name] = playlist = PlexPlaylist(self.section, name) + self[name] = playlist = PlexPlaylist(plex=self.plex, section=self.section, name=name) return playlist diff --git a/plextraktsync/trakt/TraktUserList.py b/plextraktsync/trakt/TraktUserList.py index 90d8bb596e7..d139a46374c 100644 --- a/plextraktsync/trakt/TraktUserList.py +++ b/plextraktsync/trakt/TraktUserList.py @@ -73,8 +73,9 @@ def plex_lists(self): PlexPlaylistCollection section = factory.plex_api.library_sections[1].section + plex = factory.plex_api - return PlexPlaylistCollection(section) + return PlexPlaylistCollection(plex=plex, section=section) @cached_property def plex_list(self):