yamusic

package
v0.0.0-...-7fab24c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilDownloadInfoResp = TrackError("got nil download info resp pointer")
	ErrNilDownloadInfo     = TrackError("got nil download info pointer")
	ErrNilPath             = TrackError("got nil path")
	ErrEmptyPath           = TrackError("got empty path")
	ErrZeroResultLen       = TrackError("len of download inf response's result field is zero")
)

Functions

func AccessToken

func AccessToken(userID int, accessToken string) func(*Client)

AccessToken sets user_id and access token for Yandex.Music client

func BaseURL

func BaseURL(baseURL *url.URL) func(*Client)

BaseURL sets base API URL for Yandex.Music client

func HTTPClient

func HTTPClient(httpClient Doer) func(*Client)

HTTPClient sets http client for Yandex.Music client

Types

type AccountService

type AccountService struct {
	// contains filtered or unexported fields
}

AccountService is a service to deal with accounts.

func (*AccountService) GetStatus

func (s *AccountService) GetStatus(
	ctx context.Context,
) (*AccountStatusResp, *http.Response, error)

GetStatus returns account's status

type AccountStatusResp

type AccountStatusResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         struct {
		Account struct {
			UID              int       `json:"uid"`
			Region           int       `json:"region"`
			Login            string    `json:"login"`
			FullName         string    `json:"fullName"`
			SecondName       string    `json:"secondName"`
			FirstName        string    `json:"firstName"`
			DisplayName      string    `json:"displayName"`
			Birthday         string    `json:"birthday"`
			ServiceAvailable bool      `json:"serviceAvailable"`
			HostedUser       bool      `json:"hostedUser"`
			RegisteredAt     time.Time `json:"registeredAt"`
			Now              time.Time `json:"now"`
			PassportPhones   []struct {
				Phone string `json:"phone"`
			} `json:"passport-phones"`
		} `json:"account"`
		Permissions struct {
			Until   time.Time `json:"until"`
			Values  []string  `json:"values"`
			Default []string  `json:"default"`
		} `json:"permissions"`
		Subscription struct {
			CanStartTrial bool `json:"canStartTrial"`
			Mcdonalds     bool `json:"mcdonalds"`
		} `json:"subscription"`
	} `json:"result"`
}

AccountStatusResp describes account get status method response

type Album

type Album struct {
	ID                       int           `json:"id"`
	Title                    string        `json:"title"`
	Type                     string        `json:"type,omitempty"`
	MetaType                 string        `json:"metaType"`
	ContentWarning           string        `json:"contentWarning,omitempty"`
	Year                     int           `json:"year"`
	ReleaseDate              time.Time     `json:"releaseDate"`
	CoverURI                 string        `json:"coverUri"`
	OgImage                  string        `json:"ogImage"`
	Genre                    string        `json:"genre"`
	Buy                      []interface{} `json:"buy"`
	TrackCount               int           `json:"trackCount"`
	LikesCount               int           `json:"likesCount"`
	Recent                   bool          `json:"recent"`
	VeryImportant            bool          `json:"veryImportant"`
	Available                bool          `json:"available"`
	AvailableForPremiumUsers bool          `json:"availableForPremiumUsers"`
	AvailableForOptions      []string      `json:"availableForOptions"`
	AvailableForMobile       bool          `json:"availableForMobile"`
	AvailablePartially       bool          `json:"availablePartially"`
	Bests                    []int         `json:"bests"`
	Artists                  Artists       `json:"artists"`
	Labels                   Labels        `json:"labels"`
	TrackPosition            struct {
		Volume int `json:"volume"`
		Index  int `json:"index"`
	} `json:"trackPosition"`
}

type Albums

type Albums []Album

type Artist

type Artist struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Various  bool   `json:"various"`
	Composer bool   `json:"composer"`
	Cover    struct {
		Type   string `json:"type"`
		Prefix string `json:"prefix"`
		URI    string `json:"uri"`
	} `json:"cover"`
	Genres []interface{} `json:"genres"`
}

type Artists

type Artists []Artist

type Client

type Client struct {

	// Debug sets should library print debug messages or not
	Debug bool
	// contains filtered or unexported fields
}

A Client manages communication with the Yandex.Music API.

func NewClient

func NewClient(options ...func(*Client)) *Client

NewClient returns a new API client. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) Account

func (c *Client) Account() *AccountService

Account returns account service

func (*Client) Do

func (c *Client) Do(
	ctx context.Context,
	req *http.Request,
	v interface{},
) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) Feed

func (c *Client) Feed() *FeedService

Feed returns feed service

func (*Client) Genres

func (c *Client) Genres() *GenresService

Genres returns genres service

func (*Client) Likes

func (c *Client) Likes() *LikesService

func (*Client) NewRequest

func (c *Client) NewRequest(
	method,
	urlStr string,
	body interface{},
) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body, except when body is url.Values. If it is url.Values, it is encoded as application/x-www-form-urlencoded and included in request headers.

func (*Client) Playlists

func (c *Client) Playlists() *PlaylistsService

Playlists returns playlists service

func (*Client) Search

func (c *Client) Search() *SearchService

Search returns genres service

func (*Client) SetUserID

func (c *Client) SetUserID(nID int)

SetUserID sets user's id in client

func (*Client) Tracks

func (c *Client) Tracks() *TracksService

