Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test smart playlist with items #1835

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions plextraktsync/plex/PlexApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions plextraktsync/plex/PlexPlaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
"""
Expand All @@ -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
Expand All @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion plextraktsync/sync/Sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
4 changes: 2 additions & 2 deletions plextraktsync/trakt/TraktUserListCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Loading