feat(subsonic): playlists and daily mixes, the weighted shuffle, and radio
release / go (push) Successful in 2m0s
release / web (push) Successful in 1m23s
release / govulncheck (push) Successful in 20s
release / integration (push) Failing after 4m23s
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 2m8s
release / android (push) Canceled after 3m38s
release / go (push) Successful in 2m0s
release / web (push) Successful in 1m23s
release / govulncheck (push) Successful in 20s
release / integration (push) Failing after 4m23s
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 2m8s
release / android (push) Canceled after 3m38s
Subsonic apps now get what Minstrel picks, not only what it holds: - getPlaylists lists the listener's daily mixes first, then their own playlists, then other people's public ones; getPlaylist returns the playable songs in order, as <entry> elements in XML. - getRandomSongs answers with the weighted shuffle (likes up, skips down, the last hour's plays out), narrowed by genre and release year. - getSimilarSongs and getSimilarSongs2 answer with Minstrel's radio, seeded from a song, or from a random song of an album or artist. Radio's selection moves out of the /api/radio handler into recommendation.Picker, built by recsettings.Service.Picker, so the web and Android apps and the Subsonic apps pick through one piece of code and one tuning. SongRef loses its XMLName so the field holding it names the element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,459 @@
|
||||
package subsonic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
||||
)
|
||||
|
||||
// pickHandlers serve what Minstrel chooses for the listener: their playlists
|
||||
// and daily mixes, the weighted shuffle, and radio. They answer from the same
|
||||
// code as Minstrel's own apps, so a Subsonic app gets the same picks.
|
||||
type pickHandlers struct {
|
||||
pool *pgxpool.Pool
|
||||
picker *recommendation.Picker
|
||||
playlists *playlists.Service
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
// ---- getPlaylists / getPlaylist ----
|
||||
|
||||
// PlaylistRef is one playlist in getPlaylists, and the head of getPlaylist.
|
||||
type PlaylistRef struct {
|
||||
ID string `json:"id" xml:"id,attr"`
|
||||
Name string `json:"name" xml:"name,attr"`
|
||||
Comment string `json:"comment,omitempty" xml:"comment,attr,omitempty"`
|
||||
Owner string `json:"owner,omitempty" xml:"owner,attr,omitempty"`
|
||||
Public bool `json:"public" xml:"public,attr"`
|
||||
SongCount int `json:"songCount" xml:"songCount,attr"`
|
||||
Duration int `json:"duration" xml:"duration,attr"`
|
||||
Created string `json:"created,omitempty" xml:"created,attr,omitempty"`
|
||||
Changed string `json:"changed,omitempty" xml:"changed,attr,omitempty"`
|
||||
CoverArt string `json:"coverArt,omitempty" xml:"coverArt,attr,omitempty"`
|
||||
}
|
||||
|
||||
type PlaylistsContainer struct {
|
||||
Playlists []PlaylistRef `json:"playlist" xml:"playlist"`
|
||||
}
|
||||
|
||||
type PlaylistsResponse struct {
|
||||
Envelope
|
||||
Playlists PlaylistsContainer `json:"playlists" xml:"playlists"`
|
||||
}
|
||||
|
||||
// PlaylistWithSongs is getPlaylist's body: the playlist and its songs.
|
||||
type PlaylistWithSongs struct {
|
||||
PlaylistRef
|
||||
Entries []SongRef `json:"entry" xml:"entry"`
|
||||
}
|
||||
|
||||
type PlaylistResponse struct {
|
||||
Envelope
|
||||
Playlist PlaylistWithSongs `json:"playlist" xml:"playlist"`
|
||||
}
|
||||
|
||||
// playlistRef converts a playlist row. Its cover is the first album cover in
|
||||
// it: getCoverArt answers for an album id, and a Subsonic app shows that.
|
||||
func playlistRef(p *playlists.PlaylistRow) PlaylistRef {
|
||||
ref := PlaylistRef{
|
||||
ID: uuidToID(p.ID),
|
||||
Name: p.Name,
|
||||
Comment: p.Description,
|
||||
Owner: p.OwnerUsername,
|
||||
Public: p.IsPublic,
|
||||
SongCount: int(p.TrackCount),
|
||||
Duration: int(p.DurationSec),
|
||||
Created: timestamptzToRFC3339(p.CreatedAt),
|
||||
Changed: timestamptzToRFC3339(p.UpdatedAt),
|
||||
}
|
||||
if len(p.CoverAlbumIDs) > 0 {
|
||||
ref.CoverArt = uuidToID(p.CoverAlbumIDs[0])
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
||||
// getPlaylists lists the caller's daily mixes first, then their own
|
||||
// playlists, then other people's public ones. The mixes lead because they are
|
||||
// what Minstrel makes fresh each day; within each group the service's order
|
||||
// (most recently changed first) stands.
|
||||
func (h *pickHandlers) getPlaylists(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
return
|
||||
}
|
||||
rows, err := h.playlists.List(r.Context(), user.ID)
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: list playlists", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Playlists unavailable")
|
||||
return
|
||||
}
|
||||
var mixes, own, others []PlaylistRef
|
||||
for i := range rows {
|
||||
p := &rows[i]
|
||||
switch {
|
||||
case p.UserID != user.ID:
|
||||
others = append(others, playlistRef(p))
|
||||
case p.Kind == "system":
|
||||
mixes = append(mixes, playlistRef(p))
|
||||
default:
|
||||
own = append(own, playlistRef(p))
|
||||
}
|
||||
}
|
||||
out := make([]PlaylistRef, 0, len(rows))
|
||||
out = append(append(append(out, mixes...), own...), others...)
|
||||
Write(w, r, PlaylistsResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
Playlists: PlaylistsContainer{Playlists: out},
|
||||
})
|
||||
}
|
||||
|
||||
// getPlaylist returns one playlist and its songs in playlist order. A song
|
||||
// whose file is missing, or that has left the library, keeps its place in
|
||||
// Minstrel but is not listed here, since a Subsonic app would try to play it.
|
||||
func (h *pickHandlers) getPlaylist(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
return
|
||||
}
|
||||
raw := r.URL.Query().Get("id")
|
||||
if raw == "" {
|
||||
WriteFail(w, r, ErrMissingParameter, "Missing required parameter: id")
|
||||
return
|
||||
}
|
||||
id, ok := parseUUID(raw)
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrDataNotFound, "Playlist not found")
|
||||
return
|
||||
}
|
||||
detail, err := h.playlists.Get(r.Context(), user.ID, id)
|
||||
if err != nil {
|
||||
// Someone else's private playlist reads as absent, as it does in
|
||||
// the list.
|
||||
if errors.Is(err, playlists.ErrNotFound) || errors.Is(err, playlists.ErrForbidden) {
|
||||
WriteFail(w, r, ErrDataNotFound, "Playlist not found")
|
||||
return
|
||||
}
|
||||
h.logger.Error("subsonic: get playlist", "err", err)
|
||||
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)
|
||||
}
|
||||
}
|
||||
q := dbq.New(h.pool)
|
||||
songs, err := songsInOrder(r.Context(), q, ids)
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: playlist songs", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Playlist unavailable")
|
||||
return
|
||||
}
|
||||
head := playlistRef(&detail.PlaylistRow)
|
||||
head.SongCount = len(songs)
|
||||
head.Duration = 0
|
||||
for _, s := range songs {
|
||||
head.Duration += s.Duration
|
||||
}
|
||||
Write(w, r, PlaylistResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
Playlist: PlaylistWithSongs{PlaylistRef: head, Entries: songs},
|
||||
})
|
||||
}
|
||||
|
||||
// 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.
|
||||
func songsInOrder(ctx context.Context, q *dbq.Queries, ids []pgtype.UUID) ([]SongRef, error) {
|
||||
if len(ids) == 0 {
|
||||
return []SongRef{}, nil
|
||||
}
|
||||
rows, err := q.GetTracksByIDs(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
byID := make(map[pgtype.UUID]dbq.Track, len(rows))
|
||||
for _, t := range rows {
|
||||
byID[t.ID] = t
|
||||
}
|
||||
tracks := make([]dbq.Track, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if t, ok := byID[id]; ok {
|
||||
tracks = append(tracks, t)
|
||||
}
|
||||
}
|
||||
return songRefs(ctx, q, tracks)
|
||||
}
|
||||
|
||||
// songRefs converts tracks to songs, keeping their order.
|
||||
func songRefs(ctx context.Context, q *dbq.Queries, tracks []dbq.Track) ([]SongRef, error) {
|
||||
albumTitles, artistNames, err := songParents(ctx, q, tracks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gains := replayGains(ctx, q, tracks)
|
||||
out := make([]SongRef, 0, len(tracks))
|
||||
for _, t := range tracks {
|
||||
out = append(out, songRef(t, albumTitles[t.AlbumID], artistNames[t.ArtistID], gains[t.ID]))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func candidateTracks(picks []recommendation.Candidate) []dbq.Track {
|
||||
out := make([]dbq.Track, len(picks))
|
||||
for i, p := range picks {
|
||||
out[i] = p.Track
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ---- getRandomSongs ----
|
||||
|
||||
type RandomSongsContainer struct {
|
||||
Songs []SongRef `json:"song" xml:"song"`
|
||||
}
|
||||
|
||||
type RandomSongsResponse struct {
|
||||
Envelope
|
||||
RandomSongs RandomSongsContainer `json:"randomSongs" xml:"randomSongs"`
|
||||
}
|
||||
|
||||
// getRandomSongs is a Subsonic app's shuffle. Minstrel answers with its
|
||||
// weighted shuffle, the one its own apps use: songs the listener likes come
|
||||
// up more, songs they skip less, and songs heard in the last hour not at all.
|
||||
// size defaults to 10, as the Subsonic API defines it, and is capped at the
|
||||
// server's radio length. genre, fromYear and toYear narrow the library first.
|
||||
func (h *pickHandlers) getRandomSongs(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
return
|
||||
}
|
||||
params := r.URL.Query()
|
||||
size := clampInt(atoiDefault(params.Get("size"), 10), 1, 500)
|
||||
q := dbq.New(h.pool)
|
||||
keep, err := randomSongsFilter(r.Context(), q, params.Get("genre"), params.Get("fromYear"), params.Get("toYear"))
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: random songs filter", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Shuffle unavailable")
|
||||
return
|
||||
}
|
||||
picks, err := h.picker.Shuffle(r.Context(), q, user.ID, size, keep)
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: random songs", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Shuffle unavailable")
|
||||
return
|
||||
}
|
||||
songs, err := songRefs(r.Context(), q, candidateTracks(picks))
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: random songs", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Shuffle unavailable")
|
||||
return
|
||||
}
|
||||
Write(w, r, RandomSongsResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
RandomSongs: RandomSongsContainer{Songs: songs},
|
||||
})
|
||||
}
|
||||
|
||||
// randomSongsFilter builds getRandomSongs' narrowing, or nil when nothing
|
||||
// narrows. A genre matches each of a track's genres, split on ; and , the way
|
||||
// getAlbumList2 byGenre splits them, so "Rock" reaches a track tagged
|
||||
// "Rock;Pop". The years are an album's release year, inclusive; either end
|
||||
// may be left open.
|
||||
func randomSongsFilter(ctx context.Context, q *dbq.Queries, genre, fromYear, toYear string) (func(dbq.Track) bool, error) {
|
||||
genre = strings.TrimSpace(genre)
|
||||
var albums map[pgtype.UUID]bool
|
||||
if fromYear != "" || toYear != "" {
|
||||
from, ferr := strconv.Atoi(fromYear)
|
||||
if ferr != nil {
|
||||
from = 0
|
||||
}
|
||||
to, terr := strconv.Atoi(toYear)
|
||||
if terr != nil {
|
||||
to = 9999
|
||||
}
|
||||
inRange, err := q.ListAlbumsByYearOrdered(ctx, dbq.ListAlbumsByYearOrderedParams{
|
||||
FromYear: int32(from), ToYear: int32(to), Lim: 1 << 30, Off: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
albums = make(map[pgtype.UUID]bool, len(inRange))
|
||||
for _, a := range inRange {
|
||||
albums[a.ID] = true
|
||||
}
|
||||
}
|
||||
if genre == "" && albums == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return func(t dbq.Track) bool {
|
||||
if albums != nil && !albums[t.AlbumID] {
|
||||
return false
|
||||
}
|
||||
return genre == "" || hasGenre(t.Genre, genre)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func hasGenre(tagged *string, genre string) bool {
|
||||
if tagged == nil {
|
||||
return false
|
||||
}
|
||||
for _, g := range strings.FieldsFunc(*tagged, func(r rune) bool { return r == ';' || r == ',' }) {
|
||||
if strings.EqualFold(strings.TrimSpace(g), genre) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ---- getSimilarSongs / getSimilarSongs2 ----
|
||||
|
||||
type SimilarSongsContainer struct {
|
||||
Songs []SongRef `json:"song" xml:"song"`
|
||||
}
|
||||
|
||||
type SimilarSongsResponse struct {
|
||||
Envelope
|
||||
SimilarSongs SimilarSongsContainer `json:"similarSongs" xml:"similarSongs"`
|
||||
}
|
||||
|
||||
type SimilarSongs2Response struct {
|
||||
Envelope
|
||||
SimilarSongs2 SimilarSongsContainer `json:"similarSongs2" xml:"similarSongs2"`
|
||||
}
|
||||
|
||||
// getSimilarSongs is a Subsonic app's radio, or "instant mix". Minstrel
|
||||
// answers with its own radio. id may be a song, an album or an artist; an
|
||||
// album or artist seeds the radio from one of its songs, picked at random.
|
||||
// count defaults to 50, as the Subsonic API defines it. The seed song is not
|
||||
// in the answer: the app plays it already.
|
||||
func (h *pickHandlers) getSimilarSongs(w http.ResponseWriter, r *http.Request) {
|
||||
songs, ok := h.similar(w, r, true)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
Write(w, r, SimilarSongsResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
SimilarSongs: SimilarSongsContainer{Songs: songs},
|
||||
})
|
||||
}
|
||||
|
||||
// getSimilarSongs2 is getSimilarSongs for an artist id, as the ID3 browse
|
||||
// methods give.
|
||||
func (h *pickHandlers) getSimilarSongs2(w http.ResponseWriter, r *http.Request) {
|
||||
songs, ok := h.similar(w, r, false)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
Write(w, r, SimilarSongs2Response{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
SimilarSongs2: SimilarSongsContainer{Songs: songs},
|
||||
})
|
||||
}
|
||||
|
||||
// similar runs radio for the request's id. anyKind also accepts a song or an
|
||||
// album id; otherwise only an artist id is a seed. It writes the failure
|
||||
// itself and reports false when there is nothing to answer.
|
||||
func (h *pickHandlers) similar(w http.ResponseWriter, r *http.Request, anyKind bool) ([]SongRef, bool) {
|
||||
user, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
return nil, false
|
||||
}
|
||||
params := r.URL.Query()
|
||||
raw := params.Get("id")
|
||||
if raw == "" {
|
||||
WriteFail(w, r, ErrMissingParameter, "Missing required parameter: id")
|
||||
return nil, false
|
||||
}
|
||||
id, ok := parseUUID(raw)
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrDataNotFound, "Not found")
|
||||
return nil, false
|
||||
}
|
||||
count := clampInt(atoiDefault(params.Get("count"), 50), 1, 500)
|
||||
q := dbq.New(h.pool)
|
||||
seed, found, err := radioSeed(r.Context(), q, user.ID, id, anyKind)
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: similar songs seed", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Radio unavailable")
|
||||
return nil, false
|
||||
}
|
||||
if !found {
|
||||
WriteFail(w, r, ErrDataNotFound, "Not found")
|
||||
return nil, false
|
||||
}
|
||||
picks, err := h.picker.Radio(r.Context(), q, user.ID, seed, count, nil)
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: similar songs", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Radio unavailable")
|
||||
return nil, false
|
||||
}
|
||||
songs, err := songRefs(r.Context(), q, candidateTracks(picks))
|
||||
if err != nil {
|
||||
h.logger.Error("subsonic: similar songs", "err", err)
|
||||
WriteFail(w, r, ErrGeneric, "Radio unavailable")
|
||||
return nil, false
|
||||
}
|
||||
return songs, true
|
||||
}
|
||||
|
||||
// radioSeed finds the song a radio starts from. A song id is its own seed; an
|
||||
// album or an artist gives one of its playable songs at random, so asking
|
||||
// twice for the same artist need not start from the same song.
|
||||
func radioSeed(ctx context.Context, q *dbq.Queries, userID, id pgtype.UUID, anyKind bool) (pgtype.UUID, bool, error) {
|
||||
if anyKind {
|
||||
if t, err := q.GetTrackByID(ctx, id); err == nil && !t.MissingSince.Valid {
|
||||
return t.ID, true, nil
|
||||
}
|
||||
if _, err := q.GetAlbumByID(ctx, id); err == nil {
|
||||
tracks, err := q.ListTracksByAlbum(ctx, dbq.ListTracksByAlbumParams{AlbumID: id, UserID: userID})
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, false, err
|
||||
}
|
||||
ids := make([]pgtype.UUID, 0, len(tracks))
|
||||
for _, t := range tracks {
|
||||
if !t.MissingSince.Valid {
|
||||
ids = append(ids, t.ID)
|
||||
}
|
||||
}
|
||||
return pickOne(ids)
|
||||
}
|
||||
}
|
||||
if _, err := q.GetArtistByID(ctx, id); err != nil {
|
||||
return pgtype.UUID{}, false, nil
|
||||
}
|
||||
rows, err := q.ListArtistTracksForUser(ctx, dbq.ListArtistTracksForUserParams{ArtistID: id, UserID: userID})
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, false, err
|
||||
}
|
||||
ids := make([]pgtype.UUID, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
if !row.Track.MissingSince.Valid {
|
||||
ids = append(ids, row.Track.ID)
|
||||
}
|
||||
}
|
||||
return pickOne(ids)
|
||||
}
|
||||
|
||||
func pickOne(ids []pgtype.UUID) (pgtype.UUID, bool, error) {
|
||||
if len(ids) == 0 {
|
||||
return pgtype.UUID{}, false, nil
|
||||
}
|
||||
return ids[rand.IntN(len(ids))], true, nil
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
package subsonic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recsettings"
|
||||
)
|
||||
|
||||
func TestHasGenre_SplitsTheTagLikeByGenre(t *testing.T) {
|
||||
tag := func(s string) *string { return &s }
|
||||
cases := []struct {
|
||||
tagged *string
|
||||
genre string
|
||||
want bool
|
||||
}{
|
||||
{tag("Jazz"), "Jazz", true},
|
||||
{tag("Rock;Jazz"), "jazz", true},
|
||||
{tag("Rock, Jazz"), "Jazz", true},
|
||||
{tag("Jazz Fusion"), "Jazz", false},
|
||||
{tag(""), "Jazz", false},
|
||||
{nil, "Jazz", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := hasGenre(c.tagged, c.genre); got != c.want {
|
||||
t.Errorf("hasGenre(%v, %q) = %v, want %v", c.tagged, c.genre, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// picksFixture is a small library and a listener with playlists:
|
||||
//
|
||||
// Lantern Hours (1999): Dusk (Jazz), Ember (Jazz;Funk), Flint (Rock)
|
||||
// Paper Boats (2012): Gale (Rock), Harbour (Jazz), Inlet (Rock)
|
||||
// Gone Tide (2012): Jetty (Jazz), whose file is missing
|
||||
//
|
||||
// Ember is quarantined by the listener, and Flint was played ten minutes
|
||||
// ago, so neither is a shuffle or radio pick.
|
||||
type picksFixture struct {
|
||||
pool *pgxpool.Pool
|
||||
user dbq.User
|
||||
other dbq.User
|
||||
tracks map[string]dbq.Track
|
||||
albums map[string]dbq.Album
|
||||
artist dbq.Artist
|
||||
}
|
||||
|
||||
func seedPicks(t *testing.T) picksFixture {
|
||||
t.Helper()
|
||||
if testing.Short() {
|
||||
t.Skip("skipping in -short mode")
|
||||
}
|
||||
dsn := os.Getenv("MINSTREL_TEST_DATABASE_URL")
|
||||
if dsn == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
}
|
||||
if err := db.Migrate(dsn, slog.New(slog.NewTextHandler(io.Discard, nil))); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
pool, err := pgxpool.New(context.Background(), dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("pool: %v", err)
|
||||
}
|
||||
t.Cleanup(pool.Close)
|
||||
dbtest.ResetDB(t, pool)
|
||||
|
||||
ctx := context.Background()
|
||||
q := dbq.New(pool)
|
||||
f := picksFixture{pool: pool, tracks: map[string]dbq.Track{}, albums: map[string]dbq.Album{}}
|
||||
if f.user, err = q.CreateUser(ctx, dbq.CreateUserParams{
|
||||
Username: dbtest.TestUserPrefix + "listener", PasswordHash: "x", ApiTokenHash: "x",
|
||||
}); err != nil {
|
||||
t.Fatalf("create user: %v", err)
|
||||
}
|
||||
if f.other, err = q.CreateUser(ctx, dbq.CreateUserParams{
|
||||
Username: dbtest.TestUserPrefix + "other", PasswordHash: "x", ApiTokenHash: "y",
|
||||
}); err != nil {
|
||||
t.Fatalf("create other: %v", err)
|
||||
}
|
||||
if f.artist, err = q.UpsertArtist(ctx, dbq.UpsertArtistParams{Name: "Tin Orchard", SortName: "Tin Orchard"}); err != nil {
|
||||
t.Fatalf("artist: %v", err)
|
||||
}
|
||||
albums := []struct {
|
||||
title string
|
||||
year int
|
||||
songs [][2]string // title, genre
|
||||
}{
|
||||
{"Lantern Hours", 1999, [][2]string{{"Dusk", "Jazz"}, {"Ember", "Jazz;Funk"}, {"Flint", "Rock"}}},
|
||||
{"Paper Boats", 2012, [][2]string{{"Gale", "Rock"}, {"Harbour", "Jazz"}, {"Inlet", "Rock"}}},
|
||||
{"Gone Tide", 2012, [][2]string{{"Jetty", "Jazz"}}},
|
||||
}
|
||||
for _, a := range albums {
|
||||
al, err := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: a.title, SortTitle: a.title, ArtistID: f.artist.ID})
|
||||
if err != nil {
|
||||
t.Fatalf("album %s: %v", a.title, err)
|
||||
}
|
||||
if _, err := pool.Exec(ctx, `UPDATE albums SET release_date = make_date($2::int, 6, 1) WHERE id = $1`, al.ID, a.year); err != nil {
|
||||
t.Fatalf("release date: %v", err)
|
||||
}
|
||||
f.albums[a.title] = al
|
||||
for i, s := range a.songs {
|
||||
genre := s[1]
|
||||
n := int32(i + 1)
|
||||
tr, err := q.UpsertTrack(ctx, dbq.UpsertTrackParams{
|
||||
Title: s[0], AlbumID: al.ID, ArtistID: f.artist.ID, Genre: &genre, TrackNumber: &n,
|
||||
FilePath: "/tmp/picks-" + s[0] + ".flac", DurationMs: 200_000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("track %s: %v", s[0], err)
|
||||
}
|
||||
f.tracks[s[0]] = tr
|
||||
}
|
||||
}
|
||||
f.exec(t, `UPDATE tracks SET missing_since = now() WHERE id = $1`, f.tracks["Jetty"].ID)
|
||||
f.exec(t, `INSERT INTO quarantine (user_id, track_id, reason) VALUES ($1, $2, 'bad_rip')`, f.user.ID, f.tracks["Ember"].ID)
|
||||
var session pgtype.UUID
|
||||
if err := pool.QueryRow(ctx, `INSERT INTO play_sessions (user_id, started_at, last_event_at, client_id)
|
||||
VALUES ($1, now() - interval '10 minutes', now() - interval '10 minutes', 'picks-test') RETURNING id`,
|
||||
f.user.ID).Scan(&session); err != nil {
|
||||
t.Fatalf("play session: %v", err)
|
||||
}
|
||||
f.exec(t, `INSERT INTO play_events (user_id, track_id, session_id, started_at) VALUES ($1, $2, $3, now() - interval '10 minutes')`,
|
||||
f.user.ID, f.tracks["Flint"].ID, session)
|
||||
return f
|
||||
}
|
||||
|
||||
func (f picksFixture) exec(t *testing.T, sql string, args ...any) {
|
||||
t.Helper()
|
||||
if _, err := f.pool.Exec(context.Background(), sql, args...); err != nil {
|
||||
t.Fatalf("%s: %v", sql, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (f picksFixture) handlers() *pickHandlers {
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
return &pickHandlers{
|
||||
pool: f.pool,
|
||||
// A nil tuning service scores with the shipped radio weights.
|
||||
picker: (*recsettings.Service)(nil).Picker(recsettings.PickerConfig{
|
||||
RecentlyPlayedHours: 1, MaxLength: 200, Rand: rand.Float64, Logger: logger,
|
||||
}),
|
||||
// Listing and reading playlists touch no collage files, so no data
|
||||
// directory is needed.
|
||||
playlists: playlists.NewService(f.pool, logger, ""),
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// call runs a handler as user and decodes the JSON body into out. It returns
|
||||
// the Subsonic error code, 0 on success.
|
||||
func call(t *testing.T, h func(http.ResponseWriter, *http.Request), user dbq.User, query string, out any) int {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
h(w, httptest.NewRequest(http.MethodGet, "/rest/x?f=json&"+query, nil).
|
||||
WithContext(context.WithValue(context.Background(), userCtxKey, user)))
|
||||
var env struct {
|
||||
Response json.RawMessage `json:"subsonic-response"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &env); err != nil {
|
||||
t.Fatalf("decode: %v body=%s", err, w.Body.String())
|
||||
}
|
||||
var status struct {
|
||||
Status string `json:"status"`
|
||||
Error *Error `json:"error"`
|
||||
}
|
||||
if err := json.Unmarshal(env.Response, &status); err != nil {
|
||||
t.Fatalf("decode status: %v", err)
|
||||
}
|
||||
if status.Error != nil {
|
||||
return status.Error.Code
|
||||
}
|
||||
if status.Status != "ok" {
|
||||
t.Fatalf("status %q, body=%s", status.Status, w.Body.String())
|
||||
}
|
||||
if out != nil {
|
||||
if err := json.Unmarshal(env.Response, out); err != nil {
|
||||
t.Fatalf("decode body: %v", err)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func titles(songs []SongRef) []string {
|
||||
out := make([]string, len(songs))
|
||||
for i, s := range songs {
|
||||
out[i] = s.Title
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (f picksFixture) randomSongs(t *testing.T, query string) []string {
|
||||
t.Helper()
|
||||
var got struct {
|
||||
RandomSongs RandomSongsContainer `json:"randomSongs"`
|
||||
}
|
||||
if code := call(t, f.handlers().getRandomSongs, f.user, query, &got); code != 0 {
|
||||
t.Fatalf("getRandomSongs %s: error %d", query, code)
|
||||
}
|
||||
return titles(got.RandomSongs.Songs)
|
||||
}
|
||||
|
||||
// The shuffle is the whole playable library, less what the listener has
|
||||
// quarantined and what they heard in the last hour.
|
||||
func TestGetRandomSongs_IsTheWeightedShuffleOfThePlayableLibrary(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
got := f.randomSongs(t, "size=50")
|
||||
slices.Sort(got)
|
||||
if want := []string{"Dusk", "Gale", "Harbour", "Inlet"}; !slices.Equal(got, want) {
|
||||
t.Errorf("songs = %v, want %v", got, want)
|
||||
}
|
||||
if got := f.randomSongs(t, "size=2"); len(got) != 2 || got[0] == got[1] {
|
||||
t.Errorf("size=2 = %v, want two different songs", got)
|
||||
}
|
||||
if got := f.randomSongs(t, ""); len(got) != 4 {
|
||||
t.Errorf("no size = %v, want every playable song (fewer than the default of 10)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRandomSongs_NarrowsByGenreAndYear(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
got := f.randomSongs(t, "size=50&genre=jazz")
|
||||
slices.Sort(got)
|
||||
if want := []string{"Dusk", "Harbour"}; !slices.Equal(got, want) {
|
||||
t.Errorf("genre=jazz = %v, want %v", got, want)
|
||||
}
|
||||
got = f.randomSongs(t, "size=50&fromYear=2000")
|
||||
slices.Sort(got)
|
||||
if want := []string{"Gale", "Harbour", "Inlet"}; !slices.Equal(got, want) {
|
||||
t.Errorf("fromYear=2000 = %v, want %v", got, want)
|
||||
}
|
||||
if got := f.randomSongs(t, "size=50&toYear=2000&genre=Rock"); len(got) != 0 {
|
||||
t.Errorf("rock before 2000 = %v, want none (Flint was just played)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func (f picksFixture) similar(t *testing.T, method func(http.ResponseWriter, *http.Request), key, id string) ([]string, int) {
|
||||
t.Helper()
|
||||
var got map[string]SimilarSongsContainer
|
||||
code := call(t, method, f.user, "count=10&id="+id, &got)
|
||||
return titles(got[key].Songs), code
|
||||
}
|
||||
|
||||
// Radio from a song, an album or an artist: every pick is playable, and the
|
||||
// seed song is not repeated back.
|
||||
func TestGetSimilarSongs_IsRadioFromASongAlbumOrArtist(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
h := f.handlers()
|
||||
unplayable := []string{"Ember", "Flint", "Jetty"}
|
||||
check := func(name string, got []string, code int, seed string) {
|
||||
t.Helper()
|
||||
if code != 0 {
|
||||
t.Fatalf("%s: error %d", name, code)
|
||||
}
|
||||
if len(got) == 0 {
|
||||
t.Fatalf("%s: no songs", name)
|
||||
}
|
||||
for _, s := range got {
|
||||
if slices.Contains(unplayable, s) || s == seed {
|
||||
t.Errorf("%s: %q among %v", name, s, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
got, code := f.similar(t, h.getSimilarSongs, "similarSongs", uuidToID(f.tracks["Dusk"].ID))
|
||||
check("song", got, code, "Dusk")
|
||||
got, code = f.similar(t, h.getSimilarSongs, "similarSongs", uuidToID(f.albums["Paper Boats"].ID))
|
||||
check("album", got, code, "")
|
||||
got, code = f.similar(t, h.getSimilarSongs2, "similarSongs2", uuidToID(f.artist.ID))
|
||||
check("artist", got, code, "")
|
||||
|
||||
// getSimilarSongs2 takes only an artist; a missing song is no seed.
|
||||
if _, code := f.similar(t, h.getSimilarSongs2, "similarSongs2", uuidToID(f.tracks["Dusk"].ID)); code != ErrDataNotFound {
|
||||
t.Errorf("getSimilarSongs2 with a song id: error %d, want %d", code, ErrDataNotFound)
|
||||
}
|
||||
if _, code := f.similar(t, h.getSimilarSongs, "similarSongs", uuidToID(f.albums["Gone Tide"].ID)); code != ErrDataNotFound {
|
||||
t.Errorf("an album whose only file is missing: error %d, want %d", code, ErrDataNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
// getPlaylists leads with the listener's daily mixes, then their own
|
||||
// playlists, then other people's public ones; someone else's private
|
||||
// playlist is neither listed nor readable.
|
||||
func TestGetPlaylists_MixesFirstAndOnlyWhatTheListenerMaySee(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
ctx := context.Background()
|
||||
svc := playlists.NewService(f.pool, nil, "")
|
||||
newPlaylist := func(owner dbq.User, name string, public bool, songs ...string) pgtype.UUID {
|
||||
t.Helper()
|
||||
p, err := svc.Create(ctx, owner.ID, name, "", public)
|
||||
if err != nil {
|
||||
t.Fatalf("create %s: %v", name, err)
|
||||
}
|
||||
ids := make([]pgtype.UUID, 0, len(songs))
|
||||
for _, s := range songs {
|
||||
ids = append(ids, f.tracks[s].ID)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
if err := svc.AppendTracks(ctx, owner.ID, p.ID, ids); err != nil {
|
||||
t.Fatalf("append %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
return p.ID
|
||||
}
|
||||
mine := newPlaylist(f.user, "Road Songs", false, "Inlet", "Jetty", "Dusk")
|
||||
mix := newPlaylist(f.user, "For you", false, "Gale", "Harbour")
|
||||
f.exec(t, `UPDATE playlists SET kind = 'system', system_variant = 'for_you' WHERE id = $1`, mix)
|
||||
shared := newPlaylist(f.other, "Shared", true, "Gale")
|
||||
secret := newPlaylist(f.other, "Secret", false, "Gale")
|
||||
|
||||
h := f.handlers()
|
||||
var list struct {
|
||||
Playlists PlaylistsContainer `json:"playlists"`
|
||||
}
|
||||
if code := call(t, h.getPlaylists, f.user, "", &list); code != 0 {
|
||||
t.Fatalf("getPlaylists: error %d", code)
|
||||
}
|
||||
var names []string
|
||||
for _, p := range list.Playlists.Playlists {
|
||||
names = append(names, p.Name)
|
||||
}
|
||||
if want := []string{"For you", "Road Songs", "Shared"}; !slices.Equal(names, want) {
|
||||
t.Errorf("playlists = %v, want %v", names, want)
|
||||
}
|
||||
|
||||
// Jetty's file is missing, so a Subsonic app is not offered it.
|
||||
var one struct {
|
||||
Playlist PlaylistWithSongs `json:"playlist"`
|
||||
}
|
||||
if code := call(t, h.getPlaylist, f.user, "id="+uuidToID(mine), &one); code != 0 {
|
||||
t.Fatalf("getPlaylist: error %d", code)
|
||||
}
|
||||
if got, want := titles(one.Playlist.Entries), []string{"Inlet", "Dusk"}; !slices.Equal(got, want) {
|
||||
t.Errorf("entries = %v, want %v", got, want)
|
||||
}
|
||||
if one.Playlist.SongCount != 2 || one.Playlist.Duration != 400 {
|
||||
t.Errorf("songCount %d duration %d, want 2 and 400", one.Playlist.SongCount, one.Playlist.Duration)
|
||||
}
|
||||
if code := call(t, h.getPlaylist, f.user, "id="+uuidToID(shared), nil); code != 0 {
|
||||
t.Errorf("someone's public playlist: error %d", code)
|
||||
}
|
||||
if code := call(t, h.getPlaylist, f.user, "id="+uuidToID(secret), nil); code != ErrDataNotFound {
|
||||
t.Errorf("someone's private playlist: error %d, want %d", code, ErrDataNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
// In XML a playlist's songs are <entry> elements, as the Subsonic API names
|
||||
// them, while an album's stay <song>.
|
||||
func TestPlaylistXML_SongsAreEntries(t *testing.T) {
|
||||
body := PlaylistResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
Playlist: PlaylistWithSongs{
|
||||
PlaylistRef: PlaylistRef{ID: "p1", Name: "Road Songs", SongCount: 1},
|
||||
Entries: []SongRef{{ID: "s1", Title: "Inlet", Type: "music"}},
|
||||
},
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
Write(w, httptest.NewRequest(http.MethodGet, "/rest/getPlaylist?f=xml", nil), body)
|
||||
if !strings.Contains(w.Body.String(), `<playlist id="p1" name="Road Songs"`) || !strings.Contains(w.Body.String(), `<entry id="s1"`) {
|
||||
t.Errorf("xml = %s, want a playlist element holding entry elements", w.Body.String())
|
||||
}
|
||||
|
||||
album := AlbumResponse{Envelope: NewEnvelope("ok"), Album: AlbumDetail{ID: "a1", Songs: []SongRef{{ID: "s1"}}}}
|
||||
w = httptest.NewRecorder()
|
||||
Write(w, httptest.NewRequest(http.MethodGet, "/rest/getAlbum?f=xml", nil), album)
|
||||
if !strings.Contains(w.Body.String(), `<song id="s1"`) {
|
||||
t.Errorf("album xml = %s, want song elements", w.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
// against it here never reach the database.
|
||||
func mountedRest() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
Mount(r, nil, slog.New(slog.NewTextHandler(io.Discard, nil)), Config{}, nil, func() int { return 0 })
|
||||
Mount(r, nil, slog.New(slog.NewTextHandler(io.Discard, nil)), Config{}, nil, func() int { return 0 }, nil, nil)
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/auth"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playevents"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
||||
)
|
||||
|
||||
// Mount attaches Subsonic handlers at /rest on r. Endpoints are exposed at
|
||||
@@ -24,16 +26,22 @@ import (
|
||||
//
|
||||
// hops is the live trusted-proxy depth, read per request so an admin change
|
||||
// applies without a restart; it locates the caller for the auth throttle.
|
||||
func Mount(r chi.Router, pool *pgxpool.Pool, logger *slog.Logger, cfg Config, events *playevents.Writer, hops func() int) {
|
||||
//
|
||||
// picker and lists answer the methods that serve Minstrel's choices:
|
||||
// getRandomSongs and getSimilarSongs from the picker that Minstrel's own
|
||||
// radio uses, and getPlaylists from the playlist service, daily mixes
|
||||
// included.
|
||||
func Mount(r chi.Router, pool *pgxpool.Pool, logger *slog.Logger, cfg Config, events *playevents.Writer, hops func() int, picker *recommendation.Picker, lists *playlists.Service) {
|
||||
b := &browseHandlers{pool: pool}
|
||||
m := newMediaHandlers(pool, events, logger)
|
||||
u := &userHandlers{lookup: dbq.New(pool).GetUserByUsername}
|
||||
p := &pickHandlers{pool: pool, picker: picker, playlists: lists, logger: logger}
|
||||
r.Route("/rest", func(rest chi.Router) {
|
||||
// The one method the OpenSubsonic spec has answer without credentials.
|
||||
register(rest, "/getOpenSubsonicExtensions", handleGetOpenSubsonicExtensions)
|
||||
rest.Group(func(sub chi.Router) {
|
||||
sub.Use(Middleware(pool, cfg, auth.NewLoginGuard(), hops))
|
||||
mountAuthed(sub, b, m, u)
|
||||
mountAuthed(sub, b, m, u, p)
|
||||
})
|
||||
// Subsonic clients expect every /rest/* miss to come back as a
|
||||
// Subsonic-shaped error envelope, not chi's plain-text 404. Without
|
||||
@@ -47,7 +55,7 @@ func Mount(r chi.Router, pool *pgxpool.Pool, logger *slog.Logger, cfg Config, ev
|
||||
}
|
||||
|
||||
// mountAuthed registers every method that needs a signed-in user.
|
||||
func mountAuthed(sub chi.Router, b *browseHandlers, m *mediaHandlers, u *userHandlers) {
|
||||
func mountAuthed(sub chi.Router, b *browseHandlers, m *mediaHandlers, u *userHandlers, p *pickHandlers) {
|
||||
register(sub, "/ping", handlePing)
|
||||
register(sub, "/getLicense", handleGetLicense)
|
||||
register(sub, "/getMusicFolders", b.getMusicFolders)
|
||||
@@ -67,6 +75,11 @@ func mountAuthed(sub chi.Router, b *browseHandlers, m *mediaHandlers, u *userHan
|
||||
register(sub, "/getStarred", m.handleGetStarred)
|
||||
register(sub, "/getStarred2", m.handleGetStarred2)
|
||||
register(sub, "/getUser", u.getUser)
|
||||
register(sub, "/getPlaylists", p.getPlaylists)
|
||||
register(sub, "/getPlaylist", p.getPlaylist)
|
||||
register(sub, "/getRandomSongs", p.getRandomSongs)
|
||||
register(sub, "/getSimilarSongs", p.getSimilarSongs)
|
||||
register(sub, "/getSimilarSongs2", p.getSimilarSongs2)
|
||||
// Features Minstrel doesn't have: an empty list, not an error
|
||||
// (opensubsonic.go says why).
|
||||
register(sub, "/getInternetRadioStations", handleEmptyInternetRadioStations)
|
||||
|
||||
+21
-19
@@ -162,26 +162,28 @@ type AlbumResponse struct {
|
||||
|
||||
// SongRef is the track projection used in album detail, getSong, search3,
|
||||
// and later streaming/now-playing responses.
|
||||
//
|
||||
// It carries no XMLName: the field that holds it names the element, "song"
|
||||
// in most responses and "entry" in a playlist.
|
||||
type SongRef struct {
|
||||
XMLName xml.Name `json:"-" xml:"song"`
|
||||
ID string `json:"id" xml:"id,attr"`
|
||||
Parent string `json:"parent,omitempty" xml:"parent,attr,omitempty"`
|
||||
Title string `json:"title" xml:"title,attr"`
|
||||
Album string `json:"album,omitempty" xml:"album,attr,omitempty"`
|
||||
Artist string `json:"artist,omitempty" xml:"artist,attr,omitempty"`
|
||||
ArtistID string `json:"artistId,omitempty" xml:"artistId,attr,omitempty"`
|
||||
AlbumID string `json:"albumId,omitempty" xml:"albumId,attr,omitempty"`
|
||||
Track int `json:"track,omitempty" xml:"track,attr,omitempty"`
|
||||
DiscNumber int `json:"discNumber,omitempty" xml:"discNumber,attr,omitempty"`
|
||||
Genre string `json:"genre,omitempty" xml:"genre,attr,omitempty"`
|
||||
CoverArt string `json:"coverArt,omitempty" xml:"coverArt,attr,omitempty"`
|
||||
Size int64 `json:"size,omitempty" xml:"size,attr,omitempty"`
|
||||
ContentType string `json:"contentType,omitempty" xml:"contentType,attr,omitempty"`
|
||||
Suffix string `json:"suffix,omitempty" xml:"suffix,attr,omitempty"`
|
||||
Duration int `json:"duration,omitempty" xml:"duration,attr,omitempty"`
|
||||
BitRate int `json:"bitRate,omitempty" xml:"bitRate,attr,omitempty"`
|
||||
IsDir bool `json:"isDir" xml:"isDir,attr"`
|
||||
Type string `json:"type" xml:"type,attr"`
|
||||
ID string `json:"id" xml:"id,attr"`
|
||||
Parent string `json:"parent,omitempty" xml:"parent,attr,omitempty"`
|
||||
Title string `json:"title" xml:"title,attr"`
|
||||
Album string `json:"album,omitempty" xml:"album,attr,omitempty"`
|
||||
Artist string `json:"artist,omitempty" xml:"artist,attr,omitempty"`
|
||||
ArtistID string `json:"artistId,omitempty" xml:"artistId,attr,omitempty"`
|
||||
AlbumID string `json:"albumId,omitempty" xml:"albumId,attr,omitempty"`
|
||||
Track int `json:"track,omitempty" xml:"track,attr,omitempty"`
|
||||
DiscNumber int `json:"discNumber,omitempty" xml:"discNumber,attr,omitempty"`
|
||||
Genre string `json:"genre,omitempty" xml:"genre,attr,omitempty"`
|
||||
CoverArt string `json:"coverArt,omitempty" xml:"coverArt,attr,omitempty"`
|
||||
Size int64 `json:"size,omitempty" xml:"size,attr,omitempty"`
|
||||
ContentType string `json:"contentType,omitempty" xml:"contentType,attr,omitempty"`
|
||||
Suffix string `json:"suffix,omitempty" xml:"suffix,attr,omitempty"`
|
||||
Duration int `json:"duration,omitempty" xml:"duration,attr,omitempty"`
|
||||
BitRate int `json:"bitRate,omitempty" xml:"bitRate,attr,omitempty"`
|
||||
IsDir bool `json:"isDir" xml:"isDir,attr"`
|
||||
Type string `json:"type" xml:"type,attr"`
|
||||
// ReplayGain is OpenSubsonic's replayGain: Minstrel's own
|
||||
// measurements, so third-party clients that level by ReplayGain do it
|
||||
// from the same numbers the Minstrel apps use. Omitted until measured.
|
||||
|
||||
Reference in New Issue
Block a user