139 lines
3.8 KiB
Go
139 lines
3.8 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/models"
|
|
)
|
|
|
|
// GetRadioStations gets 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
|
|
func (c *Client) GetRadioStation(ctx context.Context, stationID string) (*models.RadioStation, error) {
|
|
params := map[string]string{
|
|
"station_id": stationID,
|
|
}
|
|
|
|
var result models.RadioStation
|
|
if err := c.request.Get(ctx, "/radio/station", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetStationTracks gets tracks for a radio station
|
|
func (c *Client) GetStationTracks(ctx context.Context, stationID string, limit int) (*models.StationTracksResult, error) {
|
|
params := map[string]string{
|
|
"station_id": stationID,
|
|
}
|
|
if limit > 0 {
|
|
params["limit"] = fmt.Sprintf("%d", limit)
|
|
}
|
|
|
|
var result models.StationTracksResult
|
|
if err := c.request.Get(ctx, "/radio/station/tracks", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStations gets rotor stations (generative)
|
|
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
|
|
func (c *Client) GetRotorStation(ctx context.Context, stationID string) (*models.RotorStation, error) {
|
|
params := map[string]string{
|
|
"station_id": stationID,
|
|
}
|
|
|
|
var result models.RotorStation
|
|
if err := c.request.Get(ctx, "/rotor/station", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorStationTracks gets tracks for a rotor station
|
|
func (c *Client) GetRotorStationTracks(ctx context.Context, stationID string, limit int) (*models.RotorStationTracksResult, error) {
|
|
params := map[string]string{
|
|
"station_id": stationID,
|
|
}
|
|
if limit > 0 {
|
|
params["limit"] = fmt.Sprintf("%d", limit)
|
|
}
|
|
|
|
var result models.RotorStationTracksResult
|
|
if err := c.request.Get(ctx, "/rotor/station/tracks", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// StartRotorSession starts a rotor session
|
|
func (c *Client) StartRotorSession(ctx context.Context, stationID string) (*models.RotorSession, error) {
|
|
params := map[string]string{
|
|
"station_id": stationID,
|
|
}
|
|
|
|
var result models.RotorSession
|
|
if err := c.request.Post(ctx, "/rotor/session/start", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetRotorSession gets rotor session info
|
|
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
|
|
func (c *Client) RotorSessionFeedback(ctx context.Context, sessionID, trackID, feedbackType string) error {
|
|
params := map[string]string{
|
|
"session_id": sessionID,
|
|
"track_id": trackID,
|
|
"feedback": feedbackType, // "like", "dislike", "skip"
|
|
}
|
|
|
|
var result map[string]any
|
|
return c.request.Post(ctx, "/rotor/session/feedback", params, &result)
|
|
}
|