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:
@@ -367,7 +367,8 @@ func (q *Queries) ListGenresForArtist(ctx context.Context, artistID pgtype.UUID)
|
||||
|
||||
const listGenresWithCount = `-- name: ListGenresWithCount :many
|
||||
|
||||
SELECT trim(g.genre) AS genre, COUNT(DISTINCT tracks.id)::bigint AS track_count
|
||||
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) <> ''
|
||||
@@ -379,6 +380,7 @@ ORDER BY track_count DESC, trim(g.genre)
|
||||
type ListGenresWithCountRow struct {
|
||||
Genre string
|
||||
TrackCount int64
|
||||
AlbumCount int64
|
||||
}
|
||||
|
||||
// Every query in this file filters `tracks.missing_since IS NULL`. A row whose
|
||||
@@ -417,6 +419,9 @@ type ListGenresWithCountRow struct {
|
||||
// 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.
|
||||
//
|
||||
// album_count is the albums holding at least one of those tracks, which is
|
||||
// what a Subsonic app shows beside the genre.
|
||||
// Ordered by the expression, not the output alias: `ORDER BY genre` is
|
||||
// ambiguous between the alias and tracks.genre, and sqlc rejects it.
|
||||
func (q *Queries) ListGenresWithCount(ctx context.Context) ([]ListGenresWithCountRow, error) {
|
||||
@@ -428,7 +433,96 @@ func (q *Queries) ListGenresWithCount(ctx context.Context) ([]ListGenresWithCoun
|
||||
var items []ListGenresWithCountRow
|
||||
for rows.Next() {
|
||||
var i ListGenresWithCountRow
|
||||
if err := rows.Scan(&i.Genre, &i.TrackCount); err != nil {
|
||||
if err := rows.Scan(&i.Genre, &i.TrackCount, &i.AlbumCount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTracksByGenre = `-- name: ListTracksByGenre :many
|
||||
SELECT tracks.id, tracks.title, tracks.album_id, tracks.artist_id, tracks.track_number, tracks.disc_number, tracks.duration_ms, tracks.file_path, tracks.file_size, tracks.file_format, tracks.bitrate, tracks.mbid, tracks.genre, tracks.added_at, tracks.updated_at, tracks.tag_source, tracks.tag_sources_version, tracks.tag_read_version, tracks.missing_since, tracks.mbid_source, tracks.song_id, tracks.song_key, tracks.source_verdict, tracks.source_verdict_at, tracks.emptied_at, tracks.removed_reason, tracks.removed_by, tracks.artist_credit
|
||||
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($1::text)
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM quarantine q
|
||||
WHERE q.user_id = $2 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 $4 OFFSET $3
|
||||
`
|
||||
|
||||
type ListTracksByGenreParams struct {
|
||||
Genre string
|
||||
UserID pgtype.UUID
|
||||
Off int32
|
||||
Lim int32
|
||||
}
|
||||
|
||||
type ListTracksByGenreRow struct {
|
||||
Track Track
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (q *Queries) ListTracksByGenre(ctx context.Context, arg ListTracksByGenreParams) ([]ListTracksByGenreRow, error) {
|
||||
rows, err := q.db.Query(ctx, listTracksByGenre,
|
||||
arg.Genre,
|
||||
arg.UserID,
|
||||
arg.Off,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListTracksByGenreRow
|
||||
for rows.Next() {
|
||||
var i ListTracksByGenreRow
|
||||
if err := rows.Scan(
|
||||
&i.Track.ID,
|
||||
&i.Track.Title,
|
||||
&i.Track.AlbumID,
|
||||
&i.Track.ArtistID,
|
||||
&i.Track.TrackNumber,
|
||||
&i.Track.DiscNumber,
|
||||
&i.Track.DurationMs,
|
||||
&i.Track.FilePath,
|
||||
&i.Track.FileSize,
|
||||
&i.Track.FileFormat,
|
||||
&i.Track.Bitrate,
|
||||
&i.Track.Mbid,
|
||||
&i.Track.Genre,
|
||||
&i.Track.AddedAt,
|
||||
&i.Track.UpdatedAt,
|
||||
&i.Track.TagSource,
|
||||
&i.Track.TagSourcesVersion,
|
||||
&i.Track.TagReadVersion,
|
||||
&i.Track.MissingSince,
|
||||
&i.Track.MbidSource,
|
||||
&i.Track.SongID,
|
||||
&i.Track.SongKey,
|
||||
&i.Track.SourceVerdict,
|
||||
&i.Track.SourceVerdictAt,
|
||||
&i.Track.EmptiedAt,
|
||||
&i.Track.RemovedReason,
|
||||
&i.Track.RemovedBy,
|
||||
&i.Track.ArtistCredit,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user