Tracks returns feed service

func (*Client) UserID

func (c *Client) UserID() int

UserID returns id of authorized user. If wasn't authorized returns 0.

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is an interface that can do http request

type DownloadInfo

type DownloadInfo struct {
	XMLName xml.Name `xml:"download-info"`
	Text    string   `xml:",chardata"`
	Host    string   `xml:"host"`
	Path    string   `xml:"path"`
	TS      string   `xml:"ts"`
	Region  string   `xml:"region"`
	S       string   `xml:"s"`
}

DownloadInfo is a response of URL from DownloadInfoResp's `DownloadInfoURL` field

type DownloadInfoResp

type DownloadInfoResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         []struct {
		Codec           string `json:"codec"`
		Gain            bool   `json:"gain"`
		Preview         bool   `json:"preview"`
		DownloadInfoURL string `json:"downloadInfoUrl"`
		Direct          bool   `json:"direct"`
		BitrateInKbps   int    `json:"bitrateInKbps"`
	} `json:"result"`
}

Response of track/%d/download_info

type Error

type Error struct {
	Name    string `json:"name"`
	Message string `json:"message"`
}

Error is struct with error type and message.

type FeedResp

type FeedResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         struct {
		CanGetMoreEvents   bool          `json:"canGetMoreEvents"`
		Pumpkin            bool          `json:"pumpkin"`
		Today              string        `json:"today"`
		GeneratedPlaylists []interface{} `json:"generatedPlaylists"`
		Headlines          []struct {
			Type    string `json:"type"`
			ID      string `json:"id"`
			Message string `json:"message"`
		} `json:"headlines"`
		Days []struct {
			Day    string `json:"day"`
			Events []struct {
				ID          string `json:"id"`
				Type        string `json:"type"`
				TypeForFrom string `json:"typeForFrom,omitempty"`
				Title       []struct {
					Type string `json:"type"`
					Text string `json:"text"`
				} `json:"title,omitempty"`
				Promo struct {
					PromoID       string        `json:"promoId"`
					Category      string        `json:"category"`
					TitleURL      string        `json:"titleUrl"`
					SubtitleURL   string        `json:"subtitleUrl"`
					Title         string        `json:"title"`
					Subtitle      string        `json:"subtitle"`
					Heading       string        `json:"heading"`
					Description   string        `json:"description"`
					Background    string        `json:"background"`
					ImagePosition string        `json:"imagePosition"`
					PromotionType string        `json:"promotionType"`
					Tags          []interface{} `json:"tags"`
					StartDate     time.Time     `json:"startDate"`
					Pager         struct {
						Total   int `json:"total"`
						Page    int `json:"page"`
						PerPage int `json:"perPage"`
					} `json:"pager"`
					Playlists []struct {
						Playlist struct {
							UID                  int       `json:"uid"`
							Kind                 int       `json:"kind"`
							Revision             int       `json:"revision"`
							TrackCount           int       `json:"trackCount"`
							DurationMs           int       `json:"durationMs"`
							Collective           bool      `json:"collective"`
							IsBanner             bool      `json:"isBanner"`
							IsPremiere           bool      `json:"isPremiere"`
							Available            bool      `json:"available"`
							Title                string    `json:"title"`
							Description          string    `json:"description"`
							DescriptionFormatted string    `json:"descriptionFormatted"`
							Visibility           string    `json:"visibility"`
							BackgroundColor      string    `json:"backgroundColor"`
							TextColor            string    `json:"textColor"`
							Image                string    `json:"image"`
							OgImage              string    `json:"ogImage"`
							Created              time.Time `json:"created"`
							Modified             time.Time `json:"modified"`
							Owner                struct {
								UID      int    `json:"uid"`
								Login    string `json:"login"`
								Name     string `json:"name"`
								Verified bool   `json:"verified"`
							} `json:"owner"`
							Cover struct {
								Type    string `json:"type"`
								Dir     string `json:"dir"`
								Version string `json:"version"`
								URI     string `json:"uri"`
								Custom  bool   `json:"custom"`
							} `json:"cover"`
							Tags []struct {
								ID    string `json:"id"`
								Value string `json:"value"`
							} `json:"tags"`
						} `json:"playlist"`
						SomeArtists []struct {
							Various          bool     `json:"various"`
							Composer         bool     `json:"composer"`
							Available        bool     `json:"available"`
							TicketsAvailable bool     `json:"ticketsAvailable"`
							ID               string   `json:"id"`
							Name             string   `json:"name"`
							OgImage          string   `json:"ogImage"`
							Genres           []string `json:"genres"`
							Cover            struct {
								Type   string `json:"type"`
								Prefix string `json:"prefix"`
								URI    string `json:"uri"`
							} `json:"cover,omitempty"`
							Counts struct {
								Tracks       int `json:"tracks"`
								DirectAlbums int `json:"directAlbums"`
								AlsoAlbums   int `json:"alsoAlbums"`
								AlsoTracks   int `json:"alsoTracks"`
							} `json:"counts"`
							Ratings struct {
								Day   int `json:"day"`
								Week  int `json:"week"`
								Month int `json:"month"`
							} `json:"ratings,omitempty"`
							Links []struct {
								Title         string `json:"title"`
								Href          string `json:"href"`
								Type          string `json:"type"`
								SocialNetwork string `json:"socialNetwork,omitempty"`
							} `json:"links"`
						} `json:"someArtists"`
						ArtistsCount int `json:"artistsCount"`
					} `json:"playlists"`
				} `json:"promo,omitempty"`
				Message          string `json:"message,omitempty"`
				Genre            string `json:"genre,omitempty"`
				RadioIsAvailable bool   `json:"radioIsAvailable,omitempty"`
				Tracks           []struct {
					DurationMs               int    `json:"durationMs"`
					FileSize                 int    `json:"fileSize"`
					Available                bool   `json:"available"`
					AvailableForPremiumUsers bool   `json:"availableForPremiumUsers"`
					LyricsAvailable          bool   `json:"lyricsAvailable"`
					ID                       string `json:"id"`
					RealID                   string `json:"realId"`
					Title                    string `json:"title"`
					StorageDir               string `json:"storageDir"`
					CoverURI                 string `json:"coverUri"`
					OgImage                  string `json:"ogImage"`
					Major                    struct {
						ID   int    `json:"id"`
						Name string `json:"name"`
					} `json:"major"`
					Normalization struct {
						Gain float64 `json:"gain"`
						Peak int     `json:"peak"`
					} `json:"normalization"`
					Artists []struct {
						ID       int           `json:"id"`
						Name     string        `json:"name"`
						Various  bool          `json:"various"`
						Composer bool          `json:"composer"`
						Genres   []interface{} `json:"genres"`
						Cover    struct {
							Type   string `json:"type"`
							Prefix string `json:"prefix"`
							URI    string `json:"uri"`
						} `json:"cover"`
					} `json:"artists"`
					Albums []struct {
						ID                       int           `json:"id"`
						Year                     int           `json:"year"`
						TrackCount               int           `json:"trackCount"`
						Recent                   bool          `json:"recent"`
						VeryImportant            bool          `json:"veryImportant"`
						Available                bool          `json:"available"`
						AvailableForPremiumUsers bool          `json:"availableForPremiumUsers"`
						AvailableForMobile       bool          `json:"availableForMobile"`
						AvailablePartially       bool          `json:"availablePartially"`
						Title                    string        `json:"title"`
						CoverURI                 string        `json:"coverUri"`
						OgImage                  string        `json:"ogImage"`
						Genre                    string        `json:"genre"`
						Buy                      []interface{} `json:"buy"`
						Bests                    []interface{} `json:"bests"`
						Artists                  []struct {
							ID       int    `json:"id"`
							Name     string `json:"name"`
							Various  bool   `json:"various"`
							Composer bool   `json:"composer"`
							Cover    struct {
								Type   string `json:"type"`
								Prefix string `json:"prefix"`
								URI    string `json:"uri"`
							} `json:"cover"`
							Genres []interface{} `json:"genres"`
						} `json:"artists"`
						Labels []struct {
							ID          int    `json:"id"`
							Name        string `json:"name"`
							Description string `json:"description"`
							Image       string `json:"image"`
						} `json:"labels"`
						TrackPosition struct {
							Volume int `json:"volume"`
							Index  int `json:"index"`
						} `json:"trackPosition"`
					} `json:"albums"`
				} `json:"tracks,omitempty"`
			} `json:"events"`
			TracksToPlay []struct {
				DurationMs               int    `json:"durationMs"`
				FileSize                 int    `json:"fileSize"`
				Available                bool   `json:"available"`
				AvailableForPremiumUsers bool   `json:"availableForPremiumUsers"`
				Best                     bool   `json:"best,omitempty"`
				LyricsAvailable          bool   `json:"lyricsAvailable"`
				ID                       string `json:"id"`
				RealID                   string `json:"realId"`
				Title                    string `json:"title"`
				StorageDir               string `json:"storageDir"`
				CoverURI                 string `json:"coverUri"`
				OgImage                  string `json:"ogImage"`
				Version                  string `json:"version,omitempty"`
				ContentWarning           string `json:"contentWarning,omitempty"`
				Major                    struct {
					ID   int    `json:"id"`
					Name string `json:"name"`
				} `json:"major"`
				Normalization struct {
					Gain float64 `json:"gain"`
					Peak int     `json:"peak"`
				} `json:"normalization"`
				Artists []struct {
					ID       int    `json:"id"`
					Name     string `json:"name"`
					Various  bool   `json:"various"`
					Composer bool   `json:"composer"`
					Cover    struct {
						Type   string `json:"type"`
						Prefix string `json:"prefix"`
						URI    string `json:"uri"`
					} `json:"cover"`
					Genres []interface{} `json:"genres"`
				} `json:"artists"`
				Albums []struct {
					ID                       int           `json:"id"`
					Year                     int           `json:"year"`
					TrackCount               int           `json:"trackCount"`
					Recent                   bool          `json:"recent"`
					VeryImportant            bool          `json:"veryImportant"`
					Available                bool          `json:"available"`
					AvailableForPremiumUsers bool          `json:"availableForPremiumUsers"`
					AvailableForMobile       bool          `json:"availableForMobile"`
					AvailablePartially       bool          `json:"availablePartially"`
					Title                    string        `json:"title"`
					Type                     string        `json:"type"`
					CoverURI                 string        `json:"coverUri"`
					OgImage                  string        `json:"ogImage"`
					Genre                    string        `json:"genre"`
					Bests                    []interface{} `json:"bests"`
					Buy                      []interface{} `json:"buy"`
					ReleaseDate              time.Time     `json:"releaseDate"`
					Artists                  []struct {
						ID       int    `json:"id"`
						Name     string `json:"name"`
						Various  bool   `json:"various"`
						Composer bool   `json:"composer"`
						Cover    struct {
							Type   string `json:"type"`
							Prefix string `json:"prefix"`
							URI    string `json:"uri"`
						} `json:"cover"`
						Genres []interface{} `json:"genres"`
					} `json:"artists"`
					Labels []struct {
						ID          int    `json:"id"`
						Name        string `json:"name"`
						Description string `json:"description"`
						Image       string `json:"image"`
					} `json:"labels"`
					TrackPosition struct {
						Volume int `json:"volume"`
						Index  int `json:"index"`
					} `json:"trackPosition"`
				} `json:"albums"`
			} `json:"tracksToPlay"`
			TracksToPlayWithAds []struct {
				Type  string `json:"type"`
				Track struct {
					ID                       string `json:"id"`
					RealID                   string `json:"realId"`
					Title                    string `json:"title"`
					DurationMs               int    `json:"durationMs"`
					FileSize                 int    `json:"fileSize"`
					Available                bool   `json:"available"`
					AvailableForPremiumUsers bool   `json:"availableForPremiumUsers"`
					LyricsAvailable          bool   `json:"lyricsAvailable"`
					StorageDir               string `json:"storageDir"`
					CoverURI                 string `json:"coverUri"`
					OgImage                  string `json:"ogImage"`
					Major                    struct {
						ID   int    `json:"id"`
						Name string `json:"name"`
					} `json:"major"`
					Normalization struct {
						Gain float64 `json:"gain"`
						Peak int     `json:"peak"`
					} `json:"normalization"`
					Artists []struct {
						ID       int    `json:"id"`
						Name     string `json:"name"`
						Various  bool   `json:"various"`
						Composer bool   `json:"composer"`
						Cover    struct {
							Type   string `json:"type"`
							Prefix string `json:"prefix"`
							URI    string `json:"uri"`
						} `json:"cover"`
						Genres []interface{} `json:"genres"`
					} `json:"artists"`
					Albums []struct {
						ID                       int           `json:"id"`
						Year                     int           `json:"year"`
						TrackCount               int           `json:"trackCount"`
						Recent                   bool          `json:"recent"`
						VeryImportant            bool          `json:"veryImportant"`
						Available                bool          `json:"available"`
						AvailableForPremiumUsers bool          `json:"availableForPremiumUsers"`
						AvailableForMobile       bool          `json:"availableForMobile"`
						AvailablePartially       bool          `json:"availablePartially"`
						Title                    string        `json:"title"`
						Type                     string        `json:"type"`
						CoverURI                 string        `json:"coverUri"`
						OgImage                  string        `json:"ogImage"`
						Genre                    string        `json:"genre"`
						Bests                    []interface{} `json:"bests"`
						Buy                      []interface{} `json:"buy"`
						ReleaseDate              time.Time     `json:"releaseDate"`
						Artists                  []struct {
							ID       int    `json:"id"`
							Name     string `json:"name"`
							Various  bool   `json:"various"`
							Composer bool   `json:"composer"`
							Cover    struct {
								Type   string `json:"type"`
								Prefix string `json:"prefix"`
								URI    string `json:"uri"`
							} `json:"cover"`
							Genres []interface{} `json:"genres"`
						} `json:"artists"`
						Labels []struct {
							ID          int    `json:"id"`
							Name        string `json:"name"`
							Description string `json:"description"`
							Image       string `json:"image"`
						} `json:"labels"`
						TrackPosition struct {
							Volume int `json:"volume"`
							Index  int `json:"index"`
						} `json:"trackPosition"`
					} `json:"albums"`
				} `json:"track"`
			} `json:"tracksToPlayWithAds"`
		} `json:"days"`
	} `json:"result"`
}

