- artists/{artist_id}/tracks and /direct-albums: artistID in path, return ArtistTracks/ArtistAlbums with pager
- likes: /users/me/likes/{type}s/{add-multiple|remove}, IDs as body params
- queue: /queues/{queue_id}/... instead of /queue/...?queue_id=...
- radio: /rotor/station/{station_id}/info and /tracks
- concerts: /concerts/{concert_id}/info, /concerts/tab-config
- playlists: /users/{user_id}/playlists
- labels: /labels/{label_id}, /albums, /artists
- clips: /clips/will/like, /artists/{artist_id}/blocks/artist-clips
- feed: /landing3/* endpoints
Co-Authored-By: Claude Code <noreply@anthropic.com>
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/models"
|
|
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/utils"
|
|
)
|
|
|
|
// GetArtists gets artists by IDs
|
|
func (c *Client) GetArtists(ctx context.Context, artistIDs []string) ([]*models.Artist, error) {
|
|
if len(artistIDs) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
params := map[string]string{
|
|
"artist-ids": joinIDs(artistIDs),
|
|
}
|
|
|
|
var result []models.Artist
|
|
if err := c.request.Get(ctx, "/artists", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
artists := make([]*models.Artist, len(result))
|
|
for i := range result {
|
|
result[i].SetClient(c)
|
|
artists[i] = &result[i]
|
|
}
|
|
return artists, nil
|
|
}
|
|
|
|
// GetArtist gets a single artist by ID
|
|
func (c *Client) GetArtist(ctx context.Context, artistID string) (*models.Artist, error) {
|
|
artists, err := c.GetArtists(ctx, []string{artistID})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(artists) == 0 {
|
|
return nil, utils.NewYandexMusicError("artist not found", utils.ErrNotFound)
|
|
}
|
|
return artists[0], nil
|
|
}
|
|
|
|
// GetArtistAlbums gets albums by an artist
|
|
// GET /artists/{artist_id}/direct-albums
|
|
func (c *Client) GetArtistAlbums(ctx context.Context, artistID string, page, pageSize int) (*models.ArtistAlbums, error) {
|
|
params := map[string]string{
|
|
"page": fmt.Sprintf("%d", page),
|
|
"page-size": fmt.Sprintf("%d", pageSize),
|
|
}
|
|
|
|
var result models.ArtistAlbums
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/direct-albums", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistTracks gets tracks by an artist
|
|
// GET /artists/{artist_id}/tracks
|
|
func (c *Client) GetArtistTracks(ctx context.Context, artistID string, page, pageSize int) (*models.ArtistTracks, error) {
|
|
params := map[string]string{
|
|
"page": fmt.Sprintf("%d", page),
|
|
"page-size": fmt.Sprintf("%d", pageSize),
|
|
}
|
|
|
|
var result models.ArtistTracks
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/tracks", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|