Feed: Added can_get_more_events, pumpkin, is_wizard_passed, headlines, today, next_revision Label: Added description_formatted, image, links ([]Link), type Landing: Added pumpkin, content_id Pin: Added content_restrictions Search: Added search_request_id, text, best, podcasts, podcast_episodes, clips, banner, page, per_page, misspell fields Clip: Rewrote with all missing fields (version, player_id, uuid, thumbnail, track_ids, disclaimers, explicit, cover, content_restrictions) Concert: Added datetime, afisha_url, city, place, address, content_rating, data_session_id, event_info
274 lines
7.0 KiB
Go
274 lines
7.0 KiB
Go
// Package models provides data models for the Yandex Music API.
|
|
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// Clip represents a clip (short video) from the Yandex Music API.
|
|
type Clip struct {
|
|
BaseModel
|
|
ID JSONID `json:"id"`
|
|
Title string `json:"title"`
|
|
Version string `json:"version"`
|
|
PlayerID string `json:"player_id"`
|
|
UUID string `json:"uuid"`
|
|
Thumbnail string `json:"thumbnail"`
|
|
PreviewURL string `json:"preview_url"`
|
|
Duration int `json:"duration"`
|
|
TrackIDs []int `json:"track_ids"`
|
|
Artists []Artist `json:"artists"`
|
|
Disclaimers []string `json:"disclaimers"`
|
|
Explicit bool `json:"explicit"`
|
|
Cover *Cover `json:"cover"`
|
|
ContentRestrictions *ContentRestrictions `json:"content_restrictions"`
|
|
Client *ClientInterface `json:"-"`
|
|
ClipType string `json:"clip_type"`
|
|
IsVertical bool `json:"is_vertical"`
|
|
AspectRatio string `json:"aspect_ratio"`
|
|
}
|
|
|
|
// DeJSON deserializes a Clip from JSON data.
|
|
func (c *Clip) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
clip := &Clip{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &clip.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &clip.Title)
|
|
}
|
|
if v, ok := raw["version"]; ok {
|
|
json.Unmarshal(v, &clip.Version)
|
|
}
|
|
if v, ok := raw["player_id"]; ok {
|
|
json.Unmarshal(v, &clip.PlayerID)
|
|
}
|
|
if v, ok := raw["uuid"]; ok {
|
|
json.Unmarshal(v, &clip.UUID)
|
|
}
|
|
if v, ok := raw["thumbnail"]; ok {
|
|
json.Unmarshal(v, &clip.Thumbnail)
|
|
}
|
|
if v, ok := raw["preview_url"]; ok {
|
|
json.Unmarshal(v, &clip.PreviewURL)
|
|
}
|
|
if v, ok := raw["duration"]; ok {
|
|
json.Unmarshal(v, &clip.Duration)
|
|
}
|
|
if v, ok := raw["track_ids"]; ok {
|
|
json.Unmarshal(v, &clip.TrackIDs)
|
|
}
|
|
if v, ok := raw["artists"]; ok {
|
|
var artists []Artist
|
|
json.Unmarshal(v, &artists)
|
|
clip.Artists = artists
|
|
}
|
|
if v, ok := raw["disclaimers"]; ok {
|
|
json.Unmarshal(v, &clip.Disclaimers)
|
|
}
|
|
if v, ok := raw["explicit"]; ok {
|
|
json.Unmarshal(v, &clip.Explicit)
|
|
}
|
|
if v, ok := raw["cover"]; ok {
|
|
var cover Cover
|
|
json.Unmarshal(v, &cover)
|
|
clip.Cover = &cover
|
|
}
|
|
if v, ok := raw["content_restrictions"]; ok {
|
|
var cr ContentRestrictions
|
|
json.Unmarshal(v, &cr)
|
|
clip.ContentRestrictions = &cr
|
|
}
|
|
if v, ok := raw["clip_type"]; ok {
|
|
json.Unmarshal(v, &clip.ClipType)
|
|
}
|
|
if v, ok := raw["is_vertical"]; ok {
|
|
json.Unmarshal(v, &clip.IsVertical)
|
|
}
|
|
if v, ok := raw["aspect_ratio"]; ok {
|
|
json.Unmarshal(v, &clip.AspectRatio)
|
|
}
|
|
|
|
return clip, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Clips from JSON data.
|
|
func (c *Clip) 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 {
|
|
clip := &Clip{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, clip); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, clip)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// ClipsWillLike represents clips the user might like.
|
|
type ClipsWillLike struct {
|
|
BaseModel
|
|
Clips []Clip `json:"clips"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
// ArtistClipData represents artist clip data.
|
|
type ArtistClipData struct {
|
|
BaseModel
|
|
Clips []Clip `json:"clips"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
// ArtistClipItem represents an artist clip item.
|
|
type ArtistClipItem struct {
|
|
BaseModel
|
|
Clip *Clip `json:"clip"`
|
|
Index int `json:"index"`
|
|
}
|
|
|
|
// Shot represents a shot (short video).
|
|
type Shot struct {
|
|
BaseModel
|
|
ID JSONID `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Duration int `json:"duration"`
|
|
CoverURI string `json:"cover_uri"`
|
|
PreviewURI string `json:"preview_uri"`
|
|
Available bool `json:"available"`
|
|
Views int `json:"views"`
|
|
Likes int `json:"likes"`
|
|
Comments int `json:"comments"`
|
|
CreatedAt string `json:"created_at"`
|
|
Author *User `json:"author"`
|
|
Track *Track `json:"track"`
|
|
ShotType string `json:"shot_type"`
|
|
Tags []string `json:"tags"`
|
|
IsVertical bool `json:"is_vertical"`
|
|
AspectRatio string `json:"aspect_ratio"`
|
|
}
|
|
|
|
// DeJSON deserializes a Shot from JSON data.
|
|
func (s *Shot) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
shot := &Shot{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &shot.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &shot.Title)
|
|
}
|
|
if v, ok := raw["description"]; ok {
|
|
json.Unmarshal(v, &shot.Description)
|
|
}
|
|
if v, ok := raw["duration"]; ok {
|
|
json.Unmarshal(v, &shot.Duration)
|
|
}
|
|
if v, ok := raw["cover_uri"]; ok {
|
|
json.Unmarshal(v, &shot.CoverURI)
|
|
}
|
|
if v, ok := raw["preview_uri"]; ok {
|
|
json.Unmarshal(v, &shot.PreviewURI)
|
|
}
|
|
if v, ok := raw["available"]; ok {
|
|
json.Unmarshal(v, &shot.Available)
|
|
}
|
|
if v, ok := raw["views"]; ok {
|
|
json.Unmarshal(v, &shot.Views)
|
|
}
|
|
if v, ok := raw["likes"]; ok {
|
|
json.Unmarshal(v, &shot.Likes)
|
|
}
|
|
if v, ok := raw["comments"]; ok {
|
|
json.Unmarshal(v, &shot.Comments)
|
|
}
|
|
if v, ok := raw["created_at"]; ok {
|
|
json.Unmarshal(v, &shot.CreatedAt)
|
|
}
|
|
if v, ok := raw["shot_type"]; ok {
|
|
json.Unmarshal(v, &shot.ShotType)
|
|
}
|
|
if v, ok := raw["tags"]; ok {
|
|
json.Unmarshal(v, &shot.Tags)
|
|
}
|
|
if v, ok := raw["is_vertical"]; ok {
|
|
json.Unmarshal(v, &shot.IsVertical)
|
|
}
|
|
if v, ok := raw["aspect_ratio"]; ok {
|
|
json.Unmarshal(v, &shot.AspectRatio)
|
|
}
|
|
|
|
if v, ok := raw["author"]; ok {
|
|
var user User
|
|
json.Unmarshal(v, &user)
|
|
shot.Author = &user
|
|
}
|
|
if v, ok := raw["track"]; ok {
|
|
var track Track
|
|
json.Unmarshal(v, &track)
|
|
shot.Track = &track
|
|
}
|
|
|
|
return shot, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Shots from JSON data.
|
|
func (s *Shot) 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 {
|
|
shot := &Shot{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, shot); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, shot)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// ShotData represents shot data.
|
|
type ShotData struct {
|
|
BaseModel
|
|
Shots []Shot `json:"shots"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
// ShotEvent represents a shot event.
|
|
type ShotEvent struct {
|
|
BaseModel
|
|
EventID string `json:"event_id"`
|
|
EventType string `json:"event_type"`
|
|
Timestamp string `json:"timestamp"`
|
|
ShotID string `json:"shot_id"`
|
|
Action string `json:"action"`
|
|
}
|
|
|
|
// ShotType represents a shot type.
|
|
type ShotType struct {
|
|
BaseModel
|
|
ID JSONID `json:"id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Icon string `json:"icon"`
|
|
}
|