feat: add subsonic library discovery endpoints

This commit is contained in:
2026-04-03 21:07:58 +03:00
parent 480bdc2476
commit ad9543bf7a
3 changed files with 189 additions and 10 deletions

View File

@@ -21,12 +21,18 @@ type Response struct {
Artists []ArtistRef `json:"artists,omitempty"`
Artist *ArtistFull `json:"artist,omitempty"`
Album *AlbumFull `json:"album,omitempty"`
AlbumList2 *AlbumList2 `json:"albumList2,omitempty"`
Song *SongFull `json:"song,omitempty"`
RandomSong []SongRef `json:"randomSongs,omitempty"`
SearchResult3 *SearchResult3 `json:"searchResult3,omitempty"`
Starred2 *Starred2 `json:"starred2,omitempty"`
Playlists *Playlists `json:"playlists,omitempty"`
Playlist *Playlist `json:"playlist,omitempty"`
MusicFolders *MusicFolders `json:"musicFolders,omitempty"`
Genres *Genres `json:"genres,omitempty"`
Podcasts *Podcasts `json:"podcasts,omitempty"`
NewestPods *NewestPods `json:"newestPodcasts,omitempty"`
RadioStations *RadioStations `json:"internetRadioStations,omitempty"`
ScanStatus *ScanStatus `json:"scanStatus,omitempty"`
Error *ErrorRef `json:"error,omitempty"`
}
@@ -73,6 +79,10 @@ type AlbumFull struct {
Song []SongRef `json:"song,omitempty"`
}
type AlbumList2 struct {
Album []AlbumRef `json:"album,omitempty"`
}
type SongFull struct {
ID string `json:"id"`
Title string `json:"title"`
@@ -134,6 +144,37 @@ type PlaylistSummary struct {
Changed string `json:"changed,omitempty"`
}
type MusicFolders struct {
MusicFolder []MusicFolder `json:"musicFolder,omitempty"`
}
type MusicFolder struct {
ID string `json:"id"`
Name string `json:"name"`
}
type Genres struct {
Genre []Genre `json:"genre,omitempty"`
}
type Genre struct {
Value string `json:"value"`
AlbumCount int `json:"albumCount,omitempty"`
SongCount int `json:"songCount,omitempty"`
}
type Podcasts struct {
Channel []any `json:"channel,omitempty"`
}
type NewestPods struct {
Episode []any `json:"episode,omitempty"`
}
type RadioStations struct {
InternetRadioStation []any `json:"internetRadioStation,omitempty"`
}
type ErrorRef struct {
Code int `json:"code"`
Message string `json:"message"`
@@ -337,6 +378,23 @@ func AlbumResponse(album library.AlbumDetail) Envelope {
return response
}
func AlbumList2Response(albums []library.Album) Envelope {
response := PingResponse()
payload := &AlbumList2{}
for _, album := range albums {
payload.Album = append(payload.Album, AlbumRef{
ID: album.ID,
Name: album.Title,
Artist: album.ArtistName,
ArtistID: album.ArtistID,
Year: album.Year,
CoverArt: album.CoverArtID,
})
}
response.SubsonicResponse.AlbumList2 = payload
return response
}
func SongResponse(track library.Track) Envelope {
response := PingResponse()
response.SubsonicResponse.Song = &SongFull{
@@ -366,6 +424,46 @@ func ScanStatusResponse(status scanner.Status) Envelope {
return response
}
func MusicFoldersResponse() Envelope {
response := PingResponse()
response.SubsonicResponse.MusicFolders = &MusicFolders{
MusicFolder: []MusicFolder{{ID: "1", Name: "Music"}},
}
return response
}
func GenresResponse(genres []library.GenreSummary) Envelope {
response := PingResponse()
payload := &Genres{}
for _, genre := range genres {
payload.Genre = append(payload.Genre, Genre{
Value: genre.Value,
AlbumCount: genre.AlbumCount,
SongCount: genre.SongCount,
})
}
response.SubsonicResponse.Genres = payload
return response
}
func PodcastsResponse() Envelope {
response := PingResponse()
response.SubsonicResponse.Podcasts = &Podcasts{}
return response
}
func NewestPodcastsResponse() Envelope {
response := PingResponse()
response.SubsonicResponse.NewestPods = &NewestPods{}
return response
}
func InternetRadioStationsResponse() Envelope {
response := PingResponse()
response.SubsonicResponse.RadioStations = &RadioStations{}
return response
}
func ErrorResponse(code int, message string) Envelope {
response := PingResponse()
response.SubsonicResponse.Status = "failed"