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. 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}}, } // 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) }