Files
minstrel/internal/subsonic/opensubsonic.go
T
bvandeusenandClaude Opus 5.5 f87aba5b86
release / go (push) Failing after 1m15s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 3m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m33s
release / Build signed APK (push) Canceled after 4m9s
feat(subsonic): scan status, artist and album info, lyrics, ratings and users
The last Subsonic methods apps call that Minstrel didn't answer:

- getScanStatus counts the songs whose files are present and says
  whether a scan is running; startScan, for an admin, starts the scan the
  web app's Rescan starts, and answers "scanning" straight away since the
  scan records itself a moment later.
- getArtistInfo and getArtistInfo2 give the artist's MusicBrainz id and the
  artists in this library that sound like them, from an artist, album or
  song id; getAlbumInfo and getAlbumInfo2 give the album's MusicBrainz id.
  Minstrel fetches no biographies or outside images, so none are sent.
- getLyrics (by artist and title) and getLyricsBySongId (OpenSubsonic
  songLyrics, now declared) read lyrics when asked: a .lrc file beside the
  song gives timed lyrics, otherwise the song's own lyrics tag.
- setRating accepts a rating and keeps none: a like is Minstrel's only
  rating, and a low rating is never read as a dislike.
- getUsers lists every user, for an admin only.

ArtistRef no longer fixes its XML element name, so it can appear as
similarArtist; every field holding it names the element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:43:13 -05:00

148 lines
4.7 KiB
Go

package subsonic
import (
"encoding/xml"
"net/http"
)
// OpenSubsonicExtension names one OpenSubsonic extension and the versions of
// it the server supports.
type OpenSubsonicExtension struct {
XMLName xml.Name `json:"-" xml:"openSubsonicExtensions"`
Name string `json:"name" xml:"name,attr"`
Versions []int `json:"versions" xml:"versions"`
}
// OpenSubsonicExtensionsResponse is the body of getOpenSubsonicExtensions.
type OpenSubsonicExtensionsResponse struct {
Envelope
Extensions []OpenSubsonicExtension `json:"openSubsonicExtensions" xml:"openSubsonicExtensions"`
}
// openSubsonicExtensions lists what Minstrel implements beyond Subsonic
// 1.16.1. apiKeyAuthentication is the apiKey parameter the auth middleware
// accepts; songLyrics is getLyricsBySongId. Add an entry only for an extension the server fully serves:
// apps switch behaviour on this list.
var openSubsonicExtensions = []OpenSubsonicExtension{
{Name: "apiKeyAuthentication", Versions: []int{1}},
// getLyricsBySongId.
{Name: "songLyrics", Versions: []int{1}},
}
// handleGetOpenSubsonicExtensions answers without credentials: every
// response says openSubsonic=true, and the OpenSubsonic spec has apps call
// this before signing in to learn which extensions, such as API keys, they
// can use to sign in.
func handleGetOpenSubsonicExtensions(w http.ResponseWriter, r *http.Request) {
Write(w, r, OpenSubsonicExtensionsResponse{
Envelope: NewEnvelope("ok"),
Extensions: openSubsonicExtensions,
})
}
// Features Minstrel does not have answer with an empty list rather than an
// error. Apps fetch these to fill their own screens (a radio tab, a podcasts
// tab, who else is listening) and many show an error banner, or stop
// loading the screen, on a failed call; an empty list just leaves the tab
// empty. Each container's list is non-nil so JSON renders [] and not null.
type emptyList struct{}
type internetRadioStationsResponse struct {
Envelope
Stations struct {
XMLName xml.Name `json:"-" xml:"internetRadioStations"`
Stations []emptyList `json:"internetRadioStation" xml:"internetRadioStation"`
} `json:"internetRadioStations" xml:"internetRadioStations"`
}
type podcastsResponse struct {
Envelope
Podcasts struct {
XMLName xml.Name `json:"-" xml:"podcasts"`
Channels []emptyList `json:"channel" xml:"channel"`
} `json:"podcasts" xml:"podcasts"`
}
type NewestpodcastsResponse struct {
Envelope
NewestPodcasts struct {
XMLName xml.Name `json:"-" xml:"newestPodcasts"`
Episodes []emptyList `json:"episode" xml:"episode"`
} `json:"newestPodcasts" xml:"newestPodcasts"`
}
type bookmarksResponse struct {
Envelope
Bookmarks struct {
XMLName xml.Name `json:"-" xml:"bookmarks"`
Bookmarks []emptyList `json:"bookmark" xml:"bookmark"`
} `json:"bookmarks" xml:"bookmarks"`
}
type sharesResponse struct {
Envelope
Shares struct {
XMLName xml.Name `json:"-" xml:"shares"`
Shares []emptyList `json:"share" xml:"share"`
} `json:"shares" xml:"shares"`
}
type chatMessagesResponse struct {
Envelope
ChatMessages struct {
XMLName xml.Name `json:"-" xml:"chatMessages"`
Messages []emptyList `json:"chatMessage" xml:"chatMessage"`
} `json:"chatMessages" xml:"chatMessages"`
}
type nowPlayingResponse struct {
Envelope
NowPlaying struct {
XMLName xml.Name `json:"-" xml:"nowPlaying"`
Entries []emptyList `json:"entry" xml:"entry"`
} `json:"nowPlaying" xml:"nowPlaying"`
}
func handleEmptyInternetRadioStations(w http.ResponseWriter, r *http.Request) {
resp := internetRadioStationsResponse{Envelope: NewEnvelope("ok")}
resp.Stations.Stations = []emptyList{}
Write(w, r, resp)
}
func handleEmptyPodcasts(w http.ResponseWriter, r *http.Request) {
resp := podcastsResponse{Envelope: NewEnvelope("ok")}
resp.Podcasts.Channels = []emptyList{}
Write(w, r, resp)
}
func handleEmptyNewestPodcasts(w http.ResponseWriter, r *http.Request) {
resp := NewestpodcastsResponse{Envelope: NewEnvelope("ok")}
resp.NewestPodcasts.Episodes = []emptyList{}
Write(w, r, resp)
}
func handleEmptyBookmarks(w http.ResponseWriter, r *http.Request) {
resp := bookmarksResponse{Envelope: NewEnvelope("ok")}
resp.Bookmarks.Bookmarks = []emptyList{}
Write(w, r, resp)
}
func handleEmptyShares(w http.ResponseWriter, r *http.Request) {
resp := sharesResponse{Envelope: NewEnvelope("ok")}
resp.Shares.Shares = []emptyList{}
Write(w, r, resp)
}
func handleEmptyChatMessages(w http.ResponseWriter, r *http.Request) {
resp := chatMessagesResponse{Envelope: NewEnvelope("ok")}
resp.ChatMessages.Messages = []emptyList{}
Write(w, r, resp)
}
func handleEmptyNowPlaying(w http.ResponseWriter, r *http.Request) {
resp := nowPlayingResponse{Envelope: NewEnvelope("ok")}
resp.NowPlaying.Entries = []emptyList{}
Write(w, r, resp)
}