lastfm

package
v0.0.0-...-e1ec090 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ApiSigReplace = "ApiSigReplace"

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API holds methods for interacting with the Last.fm API

func CreateAPIService

func CreateAPIService() *API

CreateAPIService creates an instance of the lastfm api service object

func (API) AllScrobblesSince

func (lfm API) AllScrobblesSince(requestable Requestable, since *time.Time) ([]RecentTrack, error)

AllScrobblesSince returns all of a users scrobbles since a certain date

func (API) AllTopAlbums

func (lfm API) AllTopAlbums(requestable Requestable) ([]TopAlbum, error)

AllTopAlbums returns all of a user's top albums through each page

func (API) AllTopArtists

func (lfm API) AllTopArtists(requestable Requestable) ([]TopArtist, error)

AllTopArtists returns all of a user's top artists through each page

func (API) AllTopTracks

func (lfm API) AllTopTracks(requestable Requestable) ([]TopTrack, error)

AllTopTracks returns all of a user's top tracks through each page

func (API) ArtistInfo

func (lfm API) ArtistInfo(artist string) (*ErrorResponse, *ArtistInfoResponse)

func (API) LastScrobbledTimestamp

func (lfm API) LastScrobbledTimestamp(requestable Requestable) time.Time

LastScrobbledTimestamp returns the timestamp of the last scrobbled track

func (API) MakeRequest

func (lfm API) MakeRequest(method string, params interface{}) *http.Response

MakeRequest calls the lastfm api with the given parameters

func (API) ParseResponse

func (lfm API) ParseResponse(response *http.Response, output interface{}) *ErrorResponse

ParseResponse parses a JSON respone from the last.fm api

func (API) RecentTracks

func (lfm API) RecentTracks(params RecentTracksParams) (*ErrorResponse, *RecentTracksResponse)

RecentTracks fetches a user's recent tracks from the last.fm API

func (API) TopAlbums

func (lfm API) TopAlbums(params TopEntityParams) (*ErrorResponse, *TopAlbumsResponse)

TopAlbums fetches a user's top albums from the last.fm API

func (API) TopArtists

func (lfm API) TopArtists(params TopEntityParams) (*ErrorResponse, *TopArtistsResponse)

TopArtists fetches a user's top artists from the last.fm API

func (API) TopTracks

func (lfm API) TopTracks(params TopEntityParams) (*ErrorResponse, *TopTracksResponse)

TopTracks fetches a user's top tracks from the last.fm API

func (API) UserInfo

func (lfm API) UserInfo(requestable Requestable) (*ErrorResponse, *UserInfoResponse)

UserInfo fetches a user's info from the last.fm API

func (API) ValidateUser

func (lfm API) ValidateUser(username string) bool

ValidateUser validates that a given username exists in last.fm

type ArtistInfoParams

type ArtistInfoParams struct {
	Artist string `url:"artist"`
}

type ArtistInfoResponse

type ArtistInfoResponse struct {
	Artist struct {
		Name       string `json:"name"`
		URL        string `json:"url"`
		Streamable string `json:"streamable"`
		Ontour     string `json:"ontour"`
		Stats      struct {
			Listeners     string `json:"listeners"`
			Playcount     string `json:"playcount"`
			UserPlaycount string `json:"userplaycount"`
		} `json:"stats"`
		Similar struct {
			Artists []struct {
				Name   string  `json:"name"`
				URL    string  `json:"url"`
				Images []Image `json:"image"`
			} `json:"artist"`
		} `json:"similar"`
		Tags struct {
			Tag []struct {
				Name string `json:"name"`
				URL  string `json:"url"`
			}
		} `json:"tags"`
		Bio struct {
			Links struct {
				Link struct {
					Text string `json:"#text"`
					Rel  string `json:"rel"`
					Href string `json:"href"`
				} `json:"link"`
			} `json:"links"`
			Published string `json:"published"`
			Summary   string `json:"summary"`
			Content   string `json:"content"`
		} `json:"bio"`
	} `json:"artist"`
}

type ErrorResponse

type ErrorResponse struct {
	Error   int16  `json:"error"`
	Message string `json:"message"`
}

ErrorResponse is the struct type for a last.fm error response

type Image

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

Image is the struct type for a Last.fm image

type RankAttributes

type RankAttributes struct {
	Rank string `json:"rank"`
}

RankAttributes is the struct type for

type RecentTrack

type RecentTrack struct {
	Artist struct {
		MBID string `json:"mbid"`
		Text string `json:"#text"`
	} `json:"artist"`
	Attributes struct {
		IsNowPlaying string `json:"nowplaying"`
	} `json:"@attr"`
	MBID  string `json:"mbid"`
	Album struct {
		MBID string `json:"mbid"`
		Text string `json:"#text"`
	} `json:"album"`
	Images     []Image `json:"image"`
	Streamable string  `json:"streamable"`
	URL        string  `json:"url"`
	Name       string  `json:"name"`
	Timestamp  struct {
		UTS  string `json:"uts"`
		Text string `json:"#text"`
	} `json:"date"`
}

RecentTrack is a struct containing a recent track from last.fm

func ExcludeNowPlaying

func ExcludeNowPlaying(tracks []RecentTrack) []RecentTrack

type RecentTracksParams

