Initial commit
This commit is contained in:
commit
02a6dabcfb
62 files changed
+15751
No files matched your search
@@ -0,0 +1,138 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// MusicHistory represents music history
|
||||
type MusicHistory struct {
|
||||
BaseModel
|
||||
Tabs []MusicHistoryTab `json:"tabs"`
|
||||
Groups []MusicHistoryGroup `json:"groups"`
|
||||
Items []MusicHistoryItem `json:"items"`
|
||||
Context *MusicHistoryContextFullModel `json:"context"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a MusicHistory from JSON
|
||||
func (mh *MusicHistory) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
history := &MusicHistory{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["tabs"]; ok {
|
||||
var tabs []MusicHistoryTab
|
||||
json.Unmarshal(v, &tabs)
|
||||
history.Tabs = tabs
|
||||
}
|
||||
if v, ok := raw["groups"]; ok {
|
||||
var groups []MusicHistoryGroup
|
||||
json.Unmarshal(v, &groups)
|
||||
history.Groups = groups
|
||||
}
|
||||
if v, ok := raw["items"]; ok {
|
||||
var items []MusicHistoryItem
|
||||
json.Unmarshal(v, &items)
|
||||
history.Items = items
|
||||
}
|
||||
if v, ok := raw["context"]; ok {
|
||||
var context MusicHistoryContextFullModel
|
||||
json.Unmarshal(v, &context)
|
||||
history.Context = &context
|
||||
}
|
||||
|
||||
return history, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of MusicHistory
|
||||
func (mh *MusicHistory) DeList(data []byte, client ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
history := &MusicHistory{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, history); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, history)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// MusicHistoryTab represents a music history tab
|
||||
type MusicHistoryTab struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Active bool `json:"active"`
|
||||
Position int `json:"position"`
|
||||
}
|
||||
|
||||
// MusicHistoryGroup represents a music history group
|
||||
type MusicHistoryGroup struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Items []MusicHistoryItem `json:"items"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// MusicHistoryItem represents a music history item
|
||||
type MusicHistoryItem struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"` // "track", "album", "artist", "playlist"
|
||||
Track *Track `json:"track"`
|
||||
Album *Album `json:"album"`
|
||||
Artist *Artist `json:"artist"`
|
||||
Playlist *Playlist `json:"playlist"`
|
||||
PlayedAt string `json:"played_at"`
|
||||
PlayCount int `json:"play_count"`
|
||||
Duration int `json:"duration"`
|
||||
Context *MusicHistoryItemData `json:"context"`
|
||||
}
|
||||
|
||||
// MusicHistoryItemData represents music history item data
|
||||
type MusicHistoryItemData struct {
|
||||
BaseModel
|
||||
Source string `json:"source"`
|
||||
SourceID string `json:"source_id"`
|
||||
SourceType string `json:"source_type"`
|
||||
PlayContext *PlayContext `json:"play_context"`
|
||||
Position int `json:"position"`
|
||||
Duration int `json:"duration"`
|
||||
Progress float64 `json:"progress"`
|
||||
}
|
||||
|
||||
// MusicHistoryItemID represents music history item ID
|
||||
type MusicHistoryItemID struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// MusicHistoryItems represents music history items
|
||||
type MusicHistoryItems struct {
|
||||
BaseModel
|
||||
Items []MusicHistoryItem `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// MusicHistoryContextFullModel represents music history context full model
|
||||
type MusicHistoryContextFullModel struct {
|
||||
BaseModel
|
||||
DeviceID string `json:"device_id"`
|
||||
SessionID string `json:"session_id"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
ClientInfo string `json:"client_info"`
|
||||
}
|
||||
Reference in new issue
Block a user