Models added: - Disclaimer, ForeignAgent (credits.go) - ArtistConcerts (concert.go) - Dashboard, StationResult, Station, AdParams, GenerativeStream, GenerativeStreamData, GenerativeStreamInfo (radio.go) - FileInfo, FileDownloadInfo, TrackFullInfo, SimilarTracks, TrackTrailer (track.go) - Removed duplicate AdParams from feed.go Client methods added: - artists.go: GetArtistBriefInfo, GetArtistSimilar, GetArtistLinks, GetArtistAlsoAlbums, GetArtistDiscographyAlbums, GetArtistSafeDirectAlbums, GetArtistTrackIds, GetArtistAbout, GetArtistDonation, GetArtistInfo, GetArtistSkeleton, GetArtistTrailer - albums.go: GetAlbumSimilarEntities, GetAlbumTrailer - clips.go: GetClipsDisclaimer - concerts.go: GetArtistConcerts, GetConcertSkeleton - radio.go: GetRotorStationsDashboard, GetRotorStationsList, GetRotorStationInfo, GetRotorStationStream, GetRotorStationSettings - supplements.go: GetTracksCredits, GetClipsCredits - queue.go: GetQueuesList - tracks.go: GetTracksFileInfo, GetTracksSimilar, GetTrackTrailer, GetTrackFullInfo
721 lines
19 KiB
Go
721 lines
19 KiB
Go
// Package models provides data models for the Yandex Music API.
|
|
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// RadioStation represents a radio station from the Yandex Music API.
|
|
type RadioStation struct {
|
|
BaseModel
|
|
ID JSONID `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 data.
|
|
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 from JSON data.
|
|
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 data.
|
|
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 from JSON data.
|
|
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 JSONID `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 data.
|
|
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 from JSON data.
|
|
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
|
|
Language string `json:"language"`
|
|
Diversity string `json:"diversity"`
|
|
Mood int `json:"mood"`
|
|
Energy int `json:"energy"`
|
|
MoodEnergy string `json:"mood_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 data.
|
|
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 from JSON data.
|
|
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 data.
|
|
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 from JSON data.
|
|
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
|
|
}
|
|
|
|
// AdParams represents ad parameters.
|
|
type AdParams struct {
|
|
BaseModel
|
|
PartnerID string `json:"partner_id"`
|
|
CategoryID string `json:"category_id"`
|
|
PageRef string `json:"page_ref"`
|
|
TargetRef string `json:"target_ref"`
|
|
OtherParams string `json:"other_params"`
|
|
GenreID string `json:"genre_id"`
|
|
GenreName string `json:"genre_name"`
|
|
}
|
|
|
|
// DeJSON deserializes AdParams from JSON data.
|
|
func (ap *AdParams) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
params := &AdParams{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["partner_id"]; ok {
|
|
json.Unmarshal(v, ¶ms.PartnerID)
|
|
}
|
|
if v, ok := raw["category_id"]; ok {
|
|
json.Unmarshal(v, ¶ms.CategoryID)
|
|
}
|
|
if v, ok := raw["page_ref"]; ok {
|
|
json.Unmarshal(v, ¶ms.PageRef)
|
|
}
|
|
if v, ok := raw["target_ref"]; ok {
|
|
json.Unmarshal(v, ¶ms.TargetRef)
|
|
}
|
|
if v, ok := raw["other_params"]; ok {
|
|
json.Unmarshal(v, ¶ms.OtherParams)
|
|
}
|
|
if v, ok := raw["genre_id"]; ok {
|
|
json.Unmarshal(v, ¶ms.GenreID)
|
|
}
|
|
if v, ok := raw["genre_name"]; ok {
|
|
json.Unmarshal(v, ¶ms.GenreName)
|
|
}
|
|
|
|
return params, nil
|
|
}
|
|
|
|
// DeList deserializes a list of AdParams from JSON data.
|
|
func (ap *AdParams) DeList(data []byte, c 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 {
|
|
params := &AdParams{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, params); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, params)
|
|
}
|
|
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"`
|
|
}
|
|
|
|
// Dashboard represents rotor stations dashboard.
|
|
type Dashboard struct {
|
|
BaseModel
|
|
DashboardID string `json:"dashboard_id"`
|
|
Stations []StationResult `json:"stations"`
|
|
Pumpkin bool `json:"pumpkin"`
|
|
}
|
|
|
|
// DeJSON deserializes Dashboard from JSON data.
|
|
func (d *Dashboard) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
dashboard := &Dashboard{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["dashboard_id"]; ok {
|
|
json.Unmarshal(v, &dashboard.DashboardID)
|
|
}
|
|
if v, ok := raw["stations"]; ok {
|
|
var stations []StationResult
|
|
json.Unmarshal(v, &stations)
|
|
dashboard.Stations = stations
|
|
}
|
|
if v, ok := raw["pumpkin"]; ok {
|
|
json.Unmarshal(v, &dashboard.Pumpkin)
|
|
}
|
|
|
|
return dashboard, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Dashboards from JSON data.
|
|
func (d *Dashboard) DeList(data []byte, c 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 {
|
|
dashboard := &Dashboard{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, dashboard); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, dashboard)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// StationResult represents a station result.
|
|
type StationResult struct {
|
|
BaseModel
|
|
Station *Station `json:"station"`
|
|
Settings *RotorSettings `json:"settings"`
|
|
Settings2 *RotorSettings `json:"settings2"`
|
|
AdParams *AdParams `json:"ad_params"`
|
|
}
|
|
|
|
// DeJSON deserializes StationResult from JSON data.
|
|
func (sr *StationResult) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := &StationResult{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["station"]; ok {
|
|
var station Station
|
|
json.Unmarshal(v, &station)
|
|
result.Station = &station
|
|
}
|
|
if v, ok := raw["settings"]; ok {
|
|
var settings RotorSettings
|
|
json.Unmarshal(v, &settings)
|
|
result.Settings = &settings
|
|
}
|
|
if v, ok := raw["settings2"]; ok {
|
|
var settings2 RotorSettings
|
|
json.Unmarshal(v, &settings2)
|
|
result.Settings2 = &settings2
|
|
}
|
|
if v, ok := raw["ad_params"]; ok {
|
|
var adParams AdParams
|
|
json.Unmarshal(v, &adParams)
|
|
result.AdParams = &adParams
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// DeList deserializes a list of StationResults from JSON data.
|
|
func (sr *StationResult) DeList(data []byte, c 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 {
|
|
sr := &StationResult{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, sr); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, sr)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// GenerativeStream represents a generative stream.
|
|
type GenerativeStream struct {
|
|
BaseModel
|
|
Data *GenerativeStreamData `json:"data"`
|
|
Version string `json:"version"`
|
|
Stream *GenerativeStreamInfo `json:"stream"`
|
|
}
|
|
|
|
// DeJSON deserializes GenerativeStream from JSON data.
|
|
func (gs *GenerativeStream) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stream := &GenerativeStream{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["data"]; ok {
|
|
var data GenerativeStreamData
|
|
json.Unmarshal(v, &data)
|
|
stream.Data = &data
|
|
}
|
|
if v, ok := raw["version"]; ok {
|
|
json.Unmarshal(v, &stream.Version)
|
|
}
|
|
if v, ok := raw["stream"]; ok {
|
|
var streamInfo GenerativeStreamInfo
|
|
json.Unmarshal(v, &streamInfo)
|
|
stream.Stream = &streamInfo
|
|
}
|
|
|
|
return stream, nil
|
|
}
|
|
|
|
// DeList deserializes a list of GenerativeStreams from JSON data.
|
|
func (gs *GenerativeStream) DeList(data []byte, c 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 {
|
|
stream := &GenerativeStream{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, stream); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, stream)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// Station represents a radio station (used in StationResult).
|
|
type Station struct {
|
|
BaseModel
|
|
ID JSONID `json:"id"`
|
|
Name string `json:"name"`
|
|
Icon string `json:"icon"`
|
|
IDForFrom string `json:"id_for_from"`
|
|
}
|
|
|
|
// DeJSON deserializes Station from JSON data.
|
|
func (s *Station) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
station := &Station{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &station.ID)
|
|
}
|
|
if v, ok := raw["name"]; ok {
|
|
json.Unmarshal(v, &station.Name)
|
|
}
|
|
if v, ok := raw["icon"]; ok {
|
|
json.Unmarshal(v, &station.Icon)
|
|
}
|
|
if v, ok := raw["id_for_from"]; ok {
|
|
json.Unmarshal(v, &station.IDForFrom)
|
|
}
|
|
|
|
return station, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Stations from JSON data.
|
|
func (s *Station) DeList(data []byte, c 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 := &Station{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, station); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, station)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// GenerativeStreamData represents generative stream data.
|
|
type GenerativeStreamData struct {
|
|
BaseModel
|
|
Title string `json:"title"`
|
|
Subtitle string `json:"subtitle"`
|
|
BackgroundColor string `json:"background_color"`
|
|
DerivedColors *CoverDerivedColors `json:"derived_colors"`
|
|
ImageURL string `json:"image_url"`
|
|
VideoCoverURI string `json:"video_cover_uri"`
|
|
Explanations string `json:"explanations"`
|
|
}
|
|
|
|
// DeJSON deserializes GenerativeStreamData from JSON data.
|
|
func (gsd *GenerativeStreamData) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gsdData := &GenerativeStreamData{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &gsdData.Title)
|
|
}
|
|
if v, ok := raw["subtitle"]; ok {
|
|
json.Unmarshal(v, &gsdData.Subtitle)
|
|
}
|
|
if v, ok := raw["background_color"]; ok {
|
|
json.Unmarshal(v, &gsdData.BackgroundColor)
|
|
}
|
|
if v, ok := raw["derived_colors"]; ok {
|
|
var dc CoverDerivedColors
|
|
json.Unmarshal(v, &dc)
|
|
gsdData.DerivedColors = &dc
|
|
}
|
|
if v, ok := raw["image_url"]; ok {
|
|
json.Unmarshal(v, &gsdData.ImageURL)
|
|
}
|
|
if v, ok := raw["video_cover_uri"]; ok {
|
|
json.Unmarshal(v, &gsdData.VideoCoverURI)
|
|
}
|
|
if v, ok := raw["explanations"]; ok {
|
|
json.Unmarshal(v, &gsdData.Explanations)
|
|
}
|
|
|
|
return gsdData, nil
|
|
}
|
|
|
|
// DeList deserializes a list of GenerativeStreamData from JSON data.
|
|
func (gsd *GenerativeStreamData) DeList(data []byte, c 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 {
|
|
data := &GenerativeStreamData{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, data); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, data)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// GenerativeStreamInfo represents generative stream info.
|
|
type GenerativeStreamInfo struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
// DeJSON deserializes GenerativeStreamInfo from JSON data.
|
|
func (gsi *GenerativeStreamInfo) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := &GenerativeStreamInfo{BaseModel: *NewBaseModel(c)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &info.ID)
|
|
}
|
|
if v, ok := raw["url"]; ok {
|
|
json.Unmarshal(v, &info.URL)
|
|
}
|
|
|
|
return info, nil
|
|
}
|
|
|
|
// DeList deserializes a list of GenerativeStreamInfo from JSON data.
|
|
func (gsi *GenerativeStreamInfo) DeList(data []byte, c 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 {
|
|
info := &GenerativeStreamInfo{BaseModel: *NewBaseModel(c)}
|
|
if err := json.Unmarshal(item, info); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, info)
|
|
}
|
|
return result, nil
|
|
}
|