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

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:
2026-11-25 16:40:21 -05:00
co-authored by Claude Opus 5.5
parent da64d95264
commit 8731e9695a
9 changed files with 737 additions and 73 deletions
+28 -1
View File
@@ -36,7 +36,11 @@
-- Ordered by count first: raw ID3 data has a long tail of one-off junk tags,
-- so alphabetical would bury the handful of genres a library actually has
-- a lot of. Name breaks ties for a stable order.
SELECT trim(g.genre) AS genre, COUNT(DISTINCT tracks.id)::bigint AS track_count
--
-- album_count is the albums holding at least one of those tracks, which is
-- what a Subsonic app shows beside the genre.
SELECT trim(g.genre) AS genre, COUNT(DISTINCT tracks.id)::bigint AS track_count,
COUNT(DISTINCT tracks.album_id)::bigint AS album_count
FROM tracks
JOIN LATERAL regexp_split_to_table(coalesce(tracks.genre, ''), '[;,]') AS g(genre) ON true
WHERE trim(g.genre) <> ''
@@ -66,6 +70,29 @@ WHERE EXISTS (
ORDER BY albums.sort_title, albums.id
LIMIT sqlc.arg(lim) OFFSET sqlc.arg(off);
-- name: ListTracksByGenre :many
-- One genre's songs for the Subsonic getSongsByGenre, a page at a time.
-- Splits and trims identically to ListGenresWithCount, so the songs a genre
-- leads to are the ones it counted. The listener's quarantined tracks are
-- left out: an app asks for these to play them. Album by album in track
-- order, so paging walks a stable order.
SELECT sqlc.embed(tracks)
FROM tracks
JOIN albums ON albums.id = tracks.album_id
WHERE tracks.missing_since IS NULL
AND EXISTS (
SELECT 1
FROM regexp_split_to_table(coalesce(tracks.genre, ''), '[;,]') AS g(genre)
WHERE trim(g.genre) = trim(sqlc.arg(genre)::text)
)
AND NOT EXISTS (
SELECT 1 FROM quarantine q
WHERE q.user_id = sqlc.arg(user_id) AND q.track_id = tracks.id
)
ORDER BY albums.sort_title, albums.id,
tracks.disc_number NULLS FIRST, tracks.track_number NULLS FIRST, tracks.id
LIMIT sqlc.arg(lim) OFFSET sqlc.arg(off);
-- name: CountAlbumsByGenre :one
-- Total for the paging envelope. EXISTS mirrors the list query exactly; a
-- JOIN + DISTINCT here would count differently the moment an album has two