Documentation ¶
Overview ¶
Implements a simple http://last.fm API client library.
The library currently doesn't support authentication, so it only implements a few queries that are useful without authentication.
Index ¶
- Constants
- type Album
- type AlbumInfo
- type Artist
- type LastFM
- func (lfm *LastFM) CompareTaste(user1 string, user2 string) (taste *Tasteometer, err error)
- func (lfm *LastFM) GetArtistTopTags(artist Artist, autocorrect bool) (toptags *TopTags, err error)
- func (lfm *LastFM) GetRecentTracks(user string, count int) (tracks *RecentTracks, err error)
- func (lfm *LastFM) GetTrackInfo(track Track, user string, autocorrect bool) (info *TrackInfo, err error)
- func (lfm *LastFM) GetTrackTopTags(track Track, autocorrect bool) (toptags *TopTags, err error)
- func (lfm *LastFM) GetUserNeighbours(user string, limit int) (neighbours Neighbours, err error)
- func (lfm *LastFM) GetUserTopArtists(user string, period Period, limit int) (top *TopArtists, err error)
- func (lfm *LastFM) LoadCache(r io.Reader) error
- func (lfm *LastFM) SaveCache(w io.Writer) error
- type LastFMError
- type Neighbour
- type Neighbours
- type Period
- type RecentTracks
- type Tag
- type Tasteometer
- type TopArtists
- type TopTags
- type Track
- type TrackInfo
- type Wiki
Constants ¶
const ( DefaultDuration = 5 * time.Minute DefaultCleanupInterval = 1 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlbumInfo ¶
type AlbumInfo struct { TrackNo int `xml:"position,attr"` Name string `xml:"title"` Artist string `xml:"artist"` MBID string `xml:"mbid"` URL string `xml:"url"` }
More detailed struct returned in GetTrackInfo.
type LastFM ¶
type LastFM struct { Cache struct { *sync.RWMutex *cache.Cache } // contains filtered or unexported fields }
Struct used to access the API servers.
func New ¶
Create a new LastFM struct. The apiKey parameter must be an API key registered with Last.fm.
func (*LastFM) CompareTaste ¶
func (lfm *LastFM) CompareTaste(user1 string, user2 string) (taste *Tasteometer, err error)
Compares the taste of 2 users.
func (*LastFM) GetArtistTopTags ¶
Gets the top tags for an Artist. The second argument tells last.fm whether it is to apply autocorrections to the artist name.
The Artist struct must specify either the MBID or the Name. Example literals that can be given as the first argument:
lastfm.Artist{MBID: "mbid"} lastfm.Artist{Name: "Artist"}
func (*LastFM) GetRecentTracks ¶
func (lfm *LastFM) GetRecentTracks(user string, count int) (tracks *RecentTracks, err error)
Gets a list of recent tracks from the user. The .Tracks field includes the currently playing track, if any, and up to the count most recent scrobbles. The .NowPlaying field points to any currently playing track.
func (*LastFM) GetTrackInfo ¶
func (lfm *LastFM) GetTrackInfo(track Track, user string, autocorrect bool) (info *TrackInfo, err error)
Gets information for a Track. The user argument can either be empty ("") or specify a last.fm username, in which case .UserPlaycount and .UserLoved will be valid in the returned struct. The autocorrect parameter controls whether last.fm's autocorrection algorithms should be run on the artist or track names.
The Track struct must specify either the MBID or both Artist.Name and Name. Example literals that can be given as the first argument:
lastfm.Track{MBID: "mbid"} lastfm.Track{Artist: lastfm.Artist{Name: "Artist"}, Name: "Track"}
func (*LastFM) GetTrackTopTags ¶
Gets the top tags for a Track. The second argument tells last.fm whether it is to apply autocorrections to the name/artist.
The Track struct must specify either the MBID or both Artist.Name and Name. Example literals that can be given as the first argument:
lastfm.Track{MBID: "mbid"} lastfm.Track{Artist: lastfm.Artist{Name: "Artist"}, Name: "Track"}
func (*LastFM) GetUserNeighbours ¶
func (lfm *LastFM) GetUserNeighbours(user string, limit int) (neighbours Neighbours, err error)
Gets a list of up to limit closest neighbours of a user. A neighbour is another user that has high tasteometer comparison scores.
func (*LastFM) GetUserTopArtists ¶
func (lfm *LastFM) GetUserTopArtists(user string, period Period, limit int) (top *TopArtists, err error)
Gets a list of the (up to limit) most played artists of a user within a Period.
func (*LastFM) LoadCache ¶
Reads a gob-encoded representation of the Cache from the given io.Reader. Does not change the current Cache if there is a read or decoding error.
The Cache will have its parameters set to this package's DefaultDuration and DefaultCleanupInterval. To change the cache's duration/interval, a new cache is needed like so:
lfm.Cache = cache.NewFrom(duration, interval, lfm.Cache.Items())
This method is not safe for concurrent access, use before starting any requests.
type LastFMError ¶
type LastFMError struct { Code int `xml:"code,attr"` Message string `xml:",chardata"` // contains filtered or unexported fields }
func (*LastFMError) Error ¶
func (e *LastFMError) Error() string
type Neighbours ¶
type Neighbours []Neighbour
type RecentTracks ¶
type Tasteometer ¶
type TopArtists ¶
type TrackInfo ¶
type TrackInfo struct { ID int `xml:"id"` Name string `xml:"name"` MBID string `xml:"mbid"` URL string `xml:"url"` Duration time.Duration `xml:"-"` Listeners int `xml:"listeners"` TotalPlaycount int `xml:"playcount"` Artist Artist `xml:"artist"` // Sometimes not present Album *AlbumInfo `xml:"album"` TopTags []string `xml:"toptags>tag>name"` Wiki *Wiki `xml:"wiki"` // Only present if the user parameter isn't empty ("") UserPlaycount int `xml:"userplaycount"` UserLoved bool `xml:"userloved"` // For internal use RawDuration string `xml:"duration"` }