type RecentTracksParams struct {
	Username Requestable `url:"username"`
	Limit    int         `url:"limit"`
	Page     int         `url:"page"`
	Period   string      `url:"period"`
	From     string      `url:"from"`
}

RecentTracksParams is the parameters for a user.recentTracks call

type RecentTracksResponse

type RecentTracksResponse struct {
	RecentTracks struct {
		Attributes struct {
			Page       string `json:"page"`
			Total      string `json:"total"`
			User       string `json:"user"`
			PerPage    string `json:"perPage"`
			TotalPages string `json:"totalPages"`
		} `json:"@attr"`

		Tracks []RecentTrack `json:"track"`
	} `json:"recenttracks"`
}

RecentTracksResponse is the struct type for a user.getRecentTracks response from last.fm

type Requestable

type Requestable struct {
	Username string
	Session  *string
}

func (Requestable) EncodeValues

func (r Requestable) EncodeValues(key string, v *url.Values) error

type TopAlbum

type TopAlbum struct {
	Artist struct {
		URL  string `json:"url"`
		Name string `json:"name"`
		MBID string `json:"mbid"`
	} `json:"artist"`
	Attributes RankAttributes `json:"@attr"`
	Images     []Image        `json:"image"`
	Playcount  string         `json:"playcount"`
	URL        string         `json:"url"`
	Name       string         `json:"name"`
	MBID       string         `json:"mbid"`
}

TopAlbum is the struct type for a last.fm top album

type TopAlbumsResponse

type TopAlbumsResponse struct {
	TopAlbums struct {
		Albums     []TopAlbum `json:"album"`
		Attributes struct {
			Page       string `json:"page"`
			Total      string `json:"total"`
			User       string `json:"user"`
			PerPage    string `json:"perPage"`
			TotalPages string `json:"totalPages"`
		} `json:"@attr"`
	} `json:"topalbums"`
}

TopAlbumsResponse is the struct type for a user.getTopAlbums response from last.fm

type TopArtist

type TopArtist struct {
	Attributes RankAttributes `json:"@attr"`
	MBID       string         `json:"mbid"`
	URL        string         `json:"url"`
	Playcount  string         `json:"playcount"`
	Images     []Image        `json:"image"`
	Name       string         `json:"name"`
	Streamable string         `json:"streamable"`
}

TopArtist is the struct type for a last.fm top artist

type TopArtistsResponse

type TopArtistsResponse struct {
	TopArtists struct {
		Artists    []TopArtist `json:"artist"`
		Attributes struct {
			Page       string `json:"page"`
			Total      string `json:"total"`
			User       string `json:"user"`
			PerPage    string `json:"perPage"`
			TotalPages string `json:"totalPages"`
		} `json:"@attr"`
	} `json:"topartists"`
}

TopArtistsResponse is the struct type for a user.getTopArtists response from last.fm

type TopEntityParams

type TopEntityParams struct {
	Username Requestable `url:"username"`
	Limit    int         `url:"limit"`
	Page     int         `url:"page"`
	Period   string      `url:"period"`
}

TopEntityParams is the parameters for a user.getInfo response

type TopTrack

type TopTrack struct {
	MBID      string  `json:"mbid"`
	Name      string  `json:"name"`
	URL       string  `json:"url"`
	Duration  string  `json:"duration"`
	Playcount string  `json:"playcount"`
	Images    []Image `json:"image"`

	Attributes struct {
		Rank string `json:"rank"`
	} `json:"@attr"`

	Artist struct {
		URL  string `json:"url"`
		Name string `json:"name"`
		Mbid string `json:"mbid"`
	} `json:"artist"`

	Streamable struct {
		Fulltrack string `json:"fulltrack"`
		Text      string `json:"#text"`
	} `json:"streamable"`
}

TopTrack is the struct type for a last.fm top track

type TopTracksResponse

type TopTracksResponse struct {
	TopTracks struct {
		Attributes struct {
			Page       string `json:"page"`
			Total      string `json:"total"`
			User       string `json:"user"`
			PerPage    string `json:"perPage"`
			TotalPages string `json:"totalPages"`
		} `json:"@attr"`

		Tracks []TopTrack `json:"track"`
	} `json:"toptracks"`
}

TopTracksResponse is the struct type for a user.getTopTracks response from last.fm

type UserInfoParams

type UserInfoParams struct {
	Username Requestable `url:"username"`
}

UserInfoParams is the parameters for a user.getInfo call

type UserInfoResponse

type UserInfoResponse struct {
	User struct {
		Playlist   string  `json:"playlists"`
		Playcount  string  `json:"playcount"`
		Gender     string  `json:"gender"`
		Name       string  `json:"name"`
		Subscriber string  `json:"subscriber"`
		URL        string  `json:"url"`
		Country    string  `json:"country"`
		Image      []Image `json:"images"`
		Registered struct {
			Unixtime string `json:"unixtime"`
			AsNumber int64  `json:"#text"`
		} `json:"registered"`
		Type      string `json:"type"`
		Age       string `json:"age"`
		Bootstrap string `json:"bootstrap"`
		Realname  string `json:"realname"`
	} `json:"user"`
}

UserInfoResponse is the struct type for a user.getInfo response from last.fm

Jump to

Keyboard shortcuts

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