Track: Added FileInfo, FileDownloadInfo, TrackFullInfo, SimilarTracks types
Album: Added AlbumSimilarEntities, AlbumTrailer, SimilarEntityItem types
Artist: Added ArtistSimilar, ArtistLinks, ArtistAbout, ArtistInfo, ArtistSkeleton,
ArtistTrailerStatus, ArtistLink, Stats, SkeletonBlock types
Client methods added:
- artists.go: GetArtistBriefInfo, GetArtistSimilar, GetArtistLinks, GetArtistAlsoAlbums,
GetArtistDiscographyAlbums, GetArtistSafeDirectAlbums, GetArtistTrackIds, GetArtistAbout,
GetArtistDonation, GetArtistInfo, GetArtistSkeleton, GetArtistTrailer
- albums.go: GetAlbumSimilarEntities, GetAlbumTrailer
- tracks.go: GetTracksFileInfo, GetTracksSimilar, GetTrackTrailer, GetTrackFullInfo
218 lines
7.8 KiB
Go
218 lines
7.8 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"
|
|
"gitea.mrixs.me/Mrixs/yandex-music-api-go/internal/utils"
|
|
)
|
|
|
|
// GetArtists gets artists by their IDs (GET /tracks?artist-ids=...).
|
|
// Returns a slice of Artist pointers, or nil if no IDs are provided.
|
|
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 using GetArtists.
|
|
// Returns an error if no artist is found with the given 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).
|
|
// The page and pageSize parameters control pagination.
|
|
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).
|
|
// The page and pageSize parameters control pagination.
|
|
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
|
|
}
|
|
|
|
// GetArtistBriefInfo gets brief info about an artist (GET /artists/{artist_id}/brief-info).
|
|
func (c *Client) GetArtistBriefInfo(ctx context.Context, artistID string) (*models.ArtistBriefInfo, error) {
|
|
var result models.ArtistBriefInfo
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/brief-info", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistSimilar gets similar artists (GET /artists/{artist_id}/similar).
|
|
func (c *Client) GetArtistSimilar(ctx context.Context, artistID string) (*models.ArtistSimilar, error) {
|
|
var result models.ArtistSimilar
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/similar", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistLinks gets links to artist's pages (GET /artists/{artist_id}/artist-links).
|
|
func (c *Client) GetArtistLinks(ctx context.Context, artistID string) (*models.ArtistLinks, error) {
|
|
var result models.ArtistLinks
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/artist-links", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistAlsoAlbums gets albums where artist participated (GET /artists/{artist_id}/also-albums).
|
|
func (c *Client) GetArtistAlsoAlbums(ctx context.Context, artistID string, page, pageSize int, sortBy string) (*models.ArtistAlbums, error) {
|
|
params := map[string]string{
|
|
"page": fmt.Sprintf("%d", page),
|
|
"page-size": fmt.Sprintf("%d", pageSize),
|
|
"sort-by": sortBy,
|
|
}
|
|
var result models.ArtistAlbums
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/also-albums", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistDiscographyAlbums gets artist discography (GET /artists/{artist_id}/discography-albums).
|
|
func (c *Client) GetArtistDiscographyAlbums(ctx context.Context, artistID string, page, pageSize int, sortBy string) (*models.ArtistAlbums, error) {
|
|
params := map[string]string{
|
|
"page": fmt.Sprintf("%d", page),
|
|
"page-size": fmt.Sprintf("%d", pageSize),
|
|
"sort-by": sortBy,
|
|
}
|
|
var result models.ArtistAlbums
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/discography-albums", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistSafeDirectAlbums gets safe direct albums (GET /artists/{artist_id}/safe-direct-albums).
|
|
func (c *Client) GetArtistSafeDirectAlbums(ctx context.Context, artistID string, sortBy, sortOrder string, limit int) (*models.ArtistAlbums, error) {
|
|
params := map[string]string{
|
|
"sort-by": sortBy,
|
|
"sort-order": sortOrder,
|
|
"limit": fmt.Sprintf("%d", limit),
|
|
}
|
|
var result models.ArtistAlbums
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/safe-direct-albums", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistTrackIds gets track IDs by artist (GET /artists/{artist_id}/track-ids).
|
|
func (c *Client) GetArtistTrackIds(ctx context.Context, artistID string, page, pageSize int) ([]string, error) {
|
|
params := map[string]string{
|
|
"page": fmt.Sprintf("%d", page),
|
|
"page-size": fmt.Sprintf("%d", pageSize),
|
|
}
|
|
var result []string
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/track-ids", artistID), params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// GetArtistAbout gets "About artist" info (GET /artists/{artist_id}/about-artist).
|
|
func (c *Client) GetArtistAbout(ctx context.Context, artistID string) (*models.ArtistAbout, error) {
|
|
var result models.ArtistAbout
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/about-artist", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistDonation gets artist donation info (GET /artists/{artist_id}/blocks/artist-donation).
|
|
func (c *Client) GetArtistDonation(ctx context.Context, artistID string) (*models.ArtistDonations, error) {
|
|
var result models.ArtistDonations
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/blocks/artist-donation", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistInfo gets detailed artist info (GET /artists/{artist_id}/info).
|
|
func (c *Client) GetArtistInfo(ctx context.Context, artistID string) (*models.ArtistInfo, error) {
|
|
var result models.ArtistInfo
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/info", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistSkeleton gets artist page skeleton (GET /artists/{artist_id}/skeletons/{skeleton_id}).
|
|
func (c *Client) GetArtistSkeleton(ctx context.Context, artistID, skeletonID string) (*models.ArtistSkeleton, error) {
|
|
var result models.ArtistSkeleton
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/skeletons/%s", artistID, skeletonID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|
|
|
|
// GetArtistTrailer gets artist trailer (GET /artists/{artist_id}/trailer).
|
|
func (c *Client) GetArtistTrailer(ctx context.Context, artistID string) (*models.ArtistTrailerStatus, error) {
|
|
var result models.ArtistTrailerStatus
|
|
if err := c.request.Get(ctx, fmt.Sprintf("/artists/%s/trailer", artistID), nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
result.SetClient(c)
|
|
return &result, nil
|
|
}
|