Compare commits

..

No commits in common. "589e573b55f4b2d9c50970ebe5f77f1b30ac1e05" and "0a94383ba337e810f24e9dff86544d36281b1d3f" have entirely different histories.

View File

@ -43,42 +43,23 @@ func (m *ncmMetaMusic) GetAlbumImageURL() string {
return m.AlbumPic return m.AlbumPic
} }
func (m *ncmMetaMusic) GetArtists() []string { func (m *ncmMetaMusic) GetArtists() []string {
m.logger.Debug("ncm artists raw", zap.Any("artists", m.Artist)) m.logger.Debug("ncm artists", zap.Any("artists", m.Artist))
var artists []string
switch v := m.Artist.(type) {
// Case 1: Handles the format [['artistA'], ['artistB']] var artists []string = nil
case [][]string: if jsonArtists, ok := m.Artist.([][]string); ok {
for _, artistSlice := range v { for _, artist := range jsonArtists {
artists = append(artists, artistSlice...) for _, name := range artist {
} artists = append(artists, name)
// Case 2: Handles the simple format "artistA"
// Ref: https://git.unlock-music.dev/um/cli/issues/78
case string:
artists = []string{v}
// Case 3: Handles the mixed-type format [['artistA', 12345], ['artistB', 67890]]
// This is the key fix for correctly parsing artist info from certain files.
case []interface{}:
for _, item := range v {
if innerSlice, ok := item.([]interface{}); ok {
if len(innerSlice) > 0 {
// Assume the first element is the artist's name.
if artistName, ok := innerSlice[0].(string); ok {
artists = append(artists, artistName)
}
}
} }
} }
} else if artist, ok := m.Artist.(string); ok {
default: // #78: artist is a string type.
// Log a warning if the artist type is unexpected and not handled. // https://git.unlock-music.dev/um/cli/issues/78
artists = []string{artist}
} else {
m.logger.Warn("unexpected artist type", zap.Any("artists", m.Artist)) m.logger.Warn("unexpected artist type", zap.Any("artists", m.Artist))
} }
return artists return artists
} }