lastfm

package module
v0.0.0-...-582666a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 11 Imported by: 0

README

lastfm

Go Reference

A very rudimentary Go library for last.fm's archaic API. Only covers what I need for other projects. Most likely never will be stable; expect breaking changes. There is no God within these halls.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorClientOption = errors.New("lastfm: client misconfigured")

ErrorClientOption is returned when a Client is misconfigured.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Message    string `json:"message"`
	Code       int    `json:"error"`
	HTTPStatus int    `json:"-"`
}

APIError is an error sent by the JSON API.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

type Bool

type Bool bool

Bool is a boolean sent by the API.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

type Client

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

Client is an HTTP client for the Last.fm JSON API.

func New

func New(apiKey string, opts ...Option) (*Client, error)

New creates a new Client.

func (*Client) UserInfo

func (c *Client) UserInfo(ctx context.Context, query *UserQuery) (*UserInfo, error)

UserInfo fetches a user's info.

func (*Client) UserRecentTracks

func (c *Client) UserRecentTracks(ctx context.Context, query *UserQuery) (*UserRecentTracks, error)

UserRecentTracks fetches the tracks a user has most recently listened to.

func (*Client) UserTopAlbums

func (c *Client) UserTopAlbums(ctx context.Context, query *UserQuery) (*UserTopAlbums, error)

UserTopAlbums fetches a user's top albums for a period.

type Image

type Image struct {
	Size string `json:"size"`
	Text string `json:"#text"`
}

Image represents an image sent by the API.

type Option

type Option func(*Client)

Option configures a client.

func UserAgent

func UserAgent(ua string) Option

UserAgent sets a client's User-Agent header.

type Time

type Time struct {
	time.Time
}

Time is a timestamp sent by the API.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(v []byte) error

type UserInfo

type UserInfo struct {
	Name        string   `json:"name"`
	Age         int      `json:"age,string"`
	Subscriber  int      `json:"subscriber,string"`
	RealName    string   `json:"realname"`
	Bootstrap   string   `json:"bootstrap"`
	PlayCount   int      `json:"playcount,string"`
	ArtistCount int      `json:"artist_count,string"`
	Playlists   int      `json:"playlists,string"`
	TrackCount  int      `json:"track_count,string"`
	AlbumCount  int      `json:"album_count,string"`
	Image       []*Image `json:"image"`
	Registered  struct {
		UnixTime Time   `json:"unixtime"`
		Text     string `json:"text"`
	} `json:"registered"`
	Country string `json:"country"`
	Gender  string `json:"gender"`
	URL     string `json:"url"`
	Type    string `json:"type"`
}

UserInfo is a user's info sent by the API.

type UserMeta

type UserMeta struct {
	User       string `json:"user"`
	TotalPages int    `json:"totalPages,string"`
	Page       int    `json:"page,string"`
	PerPage    int    `json:"perPage,string"`
	Total      int    `json:"total,string"`
}

UserMeta is a meta information about a request sent with some user endpoints.

type UserQuery

type UserQuery struct {
	// Every user request
	User string `url:"user"`

	// getRecentTracks / getTopAlbums
	Limit  int    `url:"limit,omitempty"`
	Page   int    `url:"page,omitempty"`
	Period string `url:"period,omitempty"`

	// getRecentTracks
	From     time.Time `url:"from,unix,omitempty"`
	To       time.Time `url:"to,unix,omitempty"`
	Extended bool      `url:"extended,int,omitempty"`
}

UserQuery is used to configure a request to the users endpoint.

func (*UserQuery) Values

func (q *UserQuery) Values() (url.Values, error)

Values returns a query's values as a querystring.

type UserRecentTrack

type UserRecentTrack struct {
	Artist struct {
		MBID string `json:"mbid"`
		Name string `json:"#text"`
	} `json:"artist"`
	Album struct {
		MBID string `json:"mbid"`
		Name string `json:"#text"`
	} `json:"album"`
	Streamable Bool     `json:"streamable"`
	Image      []*Image `json:"image"`
	MBID       string   `json:"mbid"`
	Name       string   `json:"name"`
	URL        string   `json:"url"`
	Date       struct {
		Time Time `json:"uts"`
	}
	Meta struct {
		NowPlaying Bool `json:"nowplaying"`
	} `json:"@attr,omitempty"`
}

UserRecentTrack represents a track recently listened to by a user.

type UserRecentTracks

type UserRecentTracks struct {
	Tracks []*UserRecentTrack `json:"track"`
	Meta   *UserMeta          `json:"@attr"`
}

type UserTopAlbum

type UserTopAlbum struct {
	Artist struct {
		URL  string `json:"url"`
		Name string `json:"name"`
		MBID string `json:"mbid"`
	} `json:"artist"`
	Image     []*Image `json:"image"`
	MBID      string   `json:"mbid"`
	URL       string   `json:"url"`
	PlayCount int      `json:"playcount,string"`
	Name      string   `json:"name"`
	Meta      struct {
		Rank int `json:"rank,string"`
	} `json:"@attr"`
}

UserTopAlbum represents a top album for a user.

type UserTopAlbums

type UserTopAlbums struct {
	Albums []*UserTopAlbum `json:"album"`
	Meta   *UserMeta       `json:"@attr"`
}

UserTopAlbums is a user's top albums.

Jump to

Keyboard shortcuts

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