Implemented subtractive playlist editing

This commit is contained in:
patben8 committed 2026-10-22 09:58:57 +02:00
1 parent 1a28ad6102
commit 068e4da08b
7 files changed
+138 -4

No files matched your search

+23
View File
@@ -104,6 +104,7 @@ from .schemas import (
RenamePlaylist,
SaveResult,
AddEntries,
RemoveEntries,
MovePlaylist,
SetEntries,
SourceCandidate,
@@ -1473,6 +1474,28 @@ def add_entries(playlist_uuid: str, body: AddEntries) -> dict:
"duplicates": len(dupes), "count": n}
@app.post("/api/playlists/{playlist_uuid}/remove")
def remove_entries(playlist_uuid: str, body: RemoveEntries) -> dict:
"""Remove tracks from a playlist — EVERY occurrence of each — without the
caller holding its entry list (the track menu's Remove ▸ From playlist).
Other entries keep their order, including ones whose track is missing
from the collection. `tracks` = how many of the given tracks it held,
`removed` = entries dropped (more, where a track was there twice)."""
a = require_adapter()
current = a.playlist_entries(playlist_uuid)
if current is None:
raise HTTPException(404, f"Playlist not found: {playlist_uuid}")
gone = set(body.track_ids)
kept = [t for t in current if t not in gone]
held = len(gone & set(current))
removed = len(current) - len(kept)
n = len(current)
if removed and not body.dry_run:
n = a.set_playlist_entries(playlist_uuid, kept)
return {"status": "counted" if body.dry_run else "removed", "id": playlist_uuid,
"tracks": held, "removed": removed, "count": n}
@app.patch("/api/tracks")
def edit_track(body: EditTrack) -> dict:
"""Edit a single track's safe metadata fields (in-memory; persisted on save)."""
+6
View File
@@ -32,6 +32,12 @@ class AddEntries(BaseModel):
index: int | None = None
class RemoveEntries(BaseModel):
track_ids: list[str]
# Count what would go and change nothing — the confirm dialog's numbers.
dry_run: bool = False
class MovePlaylist(BaseModel):
node_id: str
parent_id: str | None = None # None = the top level