diff --git a/plextraktsync/plex/PlexApi.py b/plextraktsync/plex/PlexApi.py index 0d484f5866..e0224fc6b6 100644 --- a/plextraktsync/plex/PlexApi.py +++ b/plextraktsync/plex/PlexApi.py @@ -146,16 +146,6 @@ def ratings(self): def rate(self, m: PlexMedia, rating: int | float | None): m.rate(rating) - def update_playlist(self, name: str, items: list[PlexMedia], description=None) -> bool: - """ - Updates playlist (creates if name missing) replacing contents with items[] - """ - from plextraktsync.plex.PlexPlaylist import PlexPlaylist - - playlist = PlexPlaylist(self.server, name) - - return playlist.update(items, description) - @flatten_list def history(self, m, device=False, account=False): try: diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 4c732d9aab..fbe1331914 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -53,7 +53,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, items: list[PlexMedia], description=None, section=None) -> bool: """ Updates playlist (creates if name missing) replacing contents with items[] """ @@ -62,7 +62,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.server.createPlaylist(self.name, items=items, smart=True, section=section) 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 @@ -79,7 +79,9 @@ def update(self, items: list[PlexMedia], description=None) -> bool: if self.same_list(items, playlist.items()): return updated - playlist.removeItems(playlist.items()) + if playlist.items(): + print(self.name, len(playlist.items())) + playlist.removeItems(playlist.items()) playlist.addItems(items) self.logger.debug(f"Updated '{self.name}' items") diff --git a/plextraktsync/sync/Sync.py b/plextraktsync/sync/Sync.py index 7d341577d4..6b68a85aa7 100644 --- a/plextraktsync/sync/Sync.py +++ b/plextraktsync/sync/Sync.py @@ -101,8 +101,10 @@ def sync(self, walker: Walker, dry_run=False): self.logger.warning("Running partial library sync. Liked lists won't update because it needs full library sync.") else: if not dry_run: + section = self.plex.library_sections[1] + print("section:", section) with measure_time("Updated liked list"): - trakt_lists.sync() + trakt_lists.sync(section=section.section) if walker.config.walk_watchlist and self.sync_wl: with measure_time("Updated watchlist"): diff --git a/plextraktsync/trakt/TraktUserListCollection.py b/plextraktsync/trakt/TraktUserListCollection.py index ba21a80b86..4ec4dbf588 100644 --- a/plextraktsync/trakt/TraktUserListCollection.py +++ b/plextraktsync/trakt/TraktUserListCollection.py @@ -36,9 +36,9 @@ def add_list(self, list_id: int, list_name: str): self.append(tl) return tl - def sync(self): + def sync(self, section=None): for tl in self: - updated = tl.plex_list.update(tl.plex_items_sorted) + updated = tl.plex_list.update(tl.plex_items_sorted, section=section) if not updated: continue self.logger.info(f"Plex list {tl.title_link} ({len(tl.plex_items)} items) updated", extra={"markup": True})