fix(subsonic): albums, folders and search list only what the listener can play

getAlbum, getMusicDirectory and search2/3 ignored the listener's quarantine
and listed missing files, which an app then failed to stream; song counts
counted both. They now pass the listener and leave out missing files, as
the mixes already did. Subsonic can't mark a song unplayable, so leaving it
out is how the native apps' greyed-out row comes across.

Song search filters in SQL (SearchPlayableTracks), so a library sync paging
through search3 never gets a short page that reads as the end. Album song
counts come from one query for the whole page (CountPlayableTracksByAlbums)
instead of one per album.

tracks.sql also drops CountTracksByArtist, which nothing called; see the
next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 22:02:00 -05:00
co-authored by Claude Opus 5.5
parent d0675e1817
commit 1ff4bc8258
5 changed files with 296 additions and 37 deletions
+80
View File
@@ -0,0 +1,80 @@
package subsonic
import (
"slices"
"testing"
)
// Subsonic apps are shown only the songs the listener can play, as the web
// and Android apps are: a track they quarantined is hidden from them, and a
// missing file is left out, since Subsonic can't mark a song unplayable and
// an app would only fail to stream it. Album song counts agree with the
// songs listed.
//
// In the picks fixture the listener quarantined Ember (Lantern Hours), and
// Jetty's file (Gone Tide's only song) is missing.
func TestSubsonic_ListsOnlyWhatTheListenerCanPlay(t *testing.T) {
f := seedPicks(t)
b := &browseHandlers{pool: f.pool}
lantern := uuidToID(f.albums["Lantern Hours"].ID)
gone := uuidToID(f.albums["Gone Tide"].ID)
var album AlbumResponse
if code := call(t, b.getAlbum, f.user, "id="+lantern, &album); code != 0 {
t.Fatalf("getAlbum: error %d", code)
}
if got := titles(album.Album.Songs); !slices.Equal(got, []string{"Dusk", "Flint"}) || album.Album.SongCount != 2 {
t.Errorf("getAlbum Lantern Hours: %v (songCount %d), want [Dusk Flint] and 2", got, album.Album.SongCount)
}
if code := call(t, b.getAlbum, f.user, "id="+gone, &album); code != 0 {
t.Fatalf("getAlbum Gone Tide: error %d", code)
}
if len(album.Album.Songs) != 0 || album.Album.SongCount != 0 {
t.Errorf("getAlbum Gone Tide: %v (songCount %d), want nothing", titles(album.Album.Songs), album.Album.SongCount)
}
var dir DirectoryResponse
if code := call(t, b.getMusicDirectory, f.user, "id="+lantern, &dir); code != 0 {
t.Fatalf("getMusicDirectory: error %d", code)
}
if got := titles(dir.Directory.Children); !slices.Equal(got, []string{"Dusk", "Flint"}) {
t.Errorf("getMusicDirectory Lantern Hours: %v, want [Dusk Flint]", got)
}
var search SearchResult3Response
if code := call(t, b.search3, f.user, "query=&songCount=50&albumCount=50&artistCount=0", &search); code != 0 {
t.Fatalf("search3: error %d", code)
}
if got := titles(search.SearchResult3.Songs); !slices.Equal(got, []string{"Dusk", "Flint", "Gale", "Harbour", "Inlet"}) {
t.Errorf("search3 songs: %v, want every song but Ember and Jetty", got)
}
// Paging through the library still reaches every playable song: the
// hidden ones don't leave a short page that reads as the end.
var page SearchResult3Response
if code := call(t, b.search3, f.user, "query=&songCount=2&songOffset=2&albumCount=0&artistCount=0", &page); code != 0 {
t.Fatalf("search3 page: error %d", code)
}
if got := titles(page.SearchResult3.Songs); !slices.Equal(got, []string{"Gale", "Harbour"}) {
t.Errorf("search3 second page: %v, want [Gale Harbour]", got)
}
counts := map[string]int{}
for _, a := range search.SearchResult3.Albums {
counts[a.Name] = a.SongCount
}
want := map[string]int{"Lantern Hours": 2, "Paper Boats": 3, "Gone Tide": 0}
for name, n := range want {
if counts[name] != n {
t.Errorf("search3 album %s songCount %d, want %d", name, counts[name], n)
}
}
var artist ArtistResponse
if code := call(t, b.getArtist, f.user, "id="+uuidToID(f.artist.ID), &artist); code != 0 {
t.Fatalf("getArtist: error %d", code)
}
for _, a := range artist.Artist.Albums {
if a.SongCount != want[a.Name] {
t.Errorf("getArtist album %s songCount %d, want %d", a.Name, a.SongCount, want[a.Name])
}
}
}