FeedResp describes get feed method response

type FeedService

type FeedService struct {
	// contains filtered or unexported fields
}

FeedService is a service to deal with accounts.

func (*FeedService) Get

func (s *FeedService) Get(
	ctx context.Context,
) (*FeedResp, *http.Response, error)

Get returns feed of current user or base feed if there is no access token

type GenresListResp

type GenresListResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         []struct {
		Weight      int    `json:"weight"`
		TracksCount int    `json:"tracksCount"`
		ComposerTop bool   `json:"composerTop"`
		ShowInMenu  bool   `json:"showInMenu"`
		ID          string `json:"id"`
		Title       string `json:"title"`
		FullTitle   string `json:"fullTitle,omitempty"`
		URLPart     string `json:"urlPart,omitempty"`
		Color       string `json:"color,omitempty"`
		Titles      struct {
			Kk struct {
				Title string `json:"title"`
			} `json:"kk"`
			En struct {
				Title string `json:"title"`
			} `json:"en"`
			Be struct {
				Title     string `json:"title"`
				FullTitle string `json:"fullTitle"`
			} `json:"be"`
			Uk struct {
				Title string `json:"title"`
			} `json:"uk"`
			Ru struct {
				Title     string `json:"title"`
				FullTitle string `json:"fullTitle"`
			} `json:"ru"`
		} `json:"titles"`
		Images    struct{} `json:"images"`
		RadioIcon struct {
			BackgroundColor string `json:"backgroundColor"`
			ImageURL        string `json:"imageUrl"`
		} `json:"radioIcon,omitempty"`
		SubGenres []struct {
			Weight      int    `json:"weight"`
			TracksCount int    `json:"tracksCount"`
			ComposerTop bool   `json:"composerTop"`
			ShowInMenu  bool   `json:"showInMenu"`
			URLPart     string `json:"urlPart"`
			ID          string `json:"id"`
			Title       string `json:"title"`
			FullTitle   string `json:"fullTitle,omitempty"`
			Color       string `json:"color"`
			Titles      struct {
				En struct {
					Title     string `json:"title"`
					FullTitle string `json:"fullTitle"`
				} `json:"en"`
				Be struct {
					Title     string `json:"title"`
					FullTitle string `json:"fullTitle"`
				} `json:"be"`
				Uk struct {
					Title     string `json:"title"`
					FullTitle string `json:"fullTitle"`
				} `json:"uk"`
				Ru struct {
					Title     string `json:"title"`
					FullTitle string `json:"fullTitle"`
				} `json:"ru"`
			} `json:"titles"`
			Images struct {
				Two08X208   string `json:"208x208"`
				Three00X300 string `json:"300x300"`
			} `json:"images"`
			RadioIcon struct {
				BackgroundColor string `json:"backgroundColor"`
				ImageURL        string `json:"imageUrl"`
			} `json:"radioIcon"`
		} `json:"subGenres,omitempty"`
	} `json:"result"`
}

