Skip to content

Commit

Permalink
feat(subsonic): add getOpenSubsonicExtensions endpoint and openSubson…
Browse files Browse the repository at this point in the history
…ic response key
  • Loading branch information
sentriz committed Sep 28, 2023
1 parent e0b1603 commit 2caee44
Show file tree
Hide file tree
Showing 30 changed files with 122 additions and 82 deletions.
6 changes: 6 additions & 0 deletions server/ctrlsubsonic/handlers_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (c *Controller) ServePing(_ *http.Request) *spec.Response {
return spec.NewResponse()
}

func (c *Controller) ServeGetOpenSubsonicExtensions(_ *http.Request) *spec.Response {
sub := spec.NewResponse()
sub.OpenSubsonicExtensions = spec.OpenSubsonicExtensions{}
return sub
}

func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User)
params := r.Context().Value(CtxParams).(params.Params)
Expand Down
4 changes: 3 additions & 1 deletion server/ctrlsubsonic/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ func AddRoutes(c *Controller, r *mux.Router) {

// common
r.Handle("/getLicense{_:(?:\\.view)?}", c.H(c.ServeGetLicence))
r.Handle("/ping{_:(?:\\.view)?}", c.H(c.ServePing))
r.Handle("/getOpenSubsonicExtensions{_:(?:\\.view)?}", c.H(c.ServeGetOpenSubsonicExtensions))

r.Handle("/getMusicFolders{_:(?:\\.view)?}", c.H(c.ServeGetMusicFolders))
r.Handle("/getScanStatus{_:(?:\\.view)?}", c.H(c.ServeGetScanStatus))
r.Handle("/ping{_:(?:\\.view)?}", c.H(c.ServePing))
r.Handle("/scrobble{_:(?:\\.view)?}", c.H(c.ServeScrobble))
r.Handle("/startScan{_:(?:\\.view)?}", c.H(c.ServeStartScan))
r.Handle("/getUser{_:(?:\\.view)?}", c.H(c.ServeGetUser))
Expand Down
9 changes: 7 additions & 2 deletions server/ctrlsubsonic/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ type Response struct {
XMLNS string `xml:"xmlns,attr" json:"-"`

// https://opensubsonic.netlify.app/docs/responses/subsonic-response/
Type string `xml:"type,attr" json:"type"`
ServerVersion string `xml:"serverVersion,attr" json:"serverVersion"`
Type string `xml:"type,attr" json:"type"`
ServerVersion string `xml:"serverVersion,attr" json:"serverVersion"`
OpenSubsonic bool `xml:"openSubsonic,attr" json:"openSubsonic"`
OpenSubsonicExtensions OpenSubsonicExtensions `xml:"openSubsonicExtensions" json:"openSubsonicExtensions,omitempty"`

Error *Error `xml:"error" json:"error,omitempty"`
Albums *Albums `xml:"albumList" json:"albumList,omitempty"`
Expand Down Expand Up @@ -73,6 +75,7 @@ func NewResponse() *Response {
Version: apiVersion,
Type: gonic.Name,
ServerVersion: gonic.Version,
OpenSubsonic: true,
}
}

Expand Down Expand Up @@ -429,6 +432,8 @@ type Lyrics struct {
Title string `xml:"title,attr,omitempty" json:"title,omitempty"`
}

type OpenSubsonicExtensions map[string][]int

func formatRating(rating float64) string {
if rating == 0 {
return ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList": {
"album": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList": {
"album": [
{
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_album_list_newest
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList": {
"album": [
{
Expand Down
79 changes: 40 additions & 39 deletions server/ctrlsubsonic/testdata/test_get_album_list_random
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList": {
"album": [
{
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"id": "al-12",
"coverArt": "al-12",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"title": "album-1",
"album": "",
"parent": "al-2",
"parent": "al-10",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-9",
"coverArt": "al-9",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
Expand All @@ -33,63 +47,63 @@
"duration": 300
},
{
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"id": "al-3",
"coverArt": "al-3",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-6",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"id": "al-8",
"coverArt": "al-8",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"title": "album-1",
"album": "",
"parent": "al-2",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-12",
"coverArt": "al-12",
"artist": "artist-2",
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"title": "album-2",
"album": "",
"parent": "al-10",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-8",
"coverArt": "al-8",
"artist": "artist-1",
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-6",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-9",
"coverArt": "al-9",
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"title": "album-0",
"album": "",
"parent": "al-6",
"isDir": true,
Expand All @@ -109,19 +123,6 @@
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList2": {
"album": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList2": {
"album": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList2": {
"album": [
{
Expand Down
81 changes: 41 additions & 40 deletions server/ctrlsubsonic/testdata/test_get_album_list_two_random
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
"version": "1.15.0",
"type": "gonic",
"serverVersion": "",
"openSubsonic": true,
"albumList2": {
"album": [
{
"id": "al-8",
"coverArt": "al-8",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-11",
"coverArt": "al-11",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
Expand All @@ -35,29 +36,29 @@
"year": 2021
},
{
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"id": "al-12",
"coverArt": "al-12",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
Expand All @@ -77,53 +78,53 @@
"year": 2021
},
{
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"id": "al-4",
"coverArt": "al-4",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"coverArt": "al-13",
"id": "al-11",
"coverArt": "al-11",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-2",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-4",
"coverArt": "al-4",
"id": "al-5",
"coverArt": "al-5",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"name": "album-2",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-12",
"coverArt": "al-12",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"id": "al-8",
"coverArt": "al-8",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
Expand Down
Loading

0 comments on commit 2caee44

Please sign in to comment.