From 4712119a0ef7cd6ce3420d70bdb16599c07a7d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:38:58 +0200 Subject: [PATCH 1/7] Remove unused update_playlist from PlexApi --- plextraktsync/plex/PlexApi.py | 10 ---------- 1 file changed, 10 deletions(-) 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: From 9edcf057e441e1f921bdd95fa364fb5ab694c67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:41:35 +0200 Subject: [PATCH 2/7] Pass section to PlexPlaylist.update --- plextraktsync/plex/PlexPlaylist.py | 2 +- plextraktsync/trakt/TraktUserListCollection.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 4c732d9aab..6123872610 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[] """ 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}) From 7d32eef22b97dabf277f76a3c62cc39ecde7ad67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:41:46 +0200 Subject: [PATCH 3/7] Create smart playlist --- plextraktsync/plex/PlexPlaylist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 6123872610..41602c32f1 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -62,7 +62,7 @@ def update(self, items: list[PlexMedia], description=None, section=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 From 4701cfb8638b3cf9af7f65cf04c79d414816e55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:46:02 +0200 Subject: [PATCH 4/7] Add some random section for trakt lists --- plextraktsync/sync/Sync.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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"): From 0b39169bc5bd92821e4c8995ce9fbff6180796e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:47:07 +0200 Subject: [PATCH 5/7] Only remove items if has any --- plextraktsync/plex/PlexPlaylist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 41602c32f1..65eee101db 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -79,7 +79,8 @@ def update(self, items: list[PlexMedia], description=None, section=None) -> bool if self.same_list(items, playlist.items()): return updated - playlist.removeItems(playlist.items()) + if playlist.items(): + playlist.removeItems(playlist.items()) playlist.addItems(items) self.logger.debug(f"Updated '{self.name}' items") From 20403fbb5178299c327c910904be0bdbef98b77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Feb 2024 18:48:43 +0200 Subject: [PATCH 6/7] Debug list content --- plextraktsync/plex/PlexPlaylist.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index 65eee101db..e3d8b43c21 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -80,6 +80,7 @@ def update(self, items: list[PlexMedia], description=None, section=None) -> bool return updated if playlist.items(): + print(self.name, playlist.items()) playlist.removeItems(playlist.items()) playlist.addItems(items) self.logger.debug(f"Updated '{self.name}' items") From 6f19c9aca604b09ad36f7446092e30e495b12d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 26 Feb 2024 23:22:44 +0200 Subject: [PATCH 7/7] Print less noise --- plextraktsync/plex/PlexPlaylist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/plex/PlexPlaylist.py b/plextraktsync/plex/PlexPlaylist.py index e3d8b43c21..fbe1331914 100644 --- a/plextraktsync/plex/PlexPlaylist.py +++ b/plextraktsync/plex/PlexPlaylist.py @@ -80,7 +80,7 @@ def update(self, items: list[PlexMedia], description=None, section=None) -> bool return updated if playlist.items(): - print(self.name, playlist.items()) + print(self.name, len(playlist.items())) playlist.removeItems(playlist.items()) playlist.addItems(items) self.logger.debug(f"Updated '{self.name}' items")