Initial commit
This commit is contained in:
commit
02a6dabcfb
62 files changed
+15751
No files matched your search
@@ -0,0 +1,328 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// RadioStation represents a radio station
|
||||
type RadioStation struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
Genre string `json:"genre"`
|
||||
Available bool `json:"available"`
|
||||
IsPersonal bool `json:"is_personal"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a RadioStation from JSON
|
||||
func (r *RadioStation) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
station := &RadioStation{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &station.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &station.Title)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &station.Description)
|
||||
}
|
||||
if v, ok := raw["cover_uri"]; ok {
|
||||
json.Unmarshal(v, &station.CoverURI)
|
||||
}
|
||||
if v, ok := raw["genre"]; ok {
|
||||
json.Unmarshal(v, &station.Genre)
|
||||
}
|
||||
if v, ok := raw["available"]; ok {
|
||||
json.Unmarshal(v, &station.Available)
|
||||
}
|
||||
if v, ok := raw["is_personal"]; ok {
|
||||
json.Unmarshal(v, &station.IsPersonal)
|
||||
}
|
||||
|
||||
return station, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of RadioStations
|
||||
func (r *RadioStation) 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 {
|
||||
station := &RadioStation{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, station); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, station)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// StationTracksResult represents station tracks result
|
||||
type StationTracksResult struct {
|
||||
BaseModel
|
||||
Tracks []Track `json:"tracks"`
|
||||
Total int `json:"total"`
|
||||
Sequence string `json:"sequence"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes StationTracksResult from JSON
|
||||
func (s *StationTracksResult) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &StationTracksResult{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["tracks"]; ok {
|
||||
var tracks []Track
|
||||
json.Unmarshal(v, &tracks)
|
||||
result.Tracks = tracks
|
||||
}
|
||||
if v, ok := raw["total"]; ok {
|
||||
json.Unmarshal(v, &result.Total)
|
||||
}
|
||||
if v, ok := raw["sequence"]; ok {
|
||||
json.Unmarshal(v, &result.Sequence)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of StationTracksResult
|
||||
func (s *StationTracksResult) 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 {
|
||||
r := &StationTracksResult{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, r); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, r)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RotorStation represents a rotor (generative) station
|
||||
type RotorStation struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
Genre string `json:"genre"`
|
||||
StationType string `json:"station_type"`
|
||||
Available bool `json:"available"`
|
||||
Settings *RotorSettings `json:"settings"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a RotorStation from JSON
|
||||
func (r *RotorStation) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
station := &RotorStation{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &station.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &station.Title)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &station.Description)
|
||||
}
|
||||
if v, ok := raw["cover_uri"]; ok {
|
||||
json.Unmarshal(v, &station.CoverURI)
|
||||
}
|
||||
if v, ok := raw["genre"]; ok {
|
||||
json.Unmarshal(v, &station.Genre)
|
||||
}
|
||||
if v, ok := raw["station_type"]; ok {
|
||||
json.Unmarshal(v, &station.StationType)
|
||||
}
|
||||
if v, ok := raw["available"]; ok {
|
||||
json.Unmarshal(v, &station.Available)
|
||||
}
|
||||
if v, ok := raw["settings"]; ok {
|
||||
var settings RotorSettings
|
||||
json.Unmarshal(v, &settings)
|
||||
station.Settings = &settings
|
||||
}
|
||||
|
||||
return station, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of RotorStations
|
||||
func (r *RotorStation) 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 {
|
||||
station := &RotorStation{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, station); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, station)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RotorSettings represents rotor station settings
|
||||
type RotorSettings struct {
|
||||
BaseModel
|
||||
Diversity float64 `json:"diversity"`
|
||||
Energy float64 `json:"energy"`
|
||||
Acousticness float64 `json:"acousticness"`
|
||||
Instrumentalness float64 `json:"instrumentalness"`
|
||||
Live float64 `json:"live"`
|
||||
Speechiness float64 `json:"speechiness"`
|
||||
Tempo float64 `json:"tempo"`
|
||||
Valence float64 `json:"valence"`
|
||||
}
|
||||
|
||||
// RotorStationTracksResult represents rotor station tracks result
|
||||
type RotorStationTracksResult struct {
|
||||
BaseModel
|
||||
Tracks []Track `json:"tracks"`
|
||||
Total int `json:"total"`
|
||||
Sequence string `json:"sequence"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes RotorStationTracksResult from JSON
|
||||
func (r *RotorStationTracksResult) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &RotorStationTracksResult{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["tracks"]; ok {
|
||||
var tracks []Track
|
||||
json.Unmarshal(v, &tracks)
|
||||
result.Tracks = tracks
|
||||
}
|
||||
if v, ok := raw["total"]; ok {
|
||||
json.Unmarshal(v, &result.Total)
|
||||
}
|
||||
if v, ok := raw["sequence"]; ok {
|
||||
json.Unmarshal(v, &result.Sequence)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of RotorStationTracksResult
|
||||
func (r *RotorStationTracksResult) 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 {
|
||||
r := &RotorStationTracksResult{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, r); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, r)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RotorSession represents a rotor session
|
||||
type RotorSession struct {
|
||||
BaseModel
|
||||
SessionID string `json:"session_id"`
|
||||
StationID string `json:"station_id"`
|
||||
Tracks []Track `json:"tracks"`
|
||||
BatchID string `json:"batch_id"`
|
||||
ExpiresAt string `json:"expires_at"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a RotorSession from JSON
|
||||
func (r *RotorSession) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
session := &RotorSession{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["session_id"]; ok {
|
||||
json.Unmarshal(v, &session.SessionID)
|
||||
}
|
||||
if v, ok := raw["station_id"]; ok {
|
||||
json.Unmarshal(v, &session.StationID)
|
||||
}
|
||||
if v, ok := raw["tracks"]; ok {
|
||||
var tracks []Track
|
||||
json.Unmarshal(v, &tracks)
|
||||
session.Tracks = tracks
|
||||
}
|
||||
if v, ok := raw["batch_id"]; ok {
|
||||
json.Unmarshal(v, &session.BatchID)
|
||||
}
|
||||
if v, ok := raw["expires_at"]; ok {
|
||||
json.Unmarshal(v, &session.ExpiresAt)
|
||||
}
|
||||
if v, ok := raw["created_at"]; ok {
|
||||
json.Unmarshal(v, &session.CreatedAt)
|
||||
}
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of RotorSessions
|
||||
func (r *RotorSession) 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 {
|
||||
session := &RotorSession{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, session); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, session)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SessionFeedback represents session feedback
|
||||
type SessionFeedback struct {
|
||||
BaseModel
|
||||
TrackID string `json:"track_id"`
|
||||
Feedback string `json:"feedback"` // "like", "dislike", "skip"
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
// SessionFeedbacks represents multiple session feedbacks
|
||||
type SessionFeedbacks struct {
|
||||
BaseModel
|
||||
Feedbacks []SessionFeedback `json:"feedbacks"`
|
||||
}
|
||||
Reference in new issue
Block a user