GenresListResp describes genres method response.

type GenresService

type GenresService struct {
	// contains filtered or unexported fields
}

GenresService is a service to deal with genres.

func (*GenresService) List

List returns list of existed genres.

type InvocationInfo

type InvocationInfo struct {
	Hostname string `json:"hostname"`
	ReqID    string `json:"req-id"`
	// ExecDurationMillis sometimes int, sometimes string so saving interface{}
	ExecDurationMillis interface{} `json:"exec-duration-millis"`
}

InvocationInfo is base info in all requests

type Label

type Label struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Image       string `json:"image"`
}

type Labels

type Labels []Label

type LikeResp

type LikeResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         struct {
		Revision int `json: revision`
	}
}

type LikesService

type LikesService struct {
	// contains filtered or unexported fields
}

func (*LikesService) Dislike

func (s *LikesService) Dislike(
	ctx context.Context,
	entity string,
	ids []string,
) (*LikeResp, *http.Response, error)

func (*LikesService) Like

func (s *LikesService) Like(
	ctx context.Context,
	entity string,
	ids []string,
) (*LikeResp, *http.Response, error)

type PlaylistsAddTracksOptions

type PlaylistsAddTracksOptions struct {
	At int
}

PlaylistsAddTracksOptions are options for method AddTracks

