1
0
forked from um/cli
cli/algo/ncm/meta.go

118 lines
3.1 KiB
Go
Raw Permalink Normal View History

2020-12-25 14:41:04 +00:00
package ncm
import (
"strings"
2022-11-18 23:44:44 +00:00
"unlock-music.dev/cli/algo/common"
2020-12-25 14:41:04 +00:00
)
2022-11-21 23:08:10 +00:00
type ncmMeta interface {
common.AudioMeta
// GetFormat return the audio format, e.g. mp3, flac
2020-12-25 14:41:04 +00:00
GetFormat() string
2022-11-21 23:08:10 +00:00
// GetAlbumImageURL return the album image url
2020-12-25 14:41:04 +00:00
GetAlbumImageURL() string
}
2022-11-21 23:08:10 +00:00
type ncmMetaMusic struct {
2020-12-25 14:41:04 +00:00
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"`
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaMusic) GetAlbumImageURL() string {
2020-12-25 14:41:04 +00:00
return m.AlbumPic
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaMusic) GetArtists() (artists []string) {
2020-12-25 14:41:04 +00:00
for _, artist := range m.Artist {
for _, item := range artist {
name, ok := item.(string)
if ok {
artists = append(artists, name)
}
}
}
return
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaMusic) GetTitle() string {
2020-12-25 14:41:04 +00:00
return m.MusicName
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaMusic) GetAlbum() string {
2020-12-25 14:41:04 +00:00
return m.Album
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaMusic) GetFormat() string {
2020-12-25 14:41:04 +00:00
return m.Format
}
//goland:noinspection SpellCheckingInspection
2022-11-21 23:08:10 +00:00
type ncmMetaDJ struct {
2020-12-25 14:41:04 +00:00
ProgramID int `json:"programId"`
ProgramName string `json:"programName"`
2022-11-21 23:08:10 +00:00
MainMusic ncmMetaMusic `json:"mainMusic"`
2020-12-25 14:41:04 +00: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-21 23:08:10 +00:00
func (m *ncmMetaDJ) GetArtists() []string {
2020-12-25 14:41:04 +00:00
if m.DjName != "" {
return []string{m.DjName}
}
return m.MainMusic.GetArtists()
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaDJ) GetTitle() string {
2020-12-25 14:41:04 +00:00
if m.ProgramName != "" {
return m.ProgramName
}
return m.MainMusic.GetTitle()
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaDJ) GetAlbum() string {
2020-12-25 14:41:04 +00:00
if m.Brand != "" {
return m.Brand
}
return m.MainMusic.GetAlbum()
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaDJ) GetFormat() string {
2020-12-25 14:41:04 +00:00
return m.MainMusic.GetFormat()
}
2022-11-21 23:08:10 +00:00
func (m *ncmMetaDJ) GetAlbumImageURL() string {
2020-12-25 14:41:04 +00:00
if strings.HasPrefix(m.MainMusic.GetAlbumImageURL(), "http") {
return m.MainMusic.GetAlbumImageURL()
}
return m.DjAvatarURL
}