Files
yandex-music-api-go/internal/models/concert.go
T
Mrixs 73775a8526 Add remaining model types and client methods
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
2026-10-18 13:32:45 +03:00

323 lines
8.8 KiB
Go

// Package models provides data models for the Yandex Music API.
package models
import (
"encoding/json"
)
// Concert represents a concert from the Yandex Music API.
type Concert struct {
BaseModel
ID JSONID `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Date string `json:"date"`
Time string `json:"time"`
Datetime string `json:"datetime"`
Venue *ConcertVenue `json:"venue"`
Location *ConcertLocation `json:"location"`
MinPrice int `json:"min_price"`
MaxPrice int `json:"max_price"`
Currency string `json:"currency"`
TicketURI string `json:"ticket_uri"`
ImageURI string `json:"image_uri"`
Available bool `json:"available"`
SoldOut bool `json:"sold_out"`
Artists []Artist `json:"artists"`
Genres []string `json:"genres"`
Cashback *ConcertCashback `json:"cashback"`
Tabs []ConcertTabConfig `json:"tabs"`
Skeleton *ConcertSkeleton `json:"skeleton"`
AfishaURL string `json:"afisha_url"`
City string `json:"city"`
Place string `json:"place"`
Address string `json:"address"`
ContentRating string `json:"content_rating"`
DataSessionID string `json:"data_session_id"`
EventInfo *ConcertEventInfo `json:"event_info"`
}
// DeJSON deserializes a Concert from JSON data.
func (c *Concert) DeJSON(data []byte, client ClientInterface) (Model, error) {
var raw map[string]json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
concert := &Concert{BaseModel: *NewBaseModel(client)}
if v, ok := raw["id"]; ok {
json.Unmarshal(v, &concert.ID)
}
if v, ok := raw["title"]; ok {
json.Unmarshal(v, &concert.Title)
}
if v, ok := raw["description"]; ok {
json.Unmarshal(v, &concert.Description)
}
if v, ok := raw["date"]; ok {
json.Unmarshal(v, &concert.Date)
}
if v, ok := raw["time"]; ok {
json.Unmarshal(v, &concert.Time)
}
if v, ok := raw["min_price"]; ok {
json.Unmarshal(v, &concert.MinPrice)
}
if v, ok := raw["max_price"]; ok {
json.Unmarshal(v, &concert.MaxPrice)
}
if v, ok := raw["currency"]; ok {
json.Unmarshal(v, &concert.Currency)
}
if v, ok := raw["ticket_uri"]; ok {
json.Unmarshal(v, &concert.TicketURI)
}
if v, ok := raw["image_uri"]; ok {
json.Unmarshal(v, &concert.ImageURI)
}
if v, ok := raw["available"]; ok {
json.Unmarshal(v, &concert.Available)
}
if v, ok := raw["sold_out"]; ok {
json.Unmarshal(v, &concert.SoldOut)
}
if v, ok := raw["genres"]; ok {
json.Unmarshal(v, &concert.Genres)
}
if v, ok := raw["datetime"]; ok {
json.Unmarshal(v, &concert.Datetime)
}
if v, ok := raw["afisha_url"]; ok {
json.Unmarshal(v, &concert.AfishaURL)
}
if v, ok := raw["city"]; ok {
json.Unmarshal(v, &concert.City)
}
if v, ok := raw["place"]; ok {
json.Unmarshal(v, &concert.Place)
}
if v, ok := raw["address"]; ok {
json.Unmarshal(v, &concert.Address)
}
if v, ok := raw["content_rating"]; ok {
json.Unmarshal(v, &concert.ContentRating)
}
if v, ok := raw["data_session_id"]; ok {
json.Unmarshal(v, &concert.DataSessionID)
}
if v, ok := raw["event_info"]; ok {
json.Unmarshal(v, &concert.EventInfo)
}
if v, ok := raw["venue"]; ok {
var venue ConcertVenue
json.Unmarshal(v, &venue)
concert.Venue = &venue
}
if v, ok := raw["location"]; ok {
var location ConcertLocation
json.Unmarshal(v, &location)
concert.Location = &location
}
if v, ok := raw["artists"]; ok {
var artists []Artist
json.Unmarshal(v, &artists)
concert.Artists = artists
}
if v, ok := raw["cashback"]; ok {
var cashback ConcertCashback
json.Unmarshal(v, &cashback)
concert.Cashback = &cashback
}
if v, ok := raw["tabs"]; ok {
var tabs []ConcertTabConfig
json.Unmarshal(v, &tabs)
concert.Tabs = tabs
}
if v, ok := raw["skeleton"]; ok {
var skeleton ConcertSkeleton
json.Unmarshal(v, &skeleton)
concert.Skeleton = &skeleton
}
return concert, nil
}
// DeList deserializes a list of Concerts from JSON data.
func (c *Concert) 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 {
concert := &Concert{BaseModel: *NewBaseModel(client)}
if err := json.Unmarshal(item, concert); err != nil {
continue
}
result = append(result, concert)
}
return result, nil
}
// ConcertVenue represents a concert venue.
type ConcertVenue struct {
BaseModel
ID JSONID `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
City string `json:"city"`
Country string `json:"country"`
Capacity int `json:"capacity"`
ImageURI string `json:"image_uri"`
}
// ConcertLocation represents a concert location.
type ConcertLocation struct {
BaseModel
ID JSONID `json:"id"`
Name string `json:"name"`
City string `json:"city"`
Country string `json:"country"`
Timezone string `json:"timezone"`
Venues []ConcertVenue `json:"venues"`
}
// ConcertLocations represents concert locations.
type ConcertLocations struct {
BaseModel
Locations []ConcertLocation `json:"locations"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
// ConcertFeed represents a concert feed.
type ConcertFeed struct {
BaseModel
Concerts []Concert `json:"concerts"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
// ConcertInfo represents concert info.
type ConcertInfo struct {
BaseModel
Concert *Concert `json:"concert"`
Related []Concert `json:"related"`
}
// ConcertEventInfo represents concert event info.
type ConcertEventInfo struct {
BaseModel
EventID string `json:"event_id"`
EventType string `json:"event_type"`
Timestamp string `json:"timestamp"`
Data json.RawMessage `json:"data"`
}
// ConcertDescription represents concert description.
type ConcertDescription struct {
BaseModel
Text string `json:"text"`
HTML string `json:"html"`
ShortText string `json:"short_text"`
}
// ConcertCashback represents concert cashback.
type ConcertCashback struct {
BaseModel
Amount int `json:"amount"`
Currency string `json:"currency"`
Percent int `json:"percent"`
Expires string `json:"expires"`
}
// ConcertMinPrice represents concert min price.
type ConcertMinPrice struct {
BaseModel
Price int `json:"price"`
Currency string `json:"currency"`
}
// ConcertTabConfig represents concert tab config.
type ConcertTabConfig struct {
BaseModel
ID JSONID `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Active bool `json:"active"`
Range *ConcertTabRange `json:"range"`
}
// ConcertTabRange represents concert tab range.
type ConcertTabRange struct {
BaseModel
From string `json:"from"`
To string `json:"to"`
}
// ConcertSkeleton represents concert skeleton.
type ConcertSkeleton struct {
BaseModel
Blocks []ConcertSkeletonBlock `json:"blocks"`
}
// ConcertSkeletonBlock represents a concert skeleton block.
type ConcertSkeletonBlock struct {
BaseModel
ID JSONID `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Data json.RawMessage `json:"data"`
}
// ArtistConcerts represents concerts by an artist.
type ArtistConcerts struct {
BaseModel
ArtistTitle string `json:"artist_title"`
Concerts []Concert `json:"concerts"`
}
// DeJSON deserializes ArtistConcerts from JSON data.
func (ac *ArtistConcerts) DeJSON(data []byte, c ClientInterface) (Model, error) {
var raw map[string]json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return nil, err
}
acObj := &ArtistConcerts{BaseModel: *NewBaseModel(c)}
if v, ok := raw["artist_title"]; ok {
json.Unmarshal(v, &acObj.ArtistTitle)
}
if v, ok := raw["concerts"]; ok {
var concerts []Concert
json.Unmarshal(v, &concerts)
acObj.Concerts = concerts
}
return acObj, nil
}
// DeList deserializes a list of ArtistConcerts from JSON data.
func (ac *ArtistConcerts) 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 {
ac := &ArtistConcerts{BaseModel: *NewBaseModel(c)}
if err := json.Unmarshal(item, ac); err != nil {
continue
}
result = append(result, ac)
}
return result, nil
}