fix(song): handle empty SNG_CONTRIBUTORS array during unmarshal
This commit is contained in:
+20
-5
@@ -1,22 +1,37 @@
|
|||||||
package deezer
|
package deezer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/flytam/filenamify"
|
"github.com/flytam/filenamify"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Contributors struct {
|
||||||
|
MainArtists []string `json:"main_artist"`
|
||||||
|
Composers []string `json:"composer"`
|
||||||
|
Authors []string `json:"author"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Contributors) UnmarshalJSON(data []byte) error {
|
||||||
|
if string(data) == "[]" {
|
||||||
|
*c = Contributors{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Alias Contributors
|
||||||
|
aux := (*Alias)(c)
|
||||||
|
|
||||||
|
return json.Unmarshal(data, aux)
|
||||||
|
}
|
||||||
|
|
||||||
type Song struct {
|
type Song struct {
|
||||||
ID string `json:"SNG_ID"`
|
ID string `json:"SNG_ID"`
|
||||||
Artist string `json:"ART_NAME"`
|
Artist string `json:"ART_NAME"`
|
||||||
Title string `json:"SNG_TITLE"`
|
Title string `json:"SNG_TITLE"`
|
||||||
Version string `json:"VERSION"`
|
Version string `json:"VERSION"`
|
||||||
Cover string `json:"ALB_PICTURE"`
|
Cover string `json:"ALB_PICTURE"`
|
||||||
Contributors struct {
|
Contributors Contributors `json:"SNG_CONTRIBUTORS"`
|
||||||
MainArtists []string `json:"main_artist"`
|
|
||||||
Composers []string `json:"composer"`
|
|
||||||
Authors []string `json:"author"`
|
|
||||||
} `json:"SNG_CONTRIBUTORS"`
|
|
||||||
Duration string `json:"DURATION"`
|
Duration string `json:"DURATION"`
|
||||||
Gain string `json:"GAIN"`
|
Gain string `json:"GAIN"`
|
||||||
ISRC string `json:"ISRC"`
|
ISRC string `json:"ISRC"`
|
||||||
|
|||||||
Reference in New Issue
Block a user