Documentation
¶
Overview ¶
Package api provides a client for interacting with the Last.fm API. It includes methods for constructing API URLs, generating signatures, and making unauthenticated requests to various Last.fm API endpoints.
The package supports multiple levels of authorization, including API key, secret, and session-based authentication. It also provides utilities for parsing parameters, handling retries, and unmarshaling XML responses.
The main entry point for interacting with the API is the `Client` struct, which provides access to specific service modules such as Album, Artist, User, and more.
Key Features:
- Build API URLs with query parameters.
- Generate signatures for API requests using the API secret.
- Make GET and POST requests to the API with automatic XML unmarshaling.
Usage:
- Create a new Client with your API key and optionally, your secret.
- Use the Client to access specific API methods
- Handle responses and errors using the provided types and utilities.
- Customize the client with user agent and timeout settings.
- Use the `Request` method for general-purpose API requests.
For more information about the Last.fm API, visit: https://www.last.fm/api
Index ¶
- Constants
- Variables
- func AuthURL(params AuthURLParams) string
- func BuildAPIURL(params url.Values) string
- func Signature(params url.Values, secret string) string
- type API
- func (a *API) AuthCallbackURL(callbackURL string) string
- func (a *API) AuthTokenURL(token string) string
- func (a *API) AuthURL() string
- func (a *API) CheckCredentials(level RequestLevel) error
- func (a *API) Get(dest any, method APIMethod, params any) error
- func (a *API) GetSigned(dest any, method APIMethod, params any) error
- func (a *API) GetURL(dest any, url string) error
- func (a *API) Post(dest any, method APIMethod, params any) error
- func (a *API) PostBody(dest any, url, body string) error
- func (a *API) PostSigned(dest any, method APIMethod, params any) error
- func (a *API) Request(dest any, httpMethod string, method APIMethod, params any) error
- func (a *API) RequestSigned(dest any, httpMethod string, method APIMethod, params any) error
- func (a *API) SetRetries(retries uint)
- func (a *API) SetUserAgent(userAgent string)
- func (a *API) Signature(params url.Values) string
- type APIMethod
- type Album
- func (a Album) Info(params lastfm.AlbumInfoParams) (*lastfm.AlbumInfo, error)
- func (a Album) InfoByMBID(params lastfm.AlbumInfoMBIDParams) (*lastfm.AlbumInfo, error)
- func (a Album) Search(params lastfm.AlbumSearchParams) (*lastfm.AlbumSearchResult, error)
- func (a Album) TopTags(params lastfm.AlbumTopTagsParams) (*lastfm.AlbumTopTags, error)
- func (a Album) TopTagsByMBID(params lastfm.AlbumTopTagsMBIDParams) (*lastfm.AlbumTopTags, error)deprecated
- func (a Album) UserInfo(params lastfm.AlbumUserInfoParams) (*lastfm.AlbumUserInfo, error)
- func (a Album) UserInfoByMBID(params lastfm.AlbumUserInfoMBIDParams) (*lastfm.AlbumUserInfo, error)
- func (a Album) UserTags(params lastfm.AlbumTagsParams) (*lastfm.AlbumTags, error)
- func (a Album) UserTagsByMBID(params lastfm.AlbumTagsMBIDParams) (*lastfm.AlbumTags, error)
- type Artist
- func (a Artist) Correction(artist string) (*lastfm.ArtistCorrection, error)
- func (a Artist) Info(params lastfm.ArtistInfoParams) (*lastfm.ArtistInfo, error)
- func (a Artist) InfoByMBID(params lastfm.ArtistInfoMBIDParams) (*lastfm.ArtistInfo, error)
- func (a Artist) Search(params lastfm.ArtistSearchParams) (*lastfm.ArtistSearchResult, error)
- func (a Artist) Similar(params lastfm.ArtistSimilarParams) (*lastfm.SimilarArtists, error)
- func (a Artist) SimilarByMBID(params lastfm.ArtistSimilarMBIDParams) (*lastfm.SimilarArtists, error)
- func (a Artist) TopAlbums(params lastfm.ArtistTopAlbumsParams) (*lastfm.ArtistTopAlbums, error)
- func (a Artist) TopAlbumsByMBID(params lastfm.ArtistTopAlbumsMBIDParams) (*lastfm.ArtistTopAlbums, error)
- func (a Artist) TopTags(params lastfm.ArtistTopTagsParams) (*lastfm.ArtistTopTags, error)
- func (a Artist) TopTagsByMBID(params lastfm.ArtistTopTagsMBIDParams) (*lastfm.ArtistTopTags, error)
- func (a Artist) TopTracks(params lastfm.ArtistTopTracksParams) (*lastfm.ArtistTopTracks, error)
- func (a Artist) TopTracksByMBID(params lastfm.ArtistTopTracksMBIDParams) (*lastfm.ArtistTopTracks, error)
- func (a Artist) UserInfo(params lastfm.ArtistUserInfoParams) (*lastfm.ArtistUserInfo, error)
- func (a Artist) UserInfoByMBID(params lastfm.ArtistUserInfoMBIDParams) (*lastfm.ArtistUserInfo, error)
- func (a Artist) UserTags(params lastfm.ArtistTagsParams) (*lastfm.ArtistTags, error)
- func (a Artist) UserTagsByMBID(params lastfm.ArtistTagsMBIDParams) (*lastfm.ArtistTags, error)
- type Auth
- type AuthURLParams
- type Chart
- func (c Chart) TopArtists() (*lastfm.ChartTopArtists, error)
- func (c Chart) TopArtistsLimit(params *lastfm.ChartTopArtistsParams) (*lastfm.ChartTopArtists, error)
- func (c Chart) TopTags() (*lastfm.ChartTopTags, error)
- func (c Chart) TopTagsLimit(params *lastfm.ChartTopTagsParams) (*lastfm.ChartTopTags, error)
- func (c Chart) TopTracks() (*lastfm.ChartTopTracks, error)
- func (c Chart) TopTracksLimit(params *lastfm.ChartTopTracksParams) (*lastfm.ChartTopTracks, error)
- type Client
- type ErrorCode
- type Geo
- type HTTPClient
- type HTTPError
- type LFMWrapper
- type LastFMError
- func (e *LastFMError) Error() string
- func (e *LastFMError) HasErrorCode() bool
- func (e *LastFMError) Is(target error) bool
- func (e *LastFMError) IsCode(code ErrorCode) bool
- func (e *LastFMError) ShouldRetry() bool
- func (e *LastFMError) Unwrap() error
- func (e *LastFMError) WrapHTTPError(httpError *HTTPError) *LastFMError
- func (e *LastFMError) WrapResponse(res *http.Response) *LastFMError
- type Library
- type RequestLevel
- type Tag
- func (t Tag) Info(params lastfm.TagInfoParams) (*lastfm.TagInfo, error)
- func (t Tag) Similar(tag string) (*lastfm.SimilarTags, error)
- func (t Tag) TopAlbums(params lastfm.TagTopAlbumsParams) (*lastfm.TagTopAlbums, error)
- func (t Tag) TopArtists(params lastfm.TagTopArtistsParams) (*lastfm.TagTopArtists, error)
- func (t Tag) TopTags() (*lastfm.TagTopTags, error)
- func (t Tag) TopTagsLimit(params *lastfm.TagTopTagsParams) (*lastfm.TagTopTags, error)
- func (t Tag) TopTracks(params lastfm.TagTopTracksParams) (*lastfm.TagTopTracks, error)
- func (t Tag) WeeklyChartList(tag string) (*lastfm.TagWeeklyChartList, error)
- type Track
- func (t Track) Correction(artist, track string) (*lastfm.TrackCorrection, error)
- func (t Track) Info(params lastfm.TrackInfoParams) (*lastfm.TrackInfo, error)
- func (t Track) InfoByMBID(params lastfm.TrackInfoMBIDParams) (*lastfm.TrackInfo, error)
- func (t Track) Search(params lastfm.TrackSearchParams) (*lastfm.TrackSearchResult, error)
- func (t Track) Similar(params lastfm.TrackSimilarParams) (*lastfm.SimilarTracks, error)
- func (t Track) SimilarByMBID(params lastfm.TrackSimilarMBIDParams) (*lastfm.SimilarTracks, error)
- func (t Track) Tags(params lastfm.TrackTagsParams) (*lastfm.TrackTags, error)
- func (t Track) TagsByMBID(params lastfm.TrackTagsMBIDParams) (*lastfm.TrackTags, error)
- func (t Track) TopTags(params lastfm.TrackTopTagsParams) (*lastfm.TrackTopTags, error)
- func (t Track) TopTagsByMBID(params lastfm.TrackTopTagsMBIDParams) (*lastfm.TrackTopTags, error)
- func (t Track) UserInfo(params lastfm.TrackUserInfoParams) (*lastfm.TrackUserInfo, error)
- func (t Track) UserInfoByMBID(params lastfm.TrackUserInfoMBIDParams) (*lastfm.TrackUserInfo, error)
- type User
- func (u User) Friends(params lastfm.FriendsParams) (*lastfm.Friends, error)
- func (u User) Info(user string) (*lastfm.UserInfo, error)
- func (u User) LovedTracks(params lastfm.LovedTracksParams) (*lastfm.LovedTracks, error)
- func (u User) RecentTrack(user string) (*lastfm.RecentTrack, error)
- func (u User) RecentTrackExtended(user string) (*lastfm.RecentTrackExtended, error)
- func (u User) RecentTracks(params lastfm.RecentTracksParams) (*lastfm.RecentTracks, error)
- func (u User) RecentTracksExtended(params lastfm.RecentTracksParams) (*lastfm.RecentTracksExtended, error)
- func (u User) TaggedAlbums(params lastfm.UserTagsParams) (*lastfm.UserAlbumTags, error)
- func (u User) TaggedArtists(params lastfm.UserTagsParams) (*lastfm.UserArtistTags, error)
- func (u User) TaggedTracks(params lastfm.UserTagsParams) (*lastfm.UserTrackTags, error)
- func (u User) TopAlbums(params lastfm.UserTopAlbumsParams) (*lastfm.UserTopAlbums, error)
- func (u User) TopArtists(params lastfm.UserTopArtistsParams) (*lastfm.UserTopArtists, error)
- func (u User) TopTags(params lastfm.UserTopTagsParams) (*lastfm.UserTopTags, error)
- func (u User) TopTracks(params lastfm.UserTopTracksParams) (*lastfm.UserTopTracks, error)
- func (u User) WeeklyAlbumChart(params lastfm.WeeklyAlbumChartParams) (*lastfm.WeeklyAlbumChart, error)
- func (u User) WeeklyArtistChart(params lastfm.WeeklyArtistChartParams) (*lastfm.WeeklyArtistChart, error)
- func (u User) WeeklyChartList(user string) (*lastfm.WeeklyChartList, error)
- func (u User) WeeklyTrackChart(params lastfm.WeeklyTrackChartParams) (*lastfm.WeeklyTrackChart, error)
Constants ¶
const ( DefaultUserAgent = "LastFM (https://github.com/twoscott/gobble-fm)" DefaultRetries uint = 5 DefaultTimeout = 30 )
const ( APIKeyMissingMessage = "API Key is missing" SecretRequiredMessage = "Method requires API secret" SessionRequiredMessage = "Method requires user authentication (session key)" )
Custom error messages.
Variables ¶
var ( BaseEndpoint = "https://ws.audioscrobbler.com" Version = "2.0" Endpoint = BaseEndpoint + "/" + Version + "/" )
Functions ¶
func AuthURL ¶
func AuthURL(params AuthURLParams) string
AuthURL returns the authentication URL for the Last.fm API with the specified parameters. This URL can be used to send users to Last.fm for authentication. The URL includes the API key and a callback URL if specified.
Parameters:
- params.APIKey: The Last.fm API key.
- params.Callback: The URL to redirect the user to and provided the authenticated token to as a query parameter.
- params.Token: The token for the user to authenticate.
Returns:
- The authentication URL as a string.
func BuildAPIURL ¶
BuildAPIURL constructs a Last.fm API URL with the specified parameters.
func Signature ¶
Signature generates a Last.fm API signature for the given parameters and secret. The signature is created by concatenating the sorted parameter keys and their values, followed by the secret. The resulting string is then hashed using MD5 to produce a hexadecimal representation of the hash.
Parameters:
- params: The parameters to include in the signature.
- secret: The secret key to use for signing the request.
Returns:
- A hexadecimal string representing the signature.
Types ¶
type API ¶
type API struct {
// APIKey is the Last.fm API key used to authenticate requests.
APIKey string
// Secret is the Last.fm API secret used to sign requests.
Secret string
// UserAgent is the user agent string sent with each request to the API.
UserAgent string
// Retries is the number of times to retry failed requests.
Retries uint
Client HTTPClient
}
API represents the Last.fm API client. It provides methods for making requests to the Last.fm API and handling responses. The API client is initialized with an API key and can be configured with a user agent and timeout settings. It also supports retries for failed requests.
func NewKeyOnly ¶ added in v1.0.7
NewKeyOnly returns a new instance of API with the given API key but without a Last.fm API secret. This is useful if you don't plan to use the API secret to sign requests to the API such as auth methods.
func NewWithTimeout ¶
NewWithTimeout returns a new instance of API with the given API key and timeout settings. The timeout is specified in seconds.
func (*API) AuthCallbackURL ¶
AuthCallbackURL returns the authorization URL for the Last.fm API with a callback URL. This URL can be used for web authentication to send users to Last.fm for authentication. The user will be redirected to the callback URL after and an authorized token query parameter will be appended to the URL.
func (*API) AuthTokenURL ¶
AuthTokenURL returns the authorization URL for the Last.fm API with a token. This URL can be used to send users to Last.fm for authentication where the provided token will be authorized.
func (*API) AuthURL ¶
AuthURL returns the authorization URL for the Last.fm API. This method should be used for web authentication if you set a callback URL when creating your API account. Otherwise, use AuthCallbackURL and provide a custom callback URL.
func (*API) CheckCredentials ¶
func (a *API) CheckCredentials(level RequestLevel) error
CheckCredentials verifies the authorization level required for an API request and ensures the necessary credentials are present. It checks the presence of the API secret for requests requiring a session or secret, and the API key for requests requiring an API key. Returns an error if required credentials are missing.
Parameters:
- level: The RequestLevel indicating the level of authorization required.
Returns:
- An error if the required authentication credentials are not present.
func (*API) Get ¶
Get sends an HTTP GET request to the API using the specified method and parameters, and decodes the response into the provided destination.
Parameters:
- dest: A pointer to the variable where the response will be unmarshaled.
- method: The APIMethod representing the endpoint to call.
- params: The parameters to include in the request.
Returns:
- An error if the request fails or the response cannot be decoded.
func (*API) GetSigned ¶
GetSigned sends an HTTP GET request to the API with the specified method and parameters, signed with the API secret. The response is unmarshaled into the provided destination.
func (*API) GetURL ¶
GetURL sends an HTTP GET request to the specified URL and unmarshals the response into the provided destination.
func (*API) Post ¶
Post sends an HTTP POST request to the API using the specified method and parameters, and decodes the response into the provided destination.
Parameters:
- dest: A pointer to the variable where the response will be unmarshaled.
- method: The APIMethod representing the endpoint to call.
- params: The parameters to include in the request.
Returns:
- An error if the request fails or the response cannot be decoded.
func (*API) PostBody ¶
PostBody sends an HTTP POST request to the specified URL with the given request body and unmarshals the response into the provided destination.
func (*API) PostSigned ¶
PostSigned sends an HTTP POST request to the API with the specified method and parameters, signed with the API secret. The response is unmarshaled into the provided destination.
func (*API) Request ¶
Request sends an HTTP request to the API with the specified parameters and unmarshals the response into the provided destination.
Parameters:
- dest: A pointer to the variable where the unmarshaled XML response will be stored.
- httpMethod: The HTTP method to use for the request (e.g., "GET", "POST").
- method: The API method to call, represented as an APIMethod type.
- params: The parameters to include in the API request, typically a struct that can be serialized into query parameters.
Returns:
- An error if the request fails, the response cannot be unmarshaled, or any other issue occurs.
func (*API) RequestSigned ¶
RequestSigned sends an HTTP request to the API with the specified method and parameters, signed with the API secret. The response is unmarshaled into the provided destination.
Parameters:
- dest: A pointer to the variable where the unmarshaled response will be stored.
- httpMethod: The HTTP method to use for the request (e.g., "GET", "POST").
- method: The API method to call, represented as an APIMethod type.
- params: The parameters to include in the API request, typically a struct that can be serialized into query parameters.
Returns:
- An error if the request fails, the response cannot be unmarshaled, or any other issue occurs.
func (*API) SetRetries ¶
SetRetries sets the number of retries for failed requests.
func (*API) SetUserAgent ¶
SetUserAgent sets the user agent for the API client.
func (*API) Signature ¶
Signature generates a signature for the given parameters using the API secret. The signature is created by concatenating the sorted parameter keys and their values, followed by the session secret. The resulting string is then hashed using MD5 to produce a hexadecimal representation of the hash.
type APIMethod ¶
type APIMethod string
APIMethod represents a Last.fm API method parameter.
const ( AlbumAddTagsMethod APIMethod = "album.addTags" AlbumGetInfoMethod APIMethod = "album.getInfo" AlbumGetTagsMethod APIMethod = "album.getTags" AlbumGetTopTagsMethod APIMethod = "album.getTopTags" AlbumRemoveTagMethod APIMethod = "album.removeTag" AlbumSearchMethod APIMethod = "album.search" ArtistAddTagsMethod APIMethod = "artist.addTags" ArtistGetCorrectionMethod APIMethod = "artist.getCorrection" ArtistGetInfoMethod APIMethod = "artist.getInfo" ArtistGetSimilarMethod APIMethod = "artist.getSimilar" ArtistGetTagsMethod APIMethod = "artist.getTags" ArtistGetTopAlbumsMethod APIMethod = "artist.getTopAlbums" ArtistGetTopTagsMethod APIMethod = "artist.getTopTags" ArtistGetTopTracksMethod APIMethod = "artist.getTopTracks" ArtistRemoveTagMethod APIMethod = "artist.removeTag" ArtistSearchMethod APIMethod = "artist.search" AuthGetMobileSessionMethod APIMethod = "auth.getMobileSession" AuthGetSessionMethod APIMethod = "auth.getSession" AuthGetTokenMethod APIMethod = "auth.getToken" ChartGetTopArtistsMethod APIMethod = "chart.getTopArtists" ChartGetTopTagsMethod APIMethod = "chart.getTopTags" ChartGetTopTracksMethod APIMethod = "chart.getTopTracks" GeoGetTopArtistsMethod APIMethod = "geo.getTopArtists" GeoGetTopTracksMethod APIMethod = "geo.getTopTracks" LibraryGetArtistsMethod APIMethod = "library.getArtists" TagGetInfoMethod APIMethod = "tag.getInfo" TagGetSimilarMethod APIMethod = "tag.getSimilar" TagGetTopAlbumsMethod APIMethod = "tag.getTopAlbums" TagGetTopArtistsMethod APIMethod = "tag.getTopArtists" TagGetTopTagsMethod APIMethod = "tag.getTopTags" TagGetTopTracksMethod APIMethod = "tag.getTopTracks" TagGetWeeklyChartListMethod APIMethod = "tag.getWeeklyChartList" TrackAddTagsMethod APIMethod = "track.addTags" TrackGetCorrectionMethod APIMethod = "track.getCorrection" TrackGetInfoMethod APIMethod = "track.getInfo" TrackGetSimilarMethod APIMethod = "track.getSimilar" TrackGetTagsMethod APIMethod = "track.getTags" TrackGetTopTagsMethod APIMethod = "track.getTopTags" TrackLoveMethod APIMethod = "track.love" TrackRemoveTagMethod APIMethod = "track.removeTag" TrackScrobbleMethod APIMethod = "track.scrobble" TrackSearchMethod APIMethod = "track.search" TrackUnloveMethod APIMethod = "track.unlove" TrackUpdateNowPlayingMethod APIMethod = "track.updateNowPlaying" UserGetFriendsMethod APIMethod = "user.getFriends" UserGetInfoMethod APIMethod = "user.getInfo" UserGetLovedTracksMethod APIMethod = "user.getLovedTracks" UserGetPersonalTagsMethod APIMethod = "user.getPersonalTags" UserGetRecentTracksMethod APIMethod = "user.getRecentTracks" UserGetTopAlbumsMethod APIMethod = "user.getTopAlbums" UserGetTopArtistsMethod APIMethod = "user.getTopArtists" UserGetTopTagsMethod APIMethod = "user.getTopTags" UserGetTopTracksMethod APIMethod = "user.getTopTracks" UserGetWeeklyAlbumChartMethod APIMethod = "user.getWeeklyAlbumChart" UserGetWeeklyArtistChartMethod APIMethod = "user.getWeeklyArtistChart" UserGetWeeklyChartListMethod APIMethod = "user.getWeeklyChartList" UserGetWeeklyTrackChartMethod APIMethod = "user.getWeeklyTrackChart" )
type Album ¶
type Album struct {
// contains filtered or unexported fields
}
func (Album) InfoByMBID ¶
InfoByMBID returns the information of an album by MBID.
func (Album) Search ¶
func (a Album) Search(params lastfm.AlbumSearchParams) (*lastfm.AlbumSearchResult, error)
Search returns the results of an album search.
func (Album) TopTags ¶
func (a Album) TopTags(params lastfm.AlbumTopTagsParams) (*lastfm.AlbumTopTags, error)
TopTags returns the top tags of an album by artist and album name.
func (Album) TopTagsByMBID
deprecated
func (a Album) TopTagsByMBID(params lastfm.AlbumTopTagsMBIDParams) (*lastfm.AlbumTopTags, error)
TopTagsByMBID returns the top tags of an album by MBID.
Deprecated: Fetching top tags by MBID doesn't seem to work. Use TopTags instead.
func (Album) UserInfo ¶ added in v1.0.4
func (a Album) UserInfo(params lastfm.AlbumUserInfoParams) (*lastfm.AlbumUserInfo, error)
UserInfo returns the information of an album for user by artist and album name.
func (Album) UserInfoByMBID ¶ added in v1.0.4
func (a Album) UserInfoByMBID( params lastfm.AlbumUserInfoMBIDParams) (*lastfm.AlbumUserInfo, error)
UserInfoByMBID returns the information of an album for user by MBID.
func (Album) UserTagsByMBID ¶
UserTagsByMBID returns the tags of an album for user by MBID.
type Artist ¶
type Artist struct {
// contains filtered or unexported fields
}
func (Artist) Correction ¶
func (a Artist) Correction(artist string) (*lastfm.ArtistCorrection, error)
Correction returns the artist name corrections of an artist.
func (Artist) Info ¶
func (a Artist) Info(params lastfm.ArtistInfoParams) (*lastfm.ArtistInfo, error)
Info returns the information of an artist by artist name.
func (Artist) InfoByMBID ¶
func (a Artist) InfoByMBID(params lastfm.ArtistInfoMBIDParams) (*lastfm.ArtistInfo, error)
InfoByMBID returns the information of an artist by MBID.
func (Artist) Search ¶
func (a Artist) Search(params lastfm.ArtistSearchParams) (*lastfm.ArtistSearchResult, error)
Search returns the results of an album search.
func (Artist) Similar ¶
func (a Artist) Similar(params lastfm.ArtistSimilarParams) (*lastfm.SimilarArtists, error)
Similar returns the similar artists of an artist by artist name.
func (Artist) SimilarByMBID ¶
func (a Artist) SimilarByMBID( params lastfm.ArtistSimilarMBIDParams) (*lastfm.SimilarArtists, error)
SimilarByMBID returns the similar artists of an artist by MBID.
func (Artist) TopAlbums ¶
func (a Artist) TopAlbums(params lastfm.ArtistTopAlbumsParams) (*lastfm.ArtistTopAlbums, error)
TopAlbums returns the top albums of an artist by artist name.
func (Artist) TopAlbumsByMBID ¶
func (a Artist) TopAlbumsByMBID( params lastfm.ArtistTopAlbumsMBIDParams) (*lastfm.ArtistTopAlbums, error)
TopAlbumsByMBID returns the top albums of an artist by MBID.
func (Artist) TopTags ¶
func (a Artist) TopTags(params lastfm.ArtistTopTagsParams) (*lastfm.ArtistTopTags, error)
TopTracks returns the top tracks of an artist by artist name.
func (Artist) TopTagsByMBID ¶
func (a Artist) TopTagsByMBID( params lastfm.ArtistTopTagsMBIDParams) (*lastfm.ArtistTopTags, error)
TopTagsByMBID returns the top tracks of an artist by MBID.
func (Artist) TopTracks ¶
func (a Artist) TopTracks(params lastfm.ArtistTopTracksParams) (*lastfm.ArtistTopTracks, error)
TopTracks returns the top tracks of an artist by artist name.
func (Artist) TopTracksByMBID ¶
func (a Artist) TopTracksByMBID( params lastfm.ArtistTopTracksMBIDParams) (*lastfm.ArtistTopTracks, error)
TopTracksByMBID returns the top tracks of an artist by MBID.
func (Artist) UserInfo ¶ added in v1.0.4
func (a Artist) UserInfo(params lastfm.ArtistUserInfoParams) (*lastfm.ArtistUserInfo, error)
UserInfo returns the information of an artist for user by artist name.
func (Artist) UserInfoByMBID ¶ added in v1.0.4
func (a Artist) UserInfoByMBID( params lastfm.ArtistUserInfoMBIDParams) (*lastfm.ArtistUserInfo, error)
UserInfoByMBID returns the information of an artist for user by MBID.
func (Artist) UserTags ¶
func (a Artist) UserTags(params lastfm.ArtistTagsParams) (*lastfm.ArtistTags, error)
UserTags returns the tags of an artist for user by artist name.
func (Artist) UserTagsByMBID ¶
func (a Artist) UserTagsByMBID(params lastfm.ArtistTagsMBIDParams) (*lastfm.ArtistTags, error)
UserTagsByMBID returns the tags of an artist for user by MBID.
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
func (Auth) MobileSession ¶
MobileSession returns a session for the given mobile user credentials. This session can be used to authenticate requests to the Last.fm API. The session is obtained by calling the AuthGetMobileSession method of the Last.fm API.
func (Auth) Session ¶
Session returns a session for the given token. This session can be used to authenticate requests to the Last.fm API. The session is obtained by calling the AuthGetSession method of the Last.fm API.
func (Auth) Token ¶
Token returns a session token for the Last.fm API. This token can be used to authenticate requests to the API. The token is obtained by calling the AuthGetToken method of the Last.fm API. The token is cached in the session, so subsequent calls to this method will return the same cached token.
type AuthURLParams ¶
type Chart ¶
type Chart struct {
// contains filtered or unexported fields
}
func (Chart) TopArtists ¶
func (c Chart) TopArtists() (*lastfm.ChartTopArtists, error)
TopArtists returns all the top artists of the chart. Same as TopArtistsLimit(nil).
func (Chart) TopArtistsLimit ¶
func (c Chart) TopArtistsLimit(params *lastfm.ChartTopArtistsParams) (*lastfm.ChartTopArtists, error)
TopArtistsLimit returns the top artists of the chart.
func (Chart) TopTags ¶
func (c Chart) TopTags() (*lastfm.ChartTopTags, error)
TopTags returns the top tags of the chart. Same as TopTagsLimit(nil).
func (Chart) TopTagsLimit ¶
func (c Chart) TopTagsLimit(params *lastfm.ChartTopTagsParams) (*lastfm.ChartTopTags, error)
TopTagsLimit returns the top tags of the chart.
func (Chart) TopTracks ¶
func (c Chart) TopTracks() (*lastfm.ChartTopTracks, error)
TopTracks returns all the top tracks of the chart. Same as TopTracksLimit(nil).
func (Chart) TopTracksLimit ¶
func (c Chart) TopTracksLimit(params *lastfm.ChartTopTracksParams) (*lastfm.ChartTopTracks, error)
TopTracksLimit returns the top tracks of the chart.
type Client ¶
type Client struct {
*API
Album *Album
Artist *Artist
Auth *Auth
Chart *Chart
Geo *Geo
Library *Library
Tag *Tag
Track *Track
User *User
}
Client is the main struct that provides access to various API services. It embeds the API struct and includes fields for accessing specific service modules such as Album, Artist, User, etc.
func NewClientKeyOnly ¶
NewClientKeyOnly returns a new instance of Client with the given API key but without a Last.fm API secret. This is useful if you don't plan to use the API secret to sign requests to the API such as auth methods.
func NewClientWithTimeout ¶
NewClientWithTimeout returns a new instance of Client with the given API key, secret, and timeout settings. The timeout is specified in seconds and is used to configure the HTTP client for making API requests. This allows for better control over network timeouts when interacting with the API.
type ErrorCode ¶
type ErrorCode int
const ( NoError ErrorCode = iota // 0 (No error) ErrInvalidService // 2 ErrInvalidMethod // 3 ErrAuthenticationFailed // 4 ErrInvalidFormat // 5 ErrInvalidParameters // 6 ErrInvalidResource // 7 ErrOperationFailed // 8 ErrInvalidSessionKey // 9 ErrInvalidAPIKey // 10 ErrServiceOffline // 11 ErrSubscribersOnly // 12 ErrInvalidMethodSignature // 13 ErrItemNotStreamable // 15 ErrUserNotLoggedIn // 17 ErrTrialExpired // 18 ErrNotEnoughContent // 20 ErrNotEnoughMembers // 21 ErrNotEnoughFans // 22 ErrNotEnoughNeighbours // 23 ErrNoPeakRadio // 24 ErrRadioNotFound // 25 ErrAPIKeySuspended // 26 ErrDeprecated // 27 ErrRateLimitExceeded // 29 )
ErrorCode represents an error code returned by the Last.fm API.
type Geo ¶
type Geo struct {
// contains filtered or unexported fields
}
func (Geo) TopArtists ¶
func (g Geo) TopArtists(params lastfm.GeoTopArtistsParams) (*lastfm.GeoTopArtists, error)
TopArtists returns the top artists of a country.
func (Geo) TopTracks ¶
func (g Geo) TopTracks(params lastfm.GeoTopTracksParams) (*lastfm.GeoTopTracks, error)
TopTracks returns the top tracks of a country.
type HTTPClient ¶
HTTPClient is an interface that defines the Do method for making HTTP requests. This allows for easier testing and mocking of HTTP requests.
type HTTPError ¶
HTTPError represents an error that occurred during an HTTP request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance from an HTTP response.
type LFMWrapper ¶
type LFMWrapper struct {
XMLName xml.Name `xml:"lfm"`
Status string `xml:"status,attr"`
InnerXML []byte `xml:",innerxml"`
}
func (*LFMWrapper) Empty ¶
func (lf *LFMWrapper) Empty() bool
Empty checks if the InnerXML is empty.
func (*LFMWrapper) StatusFailed ¶
func (lf *LFMWrapper) StatusFailed() bool
StatusFailed checks if the status is "failed".
func (*LFMWrapper) StatusOK ¶
func (lf *LFMWrapper) StatusOK() bool
StatusOK checks if the status is "ok".
func (*LFMWrapper) UnmarshalInnerXML ¶
func (lf *LFMWrapper) UnmarshalInnerXML(dest any) error
UnmarshalInnerXML unmarshals the InnerXML field into the provided destination variable.
func (*LFMWrapper) UnwrapError ¶
func (lf *LFMWrapper) UnwrapError() (*LastFMError, error)
UnwrapError attempts to extract and return a LastFMError from the LFMWrapper instance. If the status of the LFMWrapper indicates success, it returns nil for both the error and LastFMError. Otherwise, it unmarshals the InnerXML field into a LastFMError structure. If the unmarshaling succeeds and the LastFMError contains an error code, it returns the LastFMError. If no error code is present or unmarshaling fails, it returns an appropriate error.
type LastFMError ¶
type LastFMError struct {
Code ErrorCode `xml:"code,attr"`
Message string `xml:",chardata"`
// contains filtered or unexported fields
}
LastFMError represents an error returned by Last.fm.
func NewLastFMError ¶
func NewLastFMError(code ErrorCode, message string) *LastFMError
NewLastFMError creates a new LastFMError instance from an error code and message.
func (*LastFMError) Error ¶
func (e *LastFMError) Error() string
Error implements the error interface.
func (*LastFMError) HasErrorCode ¶
func (e *LastFMError) HasErrorCode() bool
HasErrorCode checks if the error code indicated an error (not 0).
func (*LastFMError) Is ¶
func (e *LastFMError) Is(target error) bool
Is checks if the error matches the target error.
func (*LastFMError) IsCode ¶
func (e *LastFMError) IsCode(code ErrorCode) bool
IsCode checks if the error code matches the given code.
func (*LastFMError) ShouldRetry ¶ added in v1.0.3
func (e *LastFMError) ShouldRetry() bool
ShouldRetry returns true if the error code indicates that the request can be retried.
func (*LastFMError) Unwrap ¶
func (e *LastFMError) Unwrap() error
Unwrap implements the error interface to return the underlying HTTP error.
func (*LastFMError) WrapHTTPError ¶
func (e *LastFMError) WrapHTTPError(httpError *HTTPError) *LastFMError
WrapHTTPError wraps an HTTP error into the LastFMError.
func (*LastFMError) WrapResponse ¶
func (e *LastFMError) WrapResponse(res *http.Response) *LastFMError
WrapNewHTTPError wraps a new HTTP error from a HTTP response into the LastFMError.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
func NewLibrary ¶
NewLibrary creates and returns a new Library API route.
func (Library) Artists ¶
func (l Library) Artists(params lastfm.LibraryArtistsParams) (*lastfm.LibraryArtists, error)
type RequestLevel ¶
type RequestLevel int
RequestLevel specifies the level of authorisation and authentication required for an API request.
const ( RequestLevelNone RequestLevel = iota RequestLevelAPIKey RequestLevelSecret RequestLevelSession )
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
func (Tag) Similar ¶
func (t Tag) Similar(tag string) (*lastfm.SimilarTags, error)
Similar returns tags similar to the given tag.
func (Tag) TopAlbums ¶
func (t Tag) TopAlbums(params lastfm.TagTopAlbumsParams) (*lastfm.TagTopAlbums, error)
TopAlbums returns the top albums tagged with the given tag.
func (Tag) TopArtists ¶
func (t Tag) TopArtists(params lastfm.TagTopArtistsParams) (*lastfm.TagTopArtists, error)
TopArtists returns the top artists tagged with the given tag.
func (Tag) TopTags ¶
func (t Tag) TopTags() (*lastfm.TagTopTags, error)
TopTags returns the top tags on Last.fm.
func (Tag) TopTagsLimit ¶
func (t Tag) TopTagsLimit(params *lastfm.TagTopTagsParams) (*lastfm.TagTopTags, error)
TopTagsLimit returns the top tags on Last.fm, with optional limit and offset.
func (Tag) TopTracks ¶
func (t Tag) TopTracks(params lastfm.TagTopTracksParams) (*lastfm.TagTopTracks, error)
TopTracks returns the top tracks tagged with the given tag.
func (Tag) WeeklyChartList ¶
func (t Tag) WeeklyChartList(tag string) (*lastfm.TagWeeklyChartList, error)
WeeklyChartList returns the weekly chart list of a tag.
type Track ¶
type Track struct {
// contains filtered or unexported fields
}
func (Track) Correction ¶
func (t Track) Correction(artist, track string) (*lastfm.TrackCorrection, error)
Correction returns the track and artist name corrections of a track.
func (Track) InfoByMBID ¶
InfoByMBID returns the information of a track by MBID.
func (Track) Search ¶
func (t Track) Search(params lastfm.TrackSearchParams) (*lastfm.TrackSearchResult, error)
Search searches for tracks by track name, and optionally artist name.
func (Track) Similar ¶
func (t Track) Similar(params lastfm.TrackSimilarParams) (*lastfm.SimilarTracks, error)
Similar returns the similar tracks of a track by artist and track name.
func (Track) SimilarByMBID ¶
func (t Track) SimilarByMBID(params lastfm.TrackSimilarMBIDParams) (*lastfm.SimilarTracks, error)
SimilarByMBID returns the similar tracks of a track by MBID.
func (Track) TagsByMBID ¶
TagsByMBID returns the tags of a track by MBID.
func (Track) TopTags ¶
func (t Track) TopTags(params lastfm.TrackTopTagsParams) (*lastfm.TrackTopTags, error)
TopTags returns the top tags of a track by artist and track name.
func (Track) TopTagsByMBID ¶
func (t Track) TopTagsByMBID(params lastfm.TrackTopTagsMBIDParams) (*lastfm.TrackTopTags, error)
TopTagsByMBID returns the top tags of a track by MBID.
func (Track) UserInfo ¶ added in v1.0.4
func (t Track) UserInfo(params lastfm.TrackUserInfoParams) (*lastfm.TrackUserInfo, error)
UserInfo returns the information of a track for user by artist and track name.
func (Track) UserInfoByMBID ¶ added in v1.0.4
func (t Track) UserInfoByMBID( params lastfm.TrackUserInfoMBIDParams) (*lastfm.TrackUserInfo, error)
UserInfoByMBID returns the information of a track for user by MBID.
type User ¶
type User struct {
// contains filtered or unexported fields
}
func (User) LovedTracks ¶
func (u User) LovedTracks(params lastfm.LovedTracksParams) (*lastfm.LovedTracks, error)
LovedTracks returns the loved tracks of a user.
func (User) RecentTrack ¶ added in v1.0.6
func (u User) RecentTrack(user string) (*lastfm.RecentTrack, error)
RecentTrack returns the most recent track of a user. This is a convenience method that calls RecentTracks with limit=1.
func (User) RecentTrackExtended ¶ added in v1.0.6
func (u User) RecentTrackExtended(user string) (*lastfm.RecentTrackExtended, error)
RecentTrackExtended returns the most recent track of a user with extended information. This is a convenience method that calls RecentTracksExtended with limit=1.
func (User) RecentTracks ¶
func (u User) RecentTracks(params lastfm.RecentTracksParams) (*lastfm.RecentTracks, error)
RecentTracks returns the recent tracks of a user.
func (User) RecentTracksExtended ¶
func (u User) RecentTracksExtended( params lastfm.RecentTracksParams) (*lastfm.RecentTracksExtended, error)
RecentTracksExtended returns the recent tracks of a user with extended information.
func (User) TaggedAlbums ¶ added in v1.0.5
func (u User) TaggedAlbums(params lastfm.UserTagsParams) (*lastfm.UserAlbumTags, error)
TaggedAlbums returns the albums tagged by a user with the given tag.
func (User) TaggedArtists ¶ added in v1.0.5
func (u User) TaggedArtists(params lastfm.UserTagsParams) (*lastfm.UserArtistTags, error)
TaggedArtists returns the artists tagged by a user with the given tag.
func (User) TaggedTracks ¶ added in v1.0.5
func (u User) TaggedTracks(params lastfm.UserTagsParams) (*lastfm.UserTrackTags, error)
TaggedTracks returns the tracks tagged by a user with the given tag.
func (User) TopAlbums ¶
func (u User) TopAlbums(params lastfm.UserTopAlbumsParams) (*lastfm.UserTopAlbums, error)
TopAlbums returns the top albums of a user.
func (User) TopArtists ¶
func (u User) TopArtists(params lastfm.UserTopArtistsParams) (*lastfm.UserTopArtists, error)
TopArtists returns the top artists of a user.
func (User) TopTags ¶
func (u User) TopTags(params lastfm.UserTopTagsParams) (*lastfm.UserTopTags, error)
TopTags returns the top tags of a user.
func (User) TopTracks ¶
func (u User) TopTracks(params lastfm.UserTopTracksParams) (*lastfm.UserTopTracks, error)
TopTracks returns the top tracks of a user.
func (User) WeeklyAlbumChart ¶
func (u User) WeeklyAlbumChart( params lastfm.WeeklyAlbumChartParams) (*lastfm.WeeklyAlbumChart, error)
WeeklyAlbumChart returns the weekly album chart of a user.
func (User) WeeklyArtistChart ¶
func (u User) WeeklyArtistChart( params lastfm.WeeklyArtistChartParams) (*lastfm.WeeklyArtistChart, error)
WeeklyArtistChart returns the weekly artist chart of a user.
func (User) WeeklyChartList ¶
func (u User) WeeklyChartList(user string) (*lastfm.WeeklyChartList, error)
WeeklyChartList returns the weekly chart list of a user.
func (User) WeeklyTrackChart ¶
func (u User) WeeklyTrackChart( params lastfm.WeeklyTrackChartParams) (*lastfm.WeeklyTrackChart, error)
WeeklyTrackChart returns the weekly track chart of a user.