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
+19
View File
@@ -204,6 +204,25 @@ check("an index past the end appends", after[-1] == more[1])
check("capabilities say Traktor holds duplicates",
client.get("/api/capabilities").json()["playlists"]["duplicates"] is True)
before = [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()]
outsider = next(t["id"] for t in client.get("/api/tracks", params={"limit": 50}).json()["items"]
if t["id"] not in before)
picked = [first[0], rest[0], outsider] # first[0] is in there twice
r = client.post(f"/api/playlists/{target}/remove",
json={"track_ids": picked, "dry_run": True}).json()
check("a dry-run remove counts tracks held and entries (both copies) and changes nothing",
r["tracks"] == 2 and r["removed"] == 3
and [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()] == before)
r = client.post(f"/api/playlists/{target}/remove", json={"track_ids": picked}).json()
after = [t["id"] for t in client.get(f"/api/playlists/{target}/tracks").json()]
check("remove drops every copy and keeps the rest in order",
r["removed"] == 3 and r["count"] == len(before) - 3
and after == [t for t in before if t not in picked])
r = client.post(f"/api/playlists/{target}/remove", json={"track_ids": [outsider]}).json()
check("removing tracks it does not hold changes nothing", r["removed"] == 0 and r["count"] == len(after))
check("remove from an unknown playlist is a 404",
client.post("/api/playlists/nope/remove", json={"track_ids": picked}).status_code == 404)
box = client.post("/api/playlists/folders", json={"name": "Konduktor Drop Box"}).json()["id"]
r = client.post("/api/playlists/move", json={"node_id": target, "parent_id": box, "index": 0})
check("move answers the playlist's id", r.status_code == 200 and r.json()["id"] == target)