sonda/internal/opensubsonic/response.go
tgiachi d6064763e7 fix: OpenSubsonic apps can log in: getUser and the calls that follow
Feishin asks getUser right after the login and failed on the missing user. getUser
now says who the login is, with the roles of an app (play, download, playlists,
covers; never admin), and only about the person of the login.

Also answered with nothing, because apps ask them straight away: getArtistInfo(2),
getAlbumInfo(2), getTopSongs, getSimilarSongs(2), getLyrics, getLyricsBySongId,
getInternetRadioStations, getScanStatus, startScan and the play queue calls, and
getStarred, the older way to ask for the favourites.

A call that is not known is now in the server log with its name.
2026-11-16 11:50:44 +01:00

282 lines
13 KiB
Go

package opensubsonic
import "encoding/xml"
// The answer of every call is one Response, written as JSON or as XML: the same tree has the tags of both. In XML
// the plain values are attributes and the lists are child elements; in JSON everything is a field and the lists are
// arrays. A field that is not set is left out of both.
// APIVersion is the Subsonic API that is spoken.
const APIVersion = "1.16.1"
// Response is the envelope of an answer.
type Response struct {
XMLName xml.Name `xml:"subsonic-response" json:"-"`
Xmlns string `xml:"xmlns,attr" json:"-"`
Status string `xml:"status,attr" json:"status"`
Version string `xml:"version,attr" json:"version"`
Type string `xml:"type,attr" json:"type"`
ServerVersion string `xml:"serverVersion,attr" json:"serverVersion"`
OpenSubsonic bool `xml:"openSubsonic,attr" json:"openSubsonic"`
Error *Error `xml:"error" json:"error,omitempty"`
License *License `xml:"license" json:"license,omitempty"`
OpenSubsonicExtensions []Extension `xml:"openSubsonicExtensions" json:"openSubsonicExtensions,omitempty"`
TokenInfo *TokenInfo `xml:"tokenInfo" json:"tokenInfo,omitempty"`
MusicFolders *MusicFolders `xml:"musicFolders" json:"musicFolders,omitempty"`
Artists *ArtistsID3 `xml:"artists" json:"artists,omitempty"`
Artist *ArtistWithAlbums `xml:"artist" json:"artist,omitempty"`
Album *AlbumWithSongs `xml:"album" json:"album,omitempty"`
Song *Child `xml:"song" json:"song,omitempty"`
Genres *Genres `xml:"genres" json:"genres,omitempty"`
AlbumList2 *AlbumList2 `xml:"albumList2" json:"albumList2,omitempty"`
RandomSongs *SongList `xml:"randomSongs" json:"randomSongs,omitempty"`
SongsByGenre *SongList `xml:"songsByGenre" json:"songsByGenre,omitempty"`
SearchResult3 *SearchResult `xml:"searchResult3" json:"searchResult3,omitempty"`
Starred2 *SearchResult `xml:"starred2" json:"starred2,omitempty"`
Starred *SearchResult `xml:"starred" json:"starred,omitempty"`
LyricsList *Empty `xml:"lyricsList" json:"lyricsList,omitempty"`
Lyrics *Empty `xml:"lyrics" json:"lyrics,omitempty"`
Playlists *PlaylistList `xml:"playlists" json:"playlists,omitempty"`
Playlist *Playlist `xml:"playlist" json:"playlist,omitempty"`
NowPlaying *NowPlaying `xml:"nowPlaying" json:"nowPlaying,omitempty"`
User *User `xml:"user" json:"user,omitempty"`
ArtistInfo *Empty `xml:"artistInfo" json:"artistInfo,omitempty"`
ArtistInfo2 *Empty `xml:"artistInfo2" json:"artistInfo2,omitempty"`
AlbumInfo *Empty `xml:"albumInfo" json:"albumInfo,omitempty"`
TopSongs *Empty `xml:"topSongs" json:"topSongs,omitempty"`
SimilarSongs *Empty `xml:"similarSongs" json:"similarSongs,omitempty"`
SimilarSongs2 *Empty `xml:"similarSongs2" json:"similarSongs2,omitempty"`
InternetRadioStations *Empty `xml:"internetRadioStations" json:"internetRadioStations,omitempty"`
ScanStatus *ScanStatus `xml:"scanStatus" json:"scanStatus,omitempty"`
}
// Empty is an answer that has nothing in it: Sonda has no such thing to tell, and an app should not break for it.
type Empty struct{}
// ScanStatus says whether the library is being scanned. Apps ask it to show a progress bar; Sonda scans in
// the background and tells admins, not apps.
type ScanStatus struct {
Scanning bool `xml:"scanning,attr" json:"scanning"`
}
// User is the person of a login, and what the app may do for them.
type User struct {
Username string `xml:"username,attr" json:"username"`
Email string `xml:"email,attr,omitempty" json:"email,omitempty"`
ScrobblingEnabled bool `xml:"scrobblingEnabled,attr" json:"scrobblingEnabled"`
AdminRole bool `xml:"adminRole,attr" json:"adminRole"`
SettingsRole bool `xml:"settingsRole,attr" json:"settingsRole"`
DownloadRole bool `xml:"downloadRole,attr" json:"downloadRole"`
UploadRole bool `xml:"uploadRole,attr" json:"uploadRole"`
PlaylistRole bool `xml:"playlistRole,attr" json:"playlistRole"`
CoverArtRole bool `xml:"coverArtRole,attr" json:"coverArtRole"`
CommentRole bool `xml:"commentRole,attr" json:"commentRole"`
PodcastRole bool `xml:"podcastRole,attr" json:"podcastRole"`
StreamRole bool `xml:"streamRole,attr" json:"streamRole"`
JukeboxRole bool `xml:"jukeboxRole,attr" json:"jukeboxRole"`
ShareRole bool `xml:"shareRole,attr" json:"shareRole"`
VideoConversionRole bool `xml:"videoConversionRole,attr" json:"videoConversionRole"`
Folder []int64 `xml:"folder" json:"folder"`
}
// PlaylistList are the playlists of a person.
type PlaylistList struct {
Playlist []Playlist `xml:"playlist" json:"playlist,omitempty"`
}
// Playlist is a playlist; Entry holds its songs when it is opened.
type Playlist struct {
ID string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
Comment string `xml:"comment,attr,omitempty" json:"comment,omitempty"`
Owner string `xml:"owner,attr,omitempty" json:"owner,omitempty"`
Public bool `xml:"public,attr" json:"public"`
SongCount int `xml:"songCount,attr" json:"songCount"`
Duration int `xml:"duration,attr" json:"duration"`
Created string `xml:"created,attr" json:"created"`
Changed string `xml:"changed,attr" json:"changed"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Entry []Child `xml:"entry" json:"entry,omitempty"`
}
// NowPlaying is what is being played now. Sonda tells nobody what a person plays, so it is always empty.
type NowPlaying struct {
Entry []Child `xml:"entry" json:"entry,omitempty"`
}
// AlbumList2 is a list of albums.
type AlbumList2 struct {
Album []AlbumID3 `xml:"album" json:"album,omitempty"`
}
// SongList is a list of songs.
type SongList struct {
Song []Child `xml:"song" json:"song,omitempty"`
}
// SearchResult is what a search found: artists, albums and songs. The starred things have the same shape.
type SearchResult struct {
Artist []ArtistID3 `xml:"artist" json:"artist,omitempty"`
Album []AlbumID3 `xml:"album" json:"album,omitempty"`
Song []Child `xml:"song" json:"song,omitempty"`
}
// Error codes of the Subsonic API.
const (
ErrGeneric = 0
ErrMissingParam = 10
ErrWrongLogin = 40
ErrAuthConflict = 43
ErrBadAPIKey = 44
ErrNotAuthorized = 50
ErrNotFound = 70
errUnsupportedAuth = 42
)
// Error is the reason a call failed.
type Error struct {
Code int `xml:"code,attr" json:"code"`
Message string `xml:"message,attr,omitempty" json:"message,omitempty"`
}
// License says the server is licensed: it always is.
type License struct {
Valid bool `xml:"valid,attr" json:"valid"`
}
// Extension is an OpenSubsonic extension that the server speaks.
type Extension struct {
Name string `xml:"name,attr" json:"name"`
Versions []int `xml:"versions" json:"versions"`
}
// TokenInfo says whose the login of the call is.
type TokenInfo struct {
Username string `xml:"username,attr" json:"username"`
}
// MusicFolders are the libraries.
type MusicFolders struct {
MusicFolder []MusicFolder `xml:"musicFolder" json:"musicFolder"`
}
// MusicFolder is one library.
type MusicFolder struct {
ID int64 `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
}
// ArtistsID3 are the artists, in groups by their first letter.
type ArtistsID3 struct {
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
Index []Index `xml:"index" json:"index"`
}
// Index is the artists whose name starts with one letter.
type Index struct {
Name string `xml:"name,attr" json:"name"`
Artist []ArtistID3 `xml:"artist" json:"artist"`
}
// ArtistID3 is an artist.
type ArtistID3 struct {
ID string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
}
// ArtistWithAlbums is an artist and its albums.
type ArtistWithAlbums struct {
ArtistID3
Album []AlbumID3 `xml:"album" json:"album,omitempty"`
}
// ArtistRef is an artist credited on a song or an album, in the OpenSubsonic fields.
type ArtistRef struct {
ID string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
}
// ItemGenre is a genre of a song or an album, in the OpenSubsonic fields.
type ItemGenre struct {
Name string `xml:"name,attr" json:"name"`
}
// AlbumID3 is an album.
type AlbumID3 struct {
ID string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
ArtistID string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
SongCount int `xml:"songCount,attr" json:"songCount"`
Duration int `xml:"duration,attr" json:"duration"`
Created string `xml:"created,attr" json:"created"`
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
DisplayArtist string `xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"`
Artists []ArtistRef `xml:"artists" json:"artists,omitempty"`
Genres []ItemGenre `xml:"genres" json:"genres,omitempty"`
}
// AlbumWithSongs is an album and its songs.
type AlbumWithSongs struct {
AlbumID3
Song []Child `xml:"song" json:"song,omitempty"`
}
// ReplayGain is how loud a song is, as its file says.
type ReplayGain struct {
TrackGain *float64 `xml:"trackGain,attr,omitempty" json:"trackGain,omitempty"`
AlbumGain *float64 `xml:"albumGain,attr,omitempty" json:"albumGain,omitempty"`
TrackPeak *float64 `xml:"trackPeak,attr,omitempty" json:"trackPeak,omitempty"`
AlbumPeak *float64 `xml:"albumPeak,attr,omitempty" json:"albumPeak,omitempty"`
}
// Child is a song.
type Child struct {
ID string `xml:"id,attr" json:"id"`
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
IsDir bool `xml:"isDir,attr" json:"isDir"`
Title string `xml:"title,attr" json:"title"`
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Size int64 `xml:"size,attr,omitempty" json:"size,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
Created string `xml:"created,attr,omitempty" json:"created,omitempty"`
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
AlbumID string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
ArtistID string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
MediaType string `xml:"mediaType,attr,omitempty" json:"mediaType,omitempty"`
IsVideo bool `xml:"isVideo,attr" json:"isVideo"`
DisplayArtist string `xml:"displayArtist,attr,omitempty" json:"displayArtist,omitempty"`
Artists []ArtistRef `xml:"artists" json:"artists,omitempty"`
Genres []ItemGenre `xml:"genres" json:"genres,omitempty"`
ReplayGain *ReplayGain `xml:"replayGain" json:"replayGain,omitempty"`
}
// Genres are the genres of the music.
type Genres struct {
Genre []GenreEntry `xml:"genre" json:"genre"`
}
// GenreEntry is a genre, with how many songs and albums have it.
type GenreEntry struct {
Value string `xml:",chardata" json:"value"`
SongCount int `xml:"songCount,attr" json:"songCount"`
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
}