type PlaylistsAddTracksResp

type PlaylistsAddTracksResp struct {
	InvocationInfo InvocationInfo  `json:"invocationInfo"`
	Error          Error           `json:"error"`
	Result         PlaylistsResult `json:"result"`
}

PlaylistsAddTracksResp describes method add tracks response

type PlaylistsCover

type PlaylistsCover struct {
	Error    string   `json:"error"`
	Type     string   `json:"type"`
	ItemsURI []string `json:"itemsUri"`
	Custom   bool     `json:"custom"`
	Dir      string   `json:"dir"`
	Version  string   `json:"version"`
	URI      string   `json:"uri"`
}

PlaylistsCover is cover of playlist response

type PlaylistsCreateResp

type PlaylistsCreateResp struct {
	InvocationInfo InvocationInfo  `json:"invocationInfo"`
	Error          Error           `json:"error"`
	Result         PlaylistsResult `json:"result"`
}

PlaylistsCreateResp describes method create playlist response

type PlaylistsDeleteResp

type PlaylistsDeleteResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         string         `json:"result"`
}

PlaylistsDeleteResp describes method delete playlist response

type PlaylistsGetByKindOptions

type PlaylistsGetByKindOptions struct {
	Kinds      []int
	Mixed      bool
	RichTracks bool
}

PlaylistsGetByKindOptions options for GetByKinds method

type PlaylistsGetByKindsResp

type PlaylistsGetByKindsResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         []struct {
		PlaylistsResult
		Tracks []struct {
			ID        int       `json:"id"`
			AlbumID   int       `json:"albumId"`
			Timestamp time.Time `json:"timestamp"`
		} `json:"tracks"`
	} `json:"result"`
}

PlaylistsGetByKindsResp describes get user's playlists by kinds response

type PlaylistsGetResp

type PlaylistsGetResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         struct {
		PlaylistsResult
		Tracks Tracks `json:"tracks"`
	} `json:"result"`
}

PlaylistsGetResp describes get user's playlist by kind response

type PlaylistsListResp

type PlaylistsListResp struct {
	InvocationInfo InvocationInfo    `json:"invocationInfo"`
	Error          Error             `json:"error"`
	Result         []PlaylistsResult `json:"result"`
}

PlaylistsListResp describes get user's playlists response

type PlaylistsOwner

type PlaylistsOwner struct {
	UID      int    `json:"uid"`
	Login    string `json:"login"`
	Name     string `json:"name"`
	Sex      string `json:"sex"`
	Verified bool   `json:"verified"`
}

