feat(subsonic): apps can make, change and delete playlists (#8021)
release / web (push) Successful in 1m43s
release / go (push) Successful in 2m21s
release / govulncheck (push) Successful in 20s
release / integration (push) Failing after 4m31s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m44s
release / android (push) Canceled after 3m43s

createPlaylist makes a playlist, or with playlistId replaces its songs;
updatePlaylist renames it, sets its comment and visibility, removes songs
by the index the app was shown and adds songs; deletePlaylist deletes it.
A song index counts only the entries getPlaylist lists, so a hidden
entry ahead of it doesn't shift which song goes.

The playlist service gains ReplaceTracks and RemovePositions; the owner
and system-mix checks that each change repeated are one function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 10:17:15 -05:00
co-authored by Claude Opus 5.5
parent 3491cf4c58
commit df2095baae
7 changed files with 614 additions and 180 deletions
+38 -10
View File
@@ -153,22 +153,21 @@ func (h *pickHandlers) getPlaylist(w http.ResponseWriter, r *http.Request) {
WriteFail(w, r, ErrGeneric, "Playlist unavailable")
return
}
ids := make([]pgtype.UUID, 0, len(detail.Tracks))
for _, t := range detail.Tracks {
if t.TrackID != nil && !t.Unavailable {
ids = append(ids, *t.TrackID)
}
if detail.Kind == "system" && detail.SystemVariant != nil {
h.recall.remember(user.ID, r.URL.Query().Get("c"), *detail.SystemVariant)
}
q := dbq.New(h.pool)
songs, err := songsInOrder(r.Context(), q, ids)
h.writePlaylist(w, r, detail)
}
// writePlaylist answers with a playlist and the songs in it that an app can
// play, as getPlaylist does.
func (h *pickHandlers) writePlaylist(w http.ResponseWriter, r *http.Request, detail *playlists.PlaylistDetail) {
songs, _, err := shownEntries(r.Context(), dbq.New(h.pool), detail)
if err != nil {
h.logger.Error("subsonic: playlist songs", "err", err)
WriteFail(w, r, ErrGeneric, "Playlist unavailable")
return
}
if detail.Kind == "system" && detail.SystemVariant != nil {
h.recall.remember(user.ID, r.URL.Query().Get("c"), *detail.SystemVariant)
}
head := playlistRef(&detail.PlaylistRow)
head.SongCount = len(songs)
head.Duration = 0
@@ -181,6 +180,35 @@ func (h *pickHandlers) getPlaylist(w http.ResponseWriter, r *http.Request) {
})
}
// shownEntries returns the songs of a playlist that a Subsonic app is shown,
// in order, and each one's position in the playlist. An entry whose file is
// missing, or whose song has left the library, is not shown, so an app's
// song index and Minstrel's position differ once one is hidden.
func shownEntries(ctx context.Context, q *dbq.Queries, detail *playlists.PlaylistDetail) ([]SongRef, []int32, error) {
ids := make([]pgtype.UUID, 0, len(detail.Tracks))
candidates := make([]int32, 0, len(detail.Tracks))
for _, t := range detail.Tracks {
if t.TrackID != nil && !t.Unavailable {
ids = append(ids, *t.TrackID)
candidates = append(candidates, t.Position)
}
}
songs, err := songsInOrder(ctx, q, ids)
if err != nil {
return nil, nil, err
}
// songsInOrder drops every entry of an id it can't find and keeps the
// rest in order, so walking both lists pairs each song with its entry.
positions := make([]int32, 0, len(songs))
for i, j := 0, 0; i < len(ids) && j < len(songs); i++ {
if uuidToID(ids[i]) == songs[j].ID {
positions = append(positions, candidates[i])
j++
}
}
return songs, positions, nil
}
// songsInOrder looks up tracks by id and returns them as songs in the order
// of ids; an id with no track is skipped. One query each for the tracks,
// their albums, their artists and their gains.