2020-12-25 22:41:04 +08:00
|
|
|
package ncm
|
|
|
|
|
|
|
|
import (
|
2024-11-02 13:44:29 +09:00
|
|
|
"go.uber.org/zap"
|
2020-12-25 22:41:04 +08:00
|
|
|
"strings"
|
2022-11-19 07:44:44 +08:00
|
|
|
|
|
|
|
"unlock-music.dev/cli/algo/common"
|
2020-12-25 22:41:04 +08:00
|
|
|
)
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
type ncmMeta interface {
|
|
|
|
common.AudioMeta
|
|
|
|
|
|
|
|
// GetFormat return the audio format, e.g. mp3, flac
|
2020-12-25 22:41:04 +08:00
|
|
|
GetFormat() string
|
2022-11-22 07:08:10 +08:00
|
|
|
|
|
|
|
// GetAlbumImageURL return the album image url
|
2020-12-25 22:41:04 +08:00
|
|
|
GetAlbumImageURL() string
|
|
|
|
}
|
2022-11-22 07:08:10 +08:00
|
|
|
|
|
|
|
type ncmMetaMusic struct {
|
2024-11-02 13:44:29 +09:00
|
|
|
logger *zap.Logger
|
|
|
|
|
|
|
|
Format string `json:"format"`
|
|
|
|
MusicName string `json:"musicName"`
|
|
|
|
Artist interface{} `json:"artist"`
|
|
|
|
Album string `json:"album"`
|
|
|
|
AlbumPicDocID interface{} `json:"albumPicDocId"`
|
|
|
|
AlbumPic string `json:"albumPic"`
|
|
|
|
Flag int `json:"flag"`
|
|
|
|
Bitrate int `json:"bitrate"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Alias []interface{} `json:"alias"`
|
|
|
|
TransNames []interface{} `json:"transNames"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newNcmMetaMusic(logger *zap.Logger) *ncmMetaMusic {
|
|
|
|
ncm := new(ncmMetaMusic)
|
|
|
|
ncm.logger = logger.With(zap.String("module", "ncmMetaMusic"))
|
|
|
|
return ncm
|
2020-12-25 22:41:04 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaMusic) GetAlbumImageURL() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
return m.AlbumPic
|
|
|
|
}
|
2022-11-22 07:08:10 +08:00
|
|
|
|
2025-08-09 23:58:03 +00:00
|
|
|
|
2024-11-02 13:44:29 +09:00
|
|
|
func (m *ncmMetaMusic) GetArtists() []string {
|
2025-08-09 23:58:03 +00:00
|
|
|
m.logger.Debug("ncm artists raw", zap.Any("artists", m.Artist))
|
|
|
|
var artists []string
|
|
|
|
switch v := m.Artist.(type) {
|
|
|
|
|
|
|
|
// Case 1: Handles the format [['artistA'], ['artistB']]
|
|
|
|
case [][]string:
|
|
|
|
for _, artistSlice := range v {
|
|
|
|
artists = append(artists, artistSlice...)
|
|
|
|
}
|
2024-11-02 13:44:29 +09:00
|
|
|
|
2025-08-09 23:58:03 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
2020-12-25 22:41:04 +08:00
|
|
|
}
|
|
|
|
}
|
2025-08-09 23:58:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// Log a warning if the artist type is unexpected and not handled.
|
2024-11-02 13:44:29 +09:00
|
|
|
m.logger.Warn("unexpected artist type", zap.Any("artists", m.Artist))
|
2020-12-25 22:41:04 +08:00
|
|
|
}
|
2025-08-09 23:58:03 +00:00
|
|
|
|
2024-11-02 13:44:29 +09:00
|
|
|
return artists
|
2020-12-25 22:41:04 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaMusic) GetTitle() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
return m.MusicName
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaMusic) GetAlbum() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
return m.Album
|
|
|
|
}
|
2022-11-22 07:08:10 +08:00
|
|
|
|
|
|
|
func (m *ncmMetaMusic) GetFormat() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
return m.Format
|
|
|
|
}
|
|
|
|
|
2020-12-26 16:07:48 +08:00
|
|
|
//goland:noinspection SpellCheckingInspection
|
2022-11-22 07:08:10 +08:00
|
|
|
type ncmMetaDJ struct {
|
2020-12-25 22:41:04 +08:00
|
|
|
ProgramID int `json:"programId"`
|
|
|
|
ProgramName string `json:"programName"`
|
2022-11-22 07:08:10 +08:00
|
|
|
MainMusic ncmMetaMusic `json:"mainMusic"`
|
2020-12-25 22:41:04 +08:00
|
|
|
DjID int `json:"djId"`
|
|
|
|
DjName string `json:"djName"`
|
|
|
|
DjAvatarURL string `json:"djAvatarUrl"`
|
|
|
|
CreateTime int64 `json:"createTime"`
|
|
|
|
Brand string `json:"brand"`
|
|
|
|
Serial int `json:"serial"`
|
|
|
|
ProgramDesc string `json:"programDesc"`
|
|
|
|
ProgramFeeType int `json:"programFeeType"`
|
|
|
|
ProgramBuyed bool `json:"programBuyed"`
|
|
|
|
RadioID int `json:"radioId"`
|
|
|
|
RadioName string `json:"radioName"`
|
|
|
|
RadioCategory string `json:"radioCategory"`
|
|
|
|
RadioCategoryID int `json:"radioCategoryId"`
|
|
|
|
RadioDesc string `json:"radioDesc"`
|
|
|
|
RadioFeeType int `json:"radioFeeType"`
|
|
|
|
RadioFeeScope int `json:"radioFeeScope"`
|
|
|
|
RadioBuyed bool `json:"radioBuyed"`
|
|
|
|
RadioPrice int `json:"radioPrice"`
|
|
|
|
RadioPurchaseCount int `json:"radioPurchaseCount"`
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaDJ) GetArtists() []string {
|
2020-12-25 22:41:04 +08:00
|
|
|
if m.DjName != "" {
|
|
|
|
return []string{m.DjName}
|
|
|
|
}
|
|
|
|
return m.MainMusic.GetArtists()
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaDJ) GetTitle() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
if m.ProgramName != "" {
|
|
|
|
return m.ProgramName
|
|
|
|
}
|
|
|
|
return m.MainMusic.GetTitle()
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaDJ) GetAlbum() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
if m.Brand != "" {
|
|
|
|
return m.Brand
|
|
|
|
}
|
|
|
|
return m.MainMusic.GetAlbum()
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaDJ) GetFormat() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
return m.MainMusic.GetFormat()
|
|
|
|
}
|
|
|
|
|
2022-11-22 07:08:10 +08:00
|
|
|
func (m *ncmMetaDJ) GetAlbumImageURL() string {
|
2020-12-25 22:41:04 +08:00
|
|
|
if strings.HasPrefix(m.MainMusic.GetAlbumImageURL(), "http") {
|
|
|
|
return m.MainMusic.GetAlbumImageURL()
|
|
|
|
}
|
|
|
|
return m.DjAvatarURL
|
|
|
|
}
|