PlaylistsOwner is owner of playlist response

type PlaylistsRemoveTracksOptions

type PlaylistsRemoveTracksOptions struct {
	From int
	To   int
}

PlaylistsRemoveTracksOptions are options for method RemoveTracks

type PlaylistsRemoveTracksResp

type PlaylistsRemoveTracksResp struct {
	InvocationInfo InvocationInfo  `json:"invocationInfo"`
	Error          Error           `json:"error"`
	Result         PlaylistsResult `json:"result"`
}

PlaylistsRemoveTracksResp describes method add tracks response

type PlaylistsRenameResp

type PlaylistsRenameResp struct {
	InvocationInfo InvocationInfo  `json:"invocationInfo"`
	Error          Error           `json:"error"`
	Result         PlaylistsResult `json:"result"`
}

PlaylistsRenameResp describes method rename playlist response

type PlaylistsResult

type PlaylistsResult struct {
	UID                int            `json:"uid"`
	Kind               int            `json:"kind"`
	Revision           int            `json:"revision"`
	TrackCount         int            `json:"trackCount"`
	DurationMs         int            `json:"durationMs"`
	Collective         bool           `json:"collective"`
	Available          bool           `json:"available"`
	IsBanner           bool           `json:"isBanner"`
	IsPremiere         bool           `json:"isPremiere"`
	Title              string         `json:"title"`
	Description        string         `json:"description"`
	Visibility         string         `json:"visibility"`
	OgImage            string         `json:"ogImage"`
	Created            time.Time      `json:"created"`
	Modified           time.Time      `json:"modified"`
	Cover              PlaylistsCover `json:"cover"`
	Owner              PlaylistsOwner `json:"owner"`
	Tags               []interface{}  `json:"tags"`
	LastOwnerPlaylists []struct {
		UID        int            `json:"uid"`
		Kind       int            `json:"kind"`
		Revision   int            `json:"revision"`
		TrackCount int            `json:"trackCount"`
		DurationMs int            `json:"durationMs"`
		Collective bool           `json:"collective"`
		Available  bool           `json:"available"`
		IsBanner   bool           `json:"isBanner"`
		IsPremiere bool           `json:"isPremiere"`
		Title      string         `json:"title"`
		Visibility string         `json:"visibility"`
		OgImage    string         `json:"ogImage"`
		Created    time.Time      `json:"created"`
		Modified   time.Time      `json:"modified"`
		Tags       []interface{}  `json:"tags"`
		Owner      PlaylistsOwner `json:"owner"`
		Cover      PlaylistsCover `json:"cover"`
	} `json:"lastOwnerPlaylists"`
}

PlaylistsResult is base result of methods AddTracks and RemoveTracks

type PlaylistsService

type PlaylistsService struct {
	// contains filtered or unexported fields
}

PlaylistsService is a service to deal with accounts.

func (*PlaylistsService) AddTracks

func (s *PlaylistsService) AddTracks(
	ctx context.Context,
	kind int,
	revision int,
	tracks []PlaylistsTrack,
	opts *PlaylistsAddTracksOptions,
) (*PlaylistsAddTracksResp, *http.Response, error)

AddTracks adds tracks to playlist

func (*PlaylistsService) Create

func (s *PlaylistsService) Create(
	ctx context.Context,
	title string,
	isPublic bool,
) (*PlaylistsCreateResp, *http.Response, error)

Create creates playlist for current user

func (*PlaylistsService) Delete

func (s *PlaylistsService) Delete(
	ctx context.Context,
	kind int,
) (*PlaylistsDeleteResp, *http.Response, error)

Delete deletes playlist for current user

func (*PlaylistsService) Get

func (s *PlaylistsService) Get(
	ctx context.Context,
	userID int,
	kind int,
) (*PlaylistsGetResp, *http.Response, error)

Get returns playlist of the user by kind

func (*PlaylistsService) GetByKinds

GetByKinds returns several playlists by kinds with track ids

func (*PlaylistsService) GetByUserIDAndKind

func (s *PlaylistsService) GetByUserIDAndKind(
	ctx context.Context,
	userID string,
	kind int,
) (*PlaylistsGetResp, *http.Response, error)

func (*PlaylistsService) List

func (s *PlaylistsService) List(
	ctx context.Context,
	userID int,
) (*PlaylistsListResp, *http.Response, error)

List returns playlists of the user

func (*PlaylistsService) RemoveTracks

func (s *PlaylistsService) RemoveTracks(
	ctx context.Context,
	kind int,
	revision int,
	tracks []PlaylistsTrack,
	opts *PlaylistsRemoveTracksOptions,
) (*PlaylistsRemoveTracksResp, *http.Response, error)

RemoveTracks removes tracks from playlist

func (*PlaylistsService) Rename

func (s *PlaylistsService) Rename(
	ctx context.Context,
	kind int,
	newName string,
) (*PlaylistsRenameResp, *http.Response, error)

Rename renames playlist of current user

type PlaylistsTrack

type PlaylistsTrack struct {
	ID      int `json:"id"`
	AlbumID int `json:"albumId"`
}

PlaylistsTrack is track object with trackId and albumId that is used in add tracks and remove tracks requests

type SearchOptions

type SearchOptions struct {
	Page      int
	NoCorrect bool
}

