Add discTitles to OpenSubsonic responses
This commit is contained in:
+10
@@ -21,6 +21,16 @@
|
||||
"musicBrainzId": "1234",
|
||||
"isCompilation": true,
|
||||
"sortName": "sorted album",
|
||||
"discTitles": [
|
||||
{
|
||||
"disc": 1,
|
||||
"title": "disc 1"
|
||||
},
|
||||
{
|
||||
"disc": 2,
|
||||
"title": "disc 2"
|
||||
}
|
||||
],
|
||||
"song": [
|
||||
{
|
||||
"id": "1",
|
||||
|
||||
+2
@@ -2,6 +2,8 @@
|
||||
<album id="1" name="album" artist="artist" genre="rock" userRating="0" musicBrainzId="1234" isCompilation="true" sortName="sorted album">
|
||||
<genres name="rock"></genres>
|
||||
<genres name="progressive"></genres>
|
||||
<discTitles disc="1" title="disc 1"></discTitles>
|
||||
<discTitles disc="2" title="disc 2"></discTitles>
|
||||
<song id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" starred="2016-03-02T20:30:00Z" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320" isVideo="false" bpm="127" comment="a comment" sortName="sorted song" mediaType="song" musicBrainzId="4321">
|
||||
<genres name="rock"></genres>
|
||||
<genres name="progressive"></genres>
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@
|
||||
"genres": [],
|
||||
"musicBrainzId": "",
|
||||
"isCompilation": false,
|
||||
"sortName": ""
|
||||
"sortName": "",
|
||||
"discTitles": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@ type AlbumID3 struct {
|
||||
MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"`
|
||||
IsCompilation bool `xml:"isCompilation,attr" json:"isCompilation"`
|
||||
SortName string `xml:"sortName,attr" json:"sortName"`
|
||||
DiscTitles DiscTitles `xml:"discTitles" json:"discTitles"`
|
||||
}
|
||||
|
||||
type ArtistWithAlbumsID3 struct {
|
||||
@@ -459,12 +460,7 @@ type ItemGenre struct {
|
||||
type ItemGenres []ItemGenre
|
||||
|
||||
func (i ItemGenres) MarshalJSON() ([]byte, error) {
|
||||
if len(i) == 0 {
|
||||
return json.Marshal([]ItemGenre{})
|
||||
}
|
||||
type Alias []ItemGenre
|
||||
a := (Alias)(i)
|
||||
return json.Marshal(a)
|
||||
return marshalJSONArray(i)
|
||||
}
|
||||
|
||||
type ReplayGain struct {
|
||||
@@ -475,3 +471,24 @@ type ReplayGain struct {
|
||||
BaseGain float64 `xml:"baseGain,omitempty,attr" json:"baseGain,omitempty"`
|
||||
FallbackGain float64 `xml:"fallbackGain,omitempty,attr" json:"fallbackGain,omitempty"`
|
||||
}
|
||||
|
||||
type DiscTitle struct {
|
||||
Disc int `xml:"disc,attr,omitempty" json:"disc,omitempty"`
|
||||
Title string `xml:"title,attr,omitempty" json:"title,omitempty"`
|
||||
}
|
||||
|
||||
type DiscTitles []DiscTitle
|
||||
|
||||
func (d DiscTitles) MarshalJSON() ([]byte, error) {
|
||||
return marshalJSONArray(d)
|
||||
}
|
||||
|
||||
// marshalJSONArray marshals a slice of any type to JSON. If the slice is empty, it is marshalled as an
|
||||
// empty array instead of null.
|
||||
func marshalJSONArray[T any](v []T) ([]byte, error) {
|
||||
if len(v) == 0 {
|
||||
return json.Marshal([]T{})
|
||||
}
|
||||
a := v
|
||||
return json.Marshal(a)
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ var _ = Describe("Responses", func() {
|
||||
Id: "1", Name: "album", Artist: "artist", Genre: "rock",
|
||||
Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}},
|
||||
MusicBrainzId: "1234", IsCompilation: true, SortName: "sorted album",
|
||||
DiscTitles: DiscTitles{{Disc: 1, Title: "disc 1"}, {Disc: 2, Title: "disc 2"}},
|
||||
}
|
||||
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
||||
songs := []Child{{
|
||||
|
||||
Reference in New Issue
Block a user