Skip to content

Commit

Permalink
Implement cleaning up playlist of watched items
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Aug 31, 2024
1 parent d8f9296 commit f6d8c0c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plextraktsync/commands/update_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from plextraktsync.decorators.coro import coro
from plextraktsync.factory import factory
from plextraktsync.plex.PlexPlaylist import PlexPlaylist

if TYPE_CHECKING:
from plextraktsync.plex.types import PlexPlayable
Expand All @@ -26,7 +27,18 @@ def format_title(p: PlexPlayable):
@coro
async def update_playlist(playlist: str, remove_watched: bool, dry_run: bool):
print = factory.print
pl = playlist
print(f"Update playlist: '{pl}'")
print(f"Update playlist: '{playlist}'")
print(f"Remove watched from playlist: {remove_watched}")
print(f"Dry run: {dry_run}")

pl = PlexPlaylist(factory.plex_server, playlist)
print(f"Playlist: {pl}")
items = pl.playlist.items().copy()
p: PlexPlayable
for p in items:
if remove_watched and p.isPlayed:
print(f"{'Remove' if not dry_run else 'Would remove'} from playlist: {format_title(p)}")
items.remove(p)
print(f"Update playlist: {len(pl)} -> {len(items)} items")
if not dry_run:
pl.update(items)

0 comments on commit f6d8c0c

Please sign in to comment.