feat(subsonic): browse by genre and by folder
release / web (push) Successful in 1m16s
release / go (push) Successful in 1m47s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m59s
release / android (push) Successful in 4m30s
release / Build signed APK (push) Successful in 4m56s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 15s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m16s
release / go (push) Successful in 1m47s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m59s
release / android (push) Successful in 4m30s
release / Build signed APK (push) Successful in 4m56s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 15s
release / Verify release artifacts (tag releases only) (push) Skipped
Subsonic apps can now list genres and play one (getGenres, getSongsByGenre), and apps that browse by folder, such as DSub, can open an artist to its albums and an album to its songs (getMusicDirectory), with the album lists and search they use in that mode (getAlbumList, search2). Genres are split and counted as the web's genre index counts them, now with an album count beside the song count. A genre's songs leave out the listener's quarantined ones and missing files. Folders are Minstrel's artists and albums, under the same ids as the tag-based calls. getAlbumList2 and search3 now share their selection with the folder versions, so the two modes list and find the same things. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
package subsonic
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The XML forms an app reads: a genre's name is the element's text, and a
|
||||
// folder's entries are <child> elements.
|
||||
func TestGenreAndDirectoryXML(t *testing.T) {
|
||||
out, err := xml.Marshal(GenresResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
Genres: GenresContainer{Genres: []Genre{{Value: "Jazz", SongCount: 3, AlbumCount: 2}}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal genres: %v", err)
|
||||
}
|
||||
if want := `<genres><genre songCount="3" albumCount="2">Jazz</genre></genres>`; !strings.Contains(string(out), want) {
|
||||
t.Errorf("genres XML = %s, want it to hold %s", out, want)
|
||||
}
|
||||
|
||||
out, err = xml.Marshal(DirectoryResponse{
|
||||
Envelope: NewEnvelope("ok"),
|
||||
Directory: Directory{ID: "a", Name: "Tin Orchard", Children: []SongRef{
|
||||
{ID: "b", Parent: "a", Title: "Paper Boats", IsDir: true},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal directory: %v", err)
|
||||
}
|
||||
if want := `<directory id="a" name="Tin Orchard"><child id="b" parent="a" title="Paper Boats" isDir="true"></child></directory>`; !strings.Contains(string(out), want) {
|
||||
t.Errorf("directory XML = %s, want it to hold %s", out, want)
|
||||
}
|
||||
}
|
||||
|
||||
func (f picksFixture) browse() *browseHandlers { return &browseHandlers{pool: f.pool} }
|
||||
|
||||
// A tag of several genres counts toward each; the missing file counts toward
|
||||
// none; the genres with the most songs come first, then by name.
|
||||
func TestGetGenres_CountsEachGenreOfASplitTag(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
var got struct {
|
||||
Genres GenresContainer `json:"genres"`
|
||||
}
|
||||
if code := call(t, f.browse().getGenres, f.user, "", &got); code != 0 {
|
||||
t.Fatalf("getGenres: error %d", code)
|
||||
}
|
||||
want := []Genre{
|
||||
{Value: "Jazz", SongCount: 3, AlbumCount: 2},
|
||||
{Value: "Rock", SongCount: 3, AlbumCount: 2},
|
||||
{Value: "Funk", SongCount: 1, AlbumCount: 1},
|
||||
}
|
||||
if !slices.Equal(got.Genres.Genres, want) {
|
||||
t.Errorf("genres = %+v, want %+v", got.Genres.Genres, want)
|
||||
}
|
||||
}
|
||||
|
||||
func (f picksFixture) songsByGenre(t *testing.T, query string) ([]string, int) {
|
||||
t.Helper()
|
||||
var got struct {
|
||||
SongsByGenre struct {
|
||||
Songs *[]SongRef `json:"song"`
|
||||
} `json:"songsByGenre"`
|
||||
}
|
||||
code := call(t, f.browse().getSongsByGenre, f.user, query, &got)
|
||||
if code != 0 {
|
||||
return nil, code
|
||||
}
|
||||
if got.SongsByGenre.Songs == nil {
|
||||
t.Fatalf("getSongsByGenre %s: song is null or absent, want a list", query)
|
||||
}
|
||||
return titles(*got.SongsByGenre.Songs), 0
|
||||
}
|
||||
|
||||
// A genre's songs are its playable ones, without the listener's quarantined
|
||||
// song, album by album in track order, a page at a time.
|
||||
func TestGetSongsByGenre_PagesTheGenresPlayableSongs(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
cases := []struct {
|
||||
query string
|
||||
want []string
|
||||
}{
|
||||
{"genre=Jazz", []string{"Dusk", "Harbour"}},
|
||||
{"genre=Rock", []string{"Flint", "Gale", "Inlet"}},
|
||||
{"genre=Rock&count=2&offset=1", []string{"Gale", "Inlet"}},
|
||||
// Ember is the only Funk song, and the listener quarantined it.
|
||||
{"genre=Funk", []string{}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, code := f.songsByGenre(t, c.query)
|
||||
if code != 0 {
|
||||
t.Fatalf("%s: error %d", c.query, code)
|
||||
}
|
||||
if !slices.Equal(got, c.want) {
|
||||
t.Errorf("%s = %v, want %v", c.query, got, c.want)
|
||||
}
|
||||
}
|
||||
if _, code := f.songsByGenre(t, ""); code != ErrMissingParameter {
|
||||
t.Errorf("no genre: code %d, want %d", code, ErrMissingParameter)
|
||||
}
|
||||
}
|
||||
|
||||
func (f picksFixture) directory(t *testing.T, id string) (Directory, int) {
|
||||
t.Helper()
|
||||
var got struct {
|
||||
Directory Directory `json:"directory"`
|
||||
}
|
||||
code := call(t, f.browse().getMusicDirectory, f.user, "id="+id, &got)
|
||||
return got.Directory, code
|
||||
}
|
||||
|
||||
// An artist's folder holds its albums as folders; an album's holds its songs.
|
||||
func TestGetMusicDirectory_OpensAnArtistToAlbumsAndAnAlbumToSongs(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
artistID := uuidToID(f.artist.ID)
|
||||
|
||||
dir, code := f.directory(t, artistID)
|
||||
if code != 0 {
|
||||
t.Fatalf("artist folder: error %d", code)
|
||||
}
|
||||
if dir.ID != artistID || dir.Name != "Tin Orchard" {
|
||||
t.Errorf("artist folder = %q %q, want %q Tin Orchard", dir.ID, dir.Name, artistID)
|
||||
}
|
||||
// By release date, then title, as getArtist lists them.
|
||||
if got, want := titles(dir.Children), []string{"Lantern Hours", "Gone Tide", "Paper Boats"}; !slices.Equal(got, want) {
|
||||
t.Errorf("artist folder holds %v, want %v", got, want)
|
||||
}
|
||||
for _, c := range dir.Children {
|
||||
if !c.IsDir || c.Parent != artistID || c.Type != "" {
|
||||
t.Errorf("album %s: isDir=%v parent=%q type=%q, want a folder under the artist", c.Title, c.IsDir, c.Parent, c.Type)
|
||||
}
|
||||
}
|
||||
|
||||
paper := uuidToID(f.albums["Paper Boats"].ID)
|
||||
if dir.Children[2].ID != paper || dir.Children[2].Year != 2012 {
|
||||
t.Errorf("Paper Boats folder = %+v, want id %s and year 2012", dir.Children[2], paper)
|
||||
}
|
||||
dir, code = f.directory(t, paper)
|
||||
if code != 0 {
|
||||
t.Fatalf("album folder: error %d", code)
|
||||
}
|
||||
if dir.ID != paper || dir.Parent != artistID || dir.Name != "Paper Boats" {
|
||||
t.Errorf("album folder = %q parent %q %q, want %q under %q", dir.ID, dir.Parent, dir.Name, paper, artistID)
|
||||
}
|
||||
if got, want := titles(dir.Children), []string{"Gale", "Harbour", "Inlet"}; !slices.Equal(got, want) {
|
||||
t.Errorf("album folder holds %v, want %v", got, want)
|
||||
}
|
||||
for _, c := range dir.Children {
|
||||
if c.IsDir || c.Parent != paper || c.Type != "music" {
|
||||
t.Errorf("song %s: isDir=%v parent=%q type=%q, want a song in the album", c.Title, c.IsDir, c.Parent, c.Type)
|
||||
}
|
||||
}
|
||||
|
||||
if _, code := f.directory(t, uuidToID(f.tracks["Gale"].ID)); code != ErrDataNotFound {
|
||||
t.Errorf("a song id: code %d, want %d", code, ErrDataNotFound)
|
||||
}
|
||||
if _, code := f.directory(t, ""); code != ErrMissingParameter {
|
||||
t.Errorf("no id: code %d, want %d", code, ErrMissingParameter)
|
||||
}
|
||||
}
|
||||
|
||||
// getAlbumList offers getAlbumList2's lists, with each album a folder.
|
||||
func TestGetAlbumList_IsAlbumList2AsFolders(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
var got struct {
|
||||
AlbumList AlbumListContainer `json:"albumList"`
|
||||
}
|
||||
if code := call(t, f.browse().getAlbumList, f.user, "type=alphabeticalByName", &got); code != 0 {
|
||||
t.Fatalf("getAlbumList: error %d", code)
|
||||
}
|
||||
if names, want := titles(got.AlbumList.Albums), []string{"Gone Tide", "Lantern Hours", "Paper Boats"}; !slices.Equal(names, want) {
|
||||
t.Errorf("albums = %v, want %v", names, want)
|
||||
}
|
||||
for _, a := range got.AlbumList.Albums {
|
||||
if !a.IsDir || a.Artist != "Tin Orchard" || a.Parent != uuidToID(f.artist.ID) {
|
||||
t.Errorf("album %s: isDir=%v artist=%q parent=%q, want a folder under Tin Orchard", a.Title, a.IsDir, a.Artist, a.Parent)
|
||||
}
|
||||
}
|
||||
if code := call(t, f.browse().getAlbumList, f.user, "", nil); code != ErrMissingParameter {
|
||||
t.Errorf("no type: code %d, want %d", code, ErrMissingParameter)
|
||||
}
|
||||
}
|
||||
|
||||
// search2 finds what search3 finds, with the albums as folders.
|
||||
func TestSearch2_FindsWhatSearch3FindsWithAlbumsAsFolders(t *testing.T) {
|
||||
f := seedPicks(t)
|
||||
var got struct {
|
||||
SearchResult2 SearchResult2Container `json:"searchResult2"`
|
||||
}
|
||||
if code := call(t, f.browse().search2, f.user, "query=Paper", &got); code != 0 {
|
||||
t.Fatalf("search2: error %d", code)
|
||||
}
|
||||
res := got.SearchResult2
|
||||
if len(res.Albums) != 1 || res.Albums[0].Title != "Paper Boats" || !res.Albums[0].IsDir {
|
||||
t.Errorf("albums = %+v, want the Paper Boats folder", res.Albums)
|
||||
}
|
||||
if res.Artists == nil || len(res.Artists) != 0 || res.Songs == nil || len(res.Songs) != 0 {
|
||||
t.Errorf("artists = %v, songs = %v, want both empty lists", res.Artists, res.Songs)
|
||||
}
|
||||
|
||||
if code := call(t, f.browse().search2, f.user, "query=Harbour", &got); code != 0 {
|
||||
t.Fatalf("search2: error %d", code)
|
||||
}
|
||||
if songs := titles(got.SearchResult2.Songs); !slices.Equal(songs, []string{"Harbour"}) {
|
||||
t.Errorf("songs = %v, want [Harbour]", songs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user