SearchOptions defines search options like pagination and correction

type SearchResp

type SearchResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         struct {
		MisspellCorrected bool   `json:"misspellCorrected"`
		Nocorrect         bool   `json:"nocorrect"`
		SearchRequestID   string `json:"searchRequestId"`
		Text              string `json:"text"`
		MisspellResult    string `json:"misspellResult"`
		MisspellOriginal  string `json:"misspellOriginal"`
		Best              struct {
			Type   string       `json:"type"`
			Result SearchResult `json:"result"`
		} `json:"best"`
		Tracks struct {
			Total   int `json:"total"`
			PerPage int `json:"perPage"`
			Results []struct {
				ID             int      `json:"id"`
				DurationMs     int      `json:"durationMs"`
				Available      bool     `json:"available"`
				AvailableAsRbt bool     `json:"availableAsRbt"`
				Explicit       bool     `json:"explicit"`
				StorageDir     string   `json:"storageDir"`
				Title          string   `json:"title"`
				Version        string   `json:"version,omitempty"`
				Regions        []string `json:"regions"`
				Albums         []struct {
					ID                  int           `json:"id"`
					StorageDir          string        `json:"storageDir"`
					OriginalReleaseYear int           `json:"originalReleaseYear"`
					Year                int           `json:"year"`
					Title               string        `json:"title"`
					Artists             []interface{} `json:"artists"`
					CoverURI            string        `json:"coverUri"`
					TrackCount          int           `json:"trackCount"`
					Genre               string        `json:"genre"`
					Available           bool          `json:"available"`
					TrackPosition       struct {
						Volume int `json:"volume"`
						Index  int `json:"index"`
					} `json:"trackPosition"`
				} `json:"albums"`
				Artists []struct {
					ID    int `json:"id"`
					Cover struct {
						Type   string `json:"type"`
						Prefix string `json:"prefix"`
						URI    string `json:"uri"`
					} `json:"cover"`
					Composer   bool          `json:"composer"`
					Various    bool          `json:"various"`
					Name       string        `json:"name"`
					Decomposed []interface{} `json:"decomposed"`
				} `json:"artists"`
			} `json:"results"`
		} `json:"tracks"`
		Playlists struct {
			Total   int `json:"total"`
			PerPage int `json:"perPage"`
			Results []struct {
				UID        int    `json:"uid"`
				Kind       int    `json:"kind"`
				TrackCount int    `json:"trackCount"`
				Title      string `json:"title"`
				Owner      struct {
					UID      int    `json:"uid"`
					Login    string `json:"login"`
					Name     string `json:"name"`
					Verified bool   `json:"verified"`
				} `json:"owner"`
				Cover struct {
					Type     string   `json:"type"`
					ItemsURI []string `json:"itemsUri"`
					Custom   bool     `json:"custom"`
				} `json:"cover"`
				Tags    []interface{} `json:"tags"`
				Regions []string      `json:"regions"`
			} `json:"results"`
		} `json:"playlists"`
		Artists struct {
			Total   int            `json:"total"`
			PerPage int            `json:"perPage"`
			Results []SearchResult `json:"results"`
		} `json:"artists"`
		Videos struct {
			Total   int `json:"total"`
			PerPage int `json:"perPage"`
			Results []struct {
				YoutubeURL              string   `json:"youtubeUrl"`
				ThumbnailURL            string   `json:"thumbnailUrl"`
				Title                   string   `json:"title"`
				Duration                int      `json:"duration"`
				Text                    string   `json:"text"`
				HTMLAutoPlayVideoPlayer string   `json:"htmlAutoPlayVideoPlayer"`
				Regions                 []string `json:"regions"`
			} `json:"results"`
		} `json:"videos"`
		Albums struct {
			Total   int `json:"total"`
			PerPage int `json:"perPage"`
			Results []struct {
				ID                  int    `json:"id"`
				StorageDir          string `json:"storageDir"`
				OriginalReleaseYear int    `json:"originalReleaseYear"`
				Year                int    `json:"year"`
				Title               string `json:"title"`
				Artists             []struct {
					ID    int `json:"id"`
					Cover struct {
						Type   string `json:"type"`
						Prefix string `json:"prefix"`
						URI    string `json:"uri"`
					} `json:"cover"`
					Composer   bool          `json:"composer"`
					Various    bool          `json:"various"`
					Name       string        `json:"name"`
					Decomposed []interface{} `json:"decomposed"`
				} `json:"artists"`
				CoverURI   string   `json:"coverUri"`
				TrackCount int      `json:"trackCount"`
				Genre      string   `json:"genre"`
				Available  bool     `json:"available"`
				Regions    []string `json:"regions"`
			} `json:"results"`
		} `json:"albums"`
	} `json:"result"`
}

SearchResp describes search method response.

type SearchResult

