Skip to content

Commit

Permalink
Try to figure section automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 13, 2024
1 parent aaf7c0e commit f784ca0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions plextraktsync/plex/PlexPlaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions plextraktsync/plex/PlexPlaylistCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion plextraktsync/trakt/TraktUserList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f784ca0

Please sign in to comment.