fix(song): handle empty SNG_CONTRIBUTORS array during unmarshal
This commit is contained in:
+20
-5
@@ -1,22 +1,37 @@
|
||||
package deezer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"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 {
|
||||
ID string `json:"SNG_ID"`
|
||||
Artist string `json:"ART_NAME"`
|
||||
Title string `json:"SNG_TITLE"`
|
||||
Version string `json:"VERSION"`
|
||||
Cover string `json:"ALB_PICTURE"`
|
||||
Contributors struct {
|
||||
MainArtists []string `json:"main_artist"`
|
||||
Composers []string `json:"composer"`
|
||||
Authors []string `json:"author"`
|
||||
} `json:"SNG_CONTRIBUTORS"`
|
||||
Contributors Contributors `json:"SNG_CONTRIBUTORS"`
|
||||
Duration string `json:"DURATION"`
|
||||
Gain string `json:"GAIN"`
|
||||
ISRC string `json:"ISRC"`
|
||||
|
||||
Reference in New Issue
Block a user