Files
Mrixs 463e0bcd1a Add missing model fields from Python reference
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
2026-10-18 13:14:15 +03:00

109 lines
2.7 KiB
Go

// Package models provides data models for the Yandex Music API.
package models
import (
"encoding/json"
)
// Label represents a label from the Yandex Music API.
type Label struct {
BaseModel
ID JSONID `json:"id"`
Name string `json:"name"`
CoverURI string `json:"cover_uri"`
Description string `json:"description"`
DescriptionFormatted string `json:"description_formatted"`
Image string `json:"image"`
Website string `json:"website"`
Links []Link `json:"links"`
Type string `json:"type"`
Available bool `json:"available"`
Owner *User `json:"owner"`
}
// DeJSON deserializes a Label from JSON data.
func (l *Label) DeJSON(data []byte, client ClientInterface) (Model, error) {
var raw map[string]json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
label := &Label{BaseModel: *NewBaseModel(client)}
if v, ok := raw["id"]; ok {
json.Unmarshal(v, &label.ID)
}
if v, ok := raw["name"]; ok {
json.Unmarshal(v, &label.Name)
}
if v, ok := raw["cover_uri"]; ok {
json.Unmarshal(v, &label.CoverURI)
}
if v, ok := raw["description"]; ok {
json.Unmarshal(v, &label.Description)
}
if v, ok := raw["website"]; ok {
json.Unmarshal(v, &label.Website)
}
if v, ok := raw["available"]; ok {
json.Unmarshal(v, &label.Available)
}
if v, ok := raw["description_formatted"]; ok {
json.Unmarshal(v, &label.DescriptionFormatted)
}
if v, ok := raw["image"]; ok {
json.Unmarshal(v, &label.Image)
}
if v, ok := raw["links"]; ok {
var links []Link
json.Unmarshal(v, &links)
label.Links = links
}
if v, ok := raw["type"]; ok {
json.Unmarshal(v, &label.Type)
}
if v, ok := raw["owner"]; ok {
var user User
json.Unmarshal(v, &user)
label.Owner = &user
}
return label, nil
}
// DeList deserializes a list of Labels from JSON data.
func (l *Label) 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 {
label := &Label{BaseModel: *NewBaseModel(client)}
if err := json.Unmarshal(item, label); err != nil {
continue
}
result = append(result, label)
}
return result, nil
}
// LabelAlbums represents label albums.
type LabelAlbums struct {
BaseModel
Albums []Album `json:"albums"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
// LabelArtists represents label artists.
type LabelArtists struct {
BaseModel
Artists []Artist `json:"artists"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}