feat(subsonic): an artist's top songs, and the play queue carried between devices
release / go (push) Successful in 1m50s
release / web (push) Successful in 1m14s
release / govulncheck (push) Successful in 44s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 6m15s
release / Build signed APK (push) Successful in 7m51s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped

getTopSongs ranks the named artist's songs by how often they were played
through on this server, then by likes, then in album order, so an artist
nobody has played yet still has songs to offer. Missing files and the
listener's quarantined songs are left out.

savePlayQueue keeps one queue per listener: the songs in order, the one
playing, how far into it, and the app that saved it. getPlayQueue gives it
back to that listener only; a song no longer in the library drops out.
Saving no songs clears it. The queue lives in a new play_queues table,
which backups carry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 17:03:29 -05:00
co-authored by Claude Opus 5.5
parent 8731e9695a
commit b801f81058
15 changed files with 568 additions and 2 deletions
+50
View File
@@ -2,6 +2,7 @@ package subsonic
import (
"net/http"
"strings"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
)
@@ -92,3 +93,52 @@ func (b *browseHandlers) getSongsByGenre(w http.ResponseWriter, r *http.Request)
SongsByGenre: SongsByGenreContainer{Songs: songs},
})
}
type TopSongsContainer struct {
Songs []SongRef `json:"song" xml:"song"`
}
type TopSongsResponse struct {
Envelope
TopSongs TopSongsContainer `json:"topSongs" xml:"topSongs"`
}
// getTopSongs returns an artist's most played songs on this server, then the
// most liked, then the rest in album order (ListTopTracksForArtistName). The
// app names the artist rather than giving an id. count defaults to 50 and is
// at most 500.
func (b *browseHandlers) getTopSongs(w http.ResponseWriter, r *http.Request) {
params := r.URL.Query()
artist := strings.TrimSpace(params.Get("artist"))
if artist == "" {
WriteFail(w, r, ErrMissingParameter, "Missing required parameter: artist")
return
}
user, ok := UserFromContext(r.Context())
if !ok {
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
return
}
count := clampInt(atoiDefault(params.Get("count"), 50), 1, 500)
q := dbq.New(b.pool)
rows, err := q.ListTopTracksForArtistName(r.Context(), dbq.ListTopTracksForArtistNameParams{
ArtistName: artist, UserID: user.ID, Lim: int32(count),
})
if err != nil {
WriteFail(w, r, ErrGeneric, "Failed to load top songs")
return
}
tracks := make([]dbq.Track, len(rows))
for i, row := range rows {
tracks[i] = row.Track
}
songs, err := songRefs(r.Context(), q, tracks)
if err != nil {
WriteFail(w, r, ErrGeneric, "Failed to load top songs")
return
}
Write(w, r, TopSongsResponse{
Envelope: NewEnvelope("ok"),
TopSongs: TopSongsContainer{Songs: songs},
})
}