fix(subsonic): answer what the OpenSubsonic spec and Subsonic apps require
- getOpenSubsonicExtensions answers, without credentials, as the spec requires of a server that says openSubsonic=true; it lists apiKeyAuthentication. An apiKey sent with u is error 43 and an unknown apiKey error 44, the extension's codes; a wrong key still counts toward the sign-in throttle. - search3 with an empty query (or two quote marks) matches everything, paged in a stable order, so apps that keep a copy of the library (Symfonium) can download it. A page of songs reads its albums and artists in two queries, not two per song. - getAlbumList2 serves type=starred and highest (the listener's liked albums) and byYear (oldest first, newest first for a backwards range). - Internet radio, podcasts, bookmarks, shares, chat and now-playing answer with an empty list instead of "Method not implemented", so an app shows an empty tab rather than an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1000,7 +1000,7 @@ func (q *Queries) ListRecentlyAddedAlbumsWithArtist(ctx context.Context, limit i
|
||||
const searchAlbums = `-- name: SearchAlbums :many
|
||||
SELECT id, title, sort_title, artist_id, release_date, mbid, cover_art_path, created_at, updated_at, cover_art_source, cover_art_sources_version, release_group_mbid, announced_at FROM albums
|
||||
WHERE title ILIKE '%' || $1 || '%'
|
||||
ORDER BY sort_title
|
||||
ORDER BY sort_title, id
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
|
||||
@@ -441,7 +441,7 @@ func (q *Queries) ListTrackArtistsForAlbum(ctx context.Context, albumID pgtype.U
|
||||
const searchArtists = `-- name: SearchArtists :many
|
||||
SELECT id, name, sort_name, mbid, created_at, updated_at, artist_thumb_path, artist_fanart_path, artist_art_source, artist_art_sources_version FROM artists
|
||||
WHERE name ILIKE '%' || $1 || '%'
|
||||
ORDER BY sort_name
|
||||
ORDER BY sort_name, id
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
|
||||
@@ -166,6 +166,72 @@ func (q *Queries) ListAlbumsByGenreWithArtist(ctx context.Context, arg ListAlbum
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listAlbumsByYearOrdered = `-- name: ListAlbumsByYearOrdered :many
|
||||
SELECT albums.id, albums.title, albums.sort_title, albums.artist_id, albums.release_date, albums.mbid, albums.cover_art_path, albums.created_at, albums.updated_at, albums.cover_art_source, albums.cover_art_sources_version, albums.release_group_mbid, albums.announced_at FROM albums
|
||||
WHERE albums.release_date IS NOT NULL
|
||||
AND EXTRACT(YEAR FROM albums.release_date)::int
|
||||
BETWEEN LEAST($1::int, $2::int)
|
||||
AND GREATEST($1::int, $2::int)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM tracks
|
||||
WHERE tracks.album_id = albums.id
|
||||
AND tracks.missing_since IS NULL
|
||||
)
|
||||
ORDER BY CASE WHEN $1::int <= $2::int THEN albums.release_date END ASC,
|
||||
CASE WHEN $1::int > $2::int THEN albums.release_date END DESC,
|
||||
albums.sort_title, albums.id
|
||||
LIMIT $4 OFFSET $3
|
||||
`
|
||||
|
||||
type ListAlbumsByYearOrderedParams struct {
|
||||
FromYear int32
|
||||
ToYear int32
|
||||
Off int32
|
||||
Lim int32
|
||||
}
|
||||
|
||||
// Subsonic getAlbumList2 type=byYear: albums released within an inclusive
|
||||
// year range, oldest first, or newest first when the caller asks for the
|
||||
// range backwards (fromYear > toYear), as the Subsonic API defines it.
|
||||
func (q *Queries) ListAlbumsByYearOrdered(ctx context.Context, arg ListAlbumsByYearOrderedParams) ([]Album, error) {
|
||||
rows, err := q.db.Query(ctx, listAlbumsByYearOrdered,
|
||||
arg.FromYear,
|
||||
arg.ToYear,
|
||||
arg.Off,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Album
|
||||
for rows.Next() {
|
||||
var i Album
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.SortTitle,
|
||||
&i.ArtistID,
|
||||
&i.ReleaseDate,
|
||||
&i.Mbid,
|
||||
&i.CoverArtPath,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CoverArtSource,
|
||||
&i.CoverArtSourcesVersion,
|
||||
&i.ReleaseGroupMbid,
|
||||
&i.AnnouncedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listAlbumsByYearRangeWithArtist = `-- name: ListAlbumsByYearRangeWithArtist :many
|
||||
SELECT albums.id, albums.title, albums.sort_title, albums.artist_id, albums.release_date, albums.mbid, albums.cover_art_path, albums.created_at, albums.updated_at, albums.cover_art_source, albums.cover_art_sources_version, albums.release_group_mbid, albums.announced_at, artists.name AS artist_name
|
||||
FROM albums
|
||||
|
||||
@@ -1091,7 +1091,7 @@ WHERE title ILIKE '%' || $1::text || '%'
|
||||
SELECT 1 FROM quarantine q
|
||||
WHERE q.user_id = $2 AND q.track_id = tracks.id
|
||||
)
|
||||
ORDER BY title
|
||||
ORDER BY title, id
|
||||
LIMIT $3 OFFSET $4
|
||||
`
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ LIMIT sqlc.arg(lim) OFFSET sqlc.arg(off);
|
||||
-- name: SearchAlbums :many
|
||||
SELECT * FROM albums
|
||||
WHERE title ILIKE '%' || $1 || '%'
|
||||
ORDER BY sort_title
|
||||
ORDER BY sort_title, id
|
||||
LIMIT $2 OFFSET $3;
|
||||
|
||||
-- name: CountAlbumsMatching :one
|
||||
|
||||
@@ -27,7 +27,7 @@ SELECT * FROM artists ORDER BY sort_name;
|
||||
-- name: SearchArtists :many
|
||||
SELECT * FROM artists
|
||||
WHERE name ILIKE '%' || $1 || '%'
|
||||
ORDER BY sort_name
|
||||
ORDER BY sort_name, id
|
||||
LIMIT $2 OFFSET $3;
|
||||
|
||||
-- name: ListArtistsAlpha :many
|
||||
|
||||
@@ -144,3 +144,22 @@ JOIN LATERAL regexp_split_to_table(coalesce(tracks.genre, ''), '[;,]') AS g(genr
|
||||
WHERE tracks.artist_id = $1 AND trim(g.genre) <> ''
|
||||
AND tracks.missing_since IS NULL
|
||||
ORDER BY trim(g.genre);
|
||||
|
||||
-- name: ListAlbumsByYearOrdered :many
|
||||
-- Subsonic getAlbumList2 type=byYear: albums released within an inclusive
|
||||
-- year range, oldest first, or newest first when the caller asks for the
|
||||
-- range backwards (fromYear > toYear), as the Subsonic API defines it.
|
||||
SELECT albums.* FROM albums
|
||||
WHERE albums.release_date IS NOT NULL
|
||||
AND EXTRACT(YEAR FROM albums.release_date)::int
|
||||
BETWEEN LEAST(sqlc.arg(from_year)::int, sqlc.arg(to_year)::int)
|
||||
AND GREATEST(sqlc.arg(from_year)::int, sqlc.arg(to_year)::int)
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM tracks
|
||||
WHERE tracks.album_id = albums.id
|
||||
AND tracks.missing_since IS NULL
|
||||
)
|
||||
ORDER BY CASE WHEN sqlc.arg(from_year)::int <= sqlc.arg(to_year)::int THEN albums.release_date END ASC,
|
||||
CASE WHEN sqlc.arg(from_year)::int > sqlc.arg(to_year)::int THEN albums.release_date END DESC,
|
||||
albums.sort_title, albums.id
|
||||
LIMIT sqlc.arg(lim) OFFSET sqlc.arg(off);
|
||||
|
||||
@@ -80,7 +80,7 @@ WHERE title ILIKE '%' || $1::text || '%'
|
||||
SELECT 1 FROM quarantine q
|
||||
WHERE q.user_id = $2 AND q.track_id = tracks.id
|
||||
)
|
||||
ORDER BY title
|
||||
ORDER BY title, id
|
||||
LIMIT $3 OFFSET $4;
|
||||
|
||||
-- name: CountTracksMatching :one
|
||||
|
||||
Reference in New Issue
Block a user