type SearchResult struct {
	ID               int      `json:"id"`
	Composer         bool     `json:"composer"`
	Various          bool     `json:"various"`
	TicketsAvailable bool     `json:"ticketsAvailable"`
	Name             string   `json:"name"`
	Genres           []string `json:"genres"`
	Regions          []string `json:"regions"`
	Cover            struct {
		Type   string `json:"type"`
		Prefix string `json:"prefix"`
		URI    string `json:"uri"`
	} `json:"cover"`
	Counts struct {
		Tracks       int `json:"tracks"`
		DirectAlbums int `json:"directAlbums"`
		AlsoAlbums   int `json:"alsoAlbums"`
		AlsoTracks   int `json:"alsoTracks"`
	} `json:"counts"`
	PopularTracks []struct {
		ID             int           `json:"id"`
		DurationMs     int           `json:"durationMs"`
		Available      bool          `json:"available"`
		AvailableAsRbt bool          `json:"availableAsRbt"`
		Explicit       bool          `json:"explicit"`
		StorageDir     string        `json:"storageDir"`
		Title          string        `json:"title"`
		Regions        []string      `json:"regions"`
		Artists        []interface{} `json:"artists"`
		Albums         []struct {
			ID            int           `json:"id"`
			StorageDir    string        `json:"storageDir"`
			Title         string        `json:"title"`
			Artists       []interface{} `json:"artists"`
			CoverURI      string        `json:"coverUri"`
			TrackCount    int           `json:"trackCount"`
			Genre         string        `json:"genre"`
			Available     bool          `json:"available"`
			TrackPosition struct {
				Volume int `json:"volume"`
				Index  int `json:"index"`
			} `json:"trackPosition"`
		} `json:"albums"`
	} `json:"popularTracks"`
}

SearchResult search result json

type SearchService

type SearchService struct {
	// contains filtered or unexported fields
}

SearchService is a service to deal with genres.

func (*SearchService) Albums

func (s *SearchService) Albums(
	ctx context.Context,
	query string,
	opts *SearchOptions,
) (*SearchResp, *http.Response, error)

Albums searches albums by query

func (*SearchService) All

func (s *SearchService) All(
	ctx context.Context,
	query string,
	opts *SearchOptions,
) (*SearchResp, *http.Response, error)

All searches all(artists, albums, tracks) by query

func (*SearchService) Artists

func (s *SearchService) Artists(
	ctx context.Context,
	query string,
	opts *SearchOptions,
) (*SearchResp, *http.Response, error)

Artists searches artists by query

func (*SearchService) Tracks

func (s *SearchService) Tracks(
	ctx context.Context,
	query string,
	opts *SearchOptions,
) (*SearchResp, *http.Response, error)

Tracks searches tracks by query

type Track

type Track struct {
	ID             string `json:"id"`
	RealID         string `json:"realId"`
	Title          string `json:"title"`
	ContentWarning string `json:"contentWarning"`
	TrackSource    string `json:"trackSource"`
	Major          struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"major"`
	Available                      bool     `json:"available"`
	AvailableForPremiumUsers       bool     `json:"availableForPremiumUsers"`
	AvailableFullWithoutPermission bool     `json:"availableFullWithoutPermission"`
	AvailableForOptions            []string `json:"availableForOptions"`
	DurationMs                     int      `json:"durationMs"`
	StorageDir                     string   `json:"storageDir"`
	FileSize                       int      `json:"fileSize"`
	R128                           struct {
		I  float64 `json:"i"`
		Tp float64 `json:"tp"`
	} `json:"r128"`
	PreviewDurationMs int     `json:"previewDurationMs"`
	Artists           Artists `json:"artists"`
	Albums            Albums  `json:"albums"`
	CoverURI          string  `json:"coverUri"`
	OgImage           string  `json:"ogImage"`
	LyricsAvailable   bool    `json:"lyricsAvailable"`
	LyricsInfo        struct {
		HasAvailableSyncLyrics bool `json:"hasAvailableSyncLyrics"`
		HasAvailableTextLyrics bool `json:"hasAvailableTextLyrics"`
	} `json:"lyricsInfo"`
	Type             string `json:"type"`
	RememberPosition bool   `json:"rememberPosition"`
	TrackSharingFlag string `json:"trackSharingFlag"`
}

type TrackError

type TrackError string

func (TrackError) Error

func (te TrackError) Error() string

type TrackFull

type TrackFull struct {
	ID        int       `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Recent    bool      `json:"recent"`
	Track     Track     `json:"track"`
}

type TrackResp

type TrackResp struct {
	InvocationInfo InvocationInfo `json:"invocationInfo"`
	Error          Error          `json:"error"`
	Result         []Track        `json:"result"`
}

type Tracks

type Tracks []TrackFull

type TracksService

type TracksService struct {
	// contains filtered or unexported fields
}

TracksService is a service to deal with tracks

func (*TracksService) Get

func (t *TracksService) Get(ctx context.Context, id int) (*TrackResp, *http.Response, error)

Get returns track by its ID

func (*TracksService) GetDownloadInfo

func (t *TracksService) GetDownloadInfo(ctx context.Context, id int) (*DownloadInfo, *http.Response, error)

GetDownloadInfo returns DownloadInfo by id of track. Be careful: it uses the same context for GetDownloadInfoResp and its request

func (*TracksService) GetDownloadInfoResp

func (t *TracksService) GetDownloadInfoResp(ctx context.Context, id int) (*DownloadInfoResp, *http.Response, error)

GetDownloadInfoResp returns DownloadInfoResp byt track's ID Be careful: you can get DownloadInfo by DownloadInfoURL only for one minute since you called GetDownloadInfoResp

func (*TracksService) GetDownloadURL

func (t *TracksService) GetDownloadURL(ctx context.Context, id int) (string, error)

GetDownloadURL computes path to track by ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL