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
182 lines
6.3 KiB
Go
182 lines
6.3 KiB
Go
// Package client provides methods for interacting with Yandex Music API endpoints.
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/models"
|
|
)
|
|
|
|
// GetRadioStations gets radio stations (GET /radio/stations).
|
|
func (c *Client) GetRadioStations(ctx context.Context) ([]*models.RadioStation, error) {
|
|
var result []models.RadioStation
|
|
if err := c.request.Get(ctx, "/radio/stations", nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stations := make([]*models.RadioStation, len(result))
|
|
for i := range result {
|
|
result[i].SetClient(c)
|
|
stations[i] = &result[i]
|
|
}
|
|
return stations, nil
|
|
}
|
|
|
|
// GetRadioStation gets a radio station by ID (GET /rotor/station/{stationID}/info).
|
|
func (c *Client) GetRadioStation(ctx context.Context, stationID string) (*models.RadioStation, error) {
|
|
var result models.RadioStation
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/info", stationID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetStationTracks gets tracks for a radio station (GET /rotor/station/{stationID}/tracks).
|
|
func (c *Client) GetStationTracks(ctx context.Context, stationID string, limit int) (*models.StationTracksResult, error) {
|
|
params := map[string]string{}
|
|
if limit > 0 {
|
|
params["limit"] = fmt.Sprintf("%d", limit)
|
|
}
|
|
|
|
var result models.StationTracksResult
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/tracks", stationID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStations gets rotor stations (generative stations) (GET /rotor/stations).
|
|
func (c *Client) GetRotorStations(ctx context.Context) ([]*models.RotorStation, error) {
|
|
var result []models.RotorStation
|
|
if err := c.request.Get(ctx, "/rotor/stations", nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stations := make([]*models.RotorStation, len(result))
|
|
for i := range result {
|
|
result[i].SetClient(c)
|
|
stations[i] = &result[i]
|
|
}
|
|
return stations, nil
|
|
}
|
|
|
|
// GetRotorStation gets a rotor station by ID (GET /rotor/station/{stationID}/info).
|
|
func (c *Client) GetRotorStation(ctx context.Context, stationID string) (*models.RotorStation, error) {
|
|
var result models.RotorStation
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/info", stationID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStationTracks gets tracks for a rotor station (GET /rotor/station/{stationID}/tracks).
|
|
func (c *Client) GetRotorStationTracks(ctx context.Context, stationID string, limit int) (*models.RotorStationTracksResult, error) {
|
|
params := map[string]string{}
|
|
if limit > 0 {
|
|
params["limit"] = fmt.Sprintf("%d", limit)
|
|
}
|
|
|
|
var result models.RotorStationTracksResult
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/tracks", stationID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// StartRotorSession starts a rotor session (POST /rotor/station/{stationID}/session/start).
|
|
func (c *Client) StartRotorSession(ctx context.Context, stationID string) (*models.RotorSession, error) {
|
|
var result models.RotorSession
|
|
if err := c.request.Post(ctx, fmt.Sprintf("/rotor/station/%s/session/start", stationID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorSession gets rotor session info by session ID (GET /rotor/session).
|
|
func (c *Client) GetRotorSession(ctx context.Context, sessionID string) (*models.RotorSession, error) {
|
|
params := map[string]string{
|
|
"session_id": sessionID,
|
|
}
|
|
|
|
var result models.RotorSession
|
|
if err := c.request.Get(ctx, "/rotor/session", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// RotorSessionFeedback sends feedback for a rotor session track (POST /rotor/station/{stationID}/feedback).
|
|
// The feedbackType parameter can be "like", "dislike", or "skip".
|
|
func (c *Client) RotorSessionFeedback(ctx context.Context, sessionID, trackID, feedbackType string) error {
|
|
params := map[string]string{
|
|
"track_id": trackID,
|
|
"feedback": feedbackType, // "like", "dislike", "skip"
|
|
}
|
|
|
|
var result map[string]any
|
|
return c.request.Post(ctx, fmt.Sprintf("/rotor/station/%s/feedback", sessionID), params, &result)
|
|
}
|
|
|
|
// GetRotorStationsDashboard gets rotor stations dashboard (GET /rotor/stations/dashboard).
|
|
func (c *Client) GetRotorStationsDashboard(ctx context.Context) (*models.Dashboard, error) {
|
|
var result models.Dashboard
|
|
if err := c.request.Get(ctx, "/rotor/stations/dashboard", nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStationsList gets rotor stations list (GET /rotor/stations/list).
|
|
func (c *Client) GetRotorStationsList(ctx context.Context) ([]*models.StationResult, error) {
|
|
var result []models.StationResult
|
|
if err := c.request.Get(ctx, "/rotor/stations/list", nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
stations := make([]*models.StationResult, len(result))
|
|
for i := range result {
|
|
result[i].SetClient(c)
|
|
stations[i] = &result[i]
|
|
}
|
|
return stations, nil
|
|
}
|
|
|
|
// GetRotorStationInfo gets rotor station info (GET /rotor/station/{id}/info).
|
|
func (c *Client) GetRotorStationInfo(ctx context.Context, stationID string) (*models.RotorStation, error) {
|
|
var result models.RotorStation
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/info", stationID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStationStream gets rotor station stream (GET /rotor/station/{id}/stream).
|
|
func (c *Client) GetRotorStationStream(ctx context.Context, stationID string) (*models.GenerativeStream, error) {
|
|
var result models.GenerativeStream
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/rotor/station/%s/stream", stationID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStationSettings gets rotor station settings (POST /rotor/station/{id}/settings3).
|
|
func (c *Client) GetRotorStationSettings(ctx context.Context, stationID string, moodEnergy, diversity, language string) (bool, error) {
|
|
params := map[string]string{
|
|
"mood-energy": moodEnergy,
|
|
"diversity": diversity,
|
|
"language": language,
|
|
}
|
|
var result bool
|
|
if err := c.request.Post(ctx, fmt.Sprintf("/rotor/station/%s/settings3", stationID), params, &result); err != nil {
|
|
return false, err
|
|
}
|
|
return result, nil
|
|
}
|