Documentation
¶
Overview ¶
API Wrapper for Lastfm's API :
http://www.last.fm/api
Copyright 2014 Nedyalko Dyakov ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- type AlbumClient
- func (c *AlbumClient) GetInfo(artist, album, mbid, username string, autocorrect int) (response *AlbumInfoResponse, err error)
- func (c *AlbumClient) GetTags(artist, album, mbid, user string, autocorrect int) (response *TagsResponse, err error)
- func (c *AlbumClient) GetTopTags(artist, album, mbid string, autocorrect int) (response *TopTagsResponse, err error)
- func (c *AlbumClient) Search(album string, page, limit int) (response *AlbumSearchResponse, err error)
- type AlbumInfoResponse
- type AlbumInlineResponse
- type AlbumResponse
- type AlbumResponseNoArtistStruct
- type AlbumSearchResponse
- type ArtistBioResponse
- type ArtistClient
- func (c *ArtistClient) GetInfo(name, mbid string, autocorrect int) (response *ArtistInfoResponse, err error)
- func (c *ArtistClient) GetSimilar(name string, mbid string, autocorrect int) (response *ArtistSimilarResponse, err error)
- func (c *ArtistClient) GetTags(name, mbid, user string, autocorrect int) (response *TagsResponse, err error)
- func (c *ArtistClient) GetTopAlbums(name, mbid string, autocorrect, page, limit int) (response *TopAlbumsResponse, err error)
- func (c *ArtistClient) GetTopFans(name, mbid string, autocorrect int) (response *TopFansResponse, err error)
- func (c *ArtistClient) GetTopTags(name, mbid string, autocorrect int) (response *TopTagsResponse, err error)
- func (c *ArtistClient) GetTopTracks(name, mbid string, autocorrect, page, limit int) (response *TopTracksResponse, err error)
- func (c *ArtistClient) Search(name string, page, limit int) (response *ArtistSearchResponse, err error)
- type ArtistCorrectionResponse
- type ArtistInfoResponse
- type ArtistResponse
- type ArtistSearchResponse
- type ArtistSimilarResponse
- type AuthClient
- type AuthSessionResponse
- type AuthTokenResponse
- type Client
- type CompareInputResponse
- type CompareResultResponse
- type FanResponse
- type LastFM
- func (lfm *LastFM) GetSessionKey() string
- func (lfm *LastFM) GetToken() string
- func (lfm *LastFM) GetUserAgent() string
- func (lfm *LastFM) HasSessionKey() bool
- func (lfm *LastFM) HasToken() bool
- func (lfm *LastFM) HasUserAgent() bool
- func (lfm *LastFM) SetSessionKey(sessionKey string)
- func (lfm *LastFM) SetToken(token string)
- func (lfm *LastFM) SetUserAgent(userAgent string)
- type LastfmDateResponse
- type LastfmErrorResponse
- type LastfmImageResponse
- type LastfmOpenSearchResponse
- type LastfmResponse
- type LastfmSessionResponse
- type LastfmStatsResponse
- type LastfmStatusResponse
- type LastfmWikiResponse
- type LovedTracksResponse
- type NeighbourResponse
- type NeighboursResponse
- type OpenSearchQueryResponse
- type RecentTrackResponse
- type RecentTracksResponse
- type SimilarTracksResponse
- type TagClient
- func (c *TagClient) GetInfo(tag string) (response *TagInfoResponse, err error)
- func (c *TagClient) GetSimilar(tag string) (response *TagSimilarResponse, err error)
- func (c *TagClient) GetTopAlbums(tag string, page, limit int) (response *TopAlbumsResponse, err error)
- func (c *TagClient) GetTopArtists(tag string, page, limit int) (response *TopArtistsResponse, err error)
- func (c *TagClient) GetTopTags() (response *TopTagsResponse, err error)
- func (c *TagClient) GetTopTracks(tag string, page, limit int) (response *TopTracksResponse, err error)
- func (c *TagClient) Search(tag string, page, limit int) (response *TagSearchResponse, err error)
- type TagInfoResponse
- type TagResponse
- type TagSearchResponse
- type TagSimilarResponse
- type TagsResponse
- type TasteometerClient
- type TasteometerCompareResponse
- type TopAlbumsResponse
- type TopArtistsResponse
- type TopFansResponse
- type TopTagsResponse
- type TopTracksResponse
- type TrackClient
- func (c *TrackClient) GetCorrection(track, artist string) (response *TrackCorrectionResponse, err error)
- func (c *TrackClient) GetInfo(track, artist string, optionalParams map[string]string) (response *TrackInfoResponse, err error)
- func (c *TrackClient) GetSimilar(track, artist string, optionalParams map[string]string) (response *SimilarTracksResponse, err error)
- func (c *TrackClient) GetTags(track, artist string, optionalParams map[string]string) (response *TagsResponse, err error)
- func (c *TrackClient) GetTopFans(track, artist string, optionalParams map[string]string) (response *TopFansResponse, err error)
- func (c *TrackClient) GetTopTags(track, artist string, optionalParams map[string]string) (response *TopTagsResponse, err error)
- func (c *TrackClient) Scrobble(artist, track, timestamp string, optionalParams map[string]string) (response *TrackScrobbleResponse, err error)
- func (c *TrackClient) Search(track string, optionalParams map[string]string) (response *TrackSearchResponse, err error)
- type TrackCorrectionResponse
- type TrackInfoResponse
- type TrackResponse
- type TrackResponseNoArtistStruct
- type TrackScrobbleFieldResponse
- type TrackScrobbleIgnoredMessageResponse
- type TrackScrobbleResponse
- type TrackScrobblesResponse
- type TrackSearchResponse
- type TrackSingleCorrectionResponse
- type TrackStreamableResponse
- type UserClient
- func (c *UserClient) GetInfo(user string) (response *UserInfoResponse, err error)
- func (c *UserClient) GetLovedTracks(user string, page, limit int) (response *LovedTracksResponse, err error)
- func (c *UserClient) GetNeighbours(user string, limit int) (response *NeighboursResponse, err error)
- func (c *UserClient) GetRecentTracks(user string, page, limit int, from, to int64) (response *RecentTracksResponse, err error)
- func (c *UserClient) GetTopAlbums(user, period string, page, limit int) (response *TopAlbumsResponse, err error)
- func (c *UserClient) GetTopArtists(user, period string, page, limit int) (response *TopArtistsResponse, err error)
- func (c *UserClient) GetTopTags(user string, limit int) (response *TopTagsResponse, err error)
- func (c *UserClient) GetTopTracks(user, period string, page, limit int) (response *TopTracksResponse, err error)
- type UserInfoResponse
- type UserResponse
Examples ¶
- AlbumClient.GetInfo
- AlbumClient.GetTags
- AlbumClient.GetTopTags
- AlbumClient.Search
- ArtistClient.GetInfo
- ArtistClient.GetSimilar
- ArtistClient.GetTags
- ArtistClient.GetTopAlbums
- ArtistClient.GetTopFans
- ArtistClient.GetTopTags
- ArtistClient.GetTopTracks
- ArtistClient.Search
- AuthClient.GetMobileSession
- AuthClient.GetSession
- AuthClient.GetToken
- TagClient.GetInfo
- TagClient.GetSimilar
- TagClient.GetTopAlbums
- TagClient.GetTopArtists
- TagClient.GetTopTags
- TagClient.GetTopTracks
- TagClient.Search
- TasteometerClient.Compare
- TrackClient.GetCorrection
- TrackClient.GetInfo
- TrackClient.GetSimilar
- TrackClient.GetTags
- TrackClient.GetTopFans
- TrackClient.GetTopTags
- TrackClient.Scrobble
- TrackClient.Search
- UserClient.GetInfo
- UserClient.GetLovedTracks
- UserClient.GetNeighbours
- UserClient.GetRecentTracks
- UserClient.GetTopAlbums
- UserClient.GetTopArtists
- UserClient.GetTopTags
- UserClient.GetTopTracks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlbumClient ¶
type AlbumClient struct {
Client
}
AlbumClient Collection of methods that correspond to most of LastFM's album\.(.+) methods. Where the name of the method is \1 in CamelCase.
func (*AlbumClient) GetInfo ¶
func (c *AlbumClient) GetInfo(artist, album, mbid, username string, autocorrect int) (response *AlbumInfoResponse, err error)
Get full information for Album. Returns AlbumInforResponse or error. There may be an error returned from the parser/decoder as well.
Example ¶
Get full info for Album.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Album.GetInfo("Ogonek", "Drum And Bass Massacre", "", "", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Artist : %v\n", response.Album.Artist) fmt.Printf("Album : %v\n", response.Album.Name) fmt.Printf("ID : %v\n", response.Album.ID) fmt.Printf("URL : %v\n", response.Album.URL) fmt.Printf("Listeners : %v\n", response.Album.Listeners) fmt.Printf("Playcount : %v\n", response.Album.Playcount) fmt.Printf("First track :\n") track := response.Album.Tracks[0] fmt.Printf(" Title : %v\n", track.Name) fmt.Printf(" Duration : %v\n", track.Duration)
Output: Artist : Ogonek Album : Drum And Bass Massacre ID : 3668131 URL : http://www.last.fm/music/Ogonek/Drum+And+Bass+Massacre Listeners : 2163 Playcount : 4288 First track : Title : luk i praz Duration : 302
func (*AlbumClient) GetTags ¶
func (c *AlbumClient) GetTags(artist, album, mbid, user string, autocorrect int) (response *TagsResponse, err error)
Get Tags for some Album, that are added by some user. Returns TagsResponse or error.
Example ¶
Get Tags for Album.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Album.GetTags("Guano Apes", "Bel Air", "", "n3mo-", 1) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Tags by User : %v\n", len(response.Tags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.Tags[0].Name) fmt.Printf("URL : %v\n", response.Tags[0].URL)
Output: Number of Tags by User : 2 Tag #1 : Name : guano apes v2 URL : http://www.last.fm/tag/guano%20apes%20v2
func (*AlbumClient) GetTopTags ¶
func (c *AlbumClient) GetTopTags(artist, album, mbid string, autocorrect int) (response *TopTagsResponse, err error)
Get Top Tags for Album. Returns TopTagsResponse or error.
Example ¶
Get Top Tags for Album.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Album.GetTopTags("Guano Apes", "Bel Air", "", 1) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Top Tags : %v\n", len(response.TopTags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.TopTags[0].Name) fmt.Printf("URL : %v\n", response.TopTags[0].URL) fmt.Printf("Count : %v\n", response.TopTags[0].Count)
Output: Number of Top Tags : 14 Tag #1 : Name : rock URL : http://www.last.fm/tag/rock Count : 100
func (*AlbumClient) Search ¶
func (c *AlbumClient) Search(album string, page, limit int) (response *AlbumSearchResponse, err error)
Search album by given name. You can specify page and limit also. Default values are as stated in lastfm's api documentation. Returns AlbumSearchResponse.
Example ¶
Search for Album.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Album.Search("go", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } var album lastfm.AlbumResponseNoArtistStruct fmt.Printf("Search request for : %v\n", response.Query.SearchTerms) fmt.Printf("Total results : %v\n", response.TotalResults) if response.TotalResults > 0 { album = response.AlbumMatches[0] } fmt.Printf("First result :\n") fmt.Printf(" Album Name : %v\n", album.Name) fmt.Printf(" Album MBID : %v\n", album.MBID) fmt.Printf(" Artist Name : %v\n", album.Artist) fmt.Printf(" Album Image[%v] : %v\n", album.Image[0].Size, album.Image[0].URL)
Output: Search request for : go Total results : 31102 First result : Album Name : Demon Days Album MBID : 26193df8-54c5-4c75-80e3-84ddc9aa7379 Artist Name : Gorillaz Album Image[small] : http://userserve-ak.last.fm/serve/34s/44425129.png
type AlbumInfoResponse ¶
type AlbumInfoResponse struct { LastfmStatusResponse Album AlbumResponseNoArtistStruct `xml:"album"` }
AlbumInfoResponse, used for album.getInfo request.
type AlbumInlineResponse ¶
AlbumInlineResponse used where <album mbid="xx">album name</album> tag is present. For example in user.getRecentTracks
type AlbumResponse ¶
type AlbumResponse struct { Name string `xml:"name"` Artist ArtistResponse `xml:"artist"` ID int64 `xml:"id"` Rank int `xml:"rank,attr"` MBID string `xml:"mbid"` Listeners int64 `xml:"listeners"` URL string `xml:"url"` Playcount int64 `xml:"playcount"` Image []LastfmImageResponse `xml:"image"` ReleaseDate string `xml:"releasedate"` TopTags TopTagsResponse `xml:"toptags"` Tracks []TrackResponse `xml:"tracks>track"` }
AlbumResponse, used where <album> tag is present and there is a tree of tags in <artist></artist> pair.
type AlbumResponseNoArtistStruct ¶
type AlbumResponseNoArtistStruct struct { Name string `xml:"name"` Artist string `xml:"artist"` ID int64 `xml:"id"` Rank int `xml:"rank,attr"` MBID string `xml:"mbid"` Listeners int64 `xml:"listeners"` URL string `xml:"url"` Playcount int64 `xml:"playcount"` Image []LastfmImageResponse `xml:"image"` ReleaseDate string `xml:"releasedate"` TopTags TopTagsResponse `xml:"toptags"` Tracks []TrackResponse `xml:"tracks>track"` }
AlbumResponseNoArtistStruct, used where <album> tag is present but there is no subtags in <artist></artist>.
type AlbumSearchResponse ¶
type AlbumSearchResponse struct { LastfmStatusResponse LastfmOpenSearchResponse AlbumMatches []AlbumResponseNoArtistStruct `xml:"results>albummatches>album"` }
AlbumSearchResponse, used for album.search request.
type ArtistBioResponse ¶
type ArtistBioResponse struct {
LastfmWikiResponse
}
ArtistBioResponse part of ArtistResponse can be found in artist.getInfo`s response.
type ArtistClient ¶
type ArtistClient struct {
Client
}
ArtistClient Collection of methods that correspond to most of LastFM's artist\.(.+) methods. Where the name of the method is \1 in CamelCase.
func (*ArtistClient) GetInfo ¶
func (c *ArtistClient) GetInfo(name, mbid string, autocorrect int) (response *ArtistInfoResponse, err error)
Get info for Artist with given name. Returns ArtistInfoResponse or error. Response data is actually in response.Artist.
Example ¶
Get full info for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetInfo("Gorillaz", "", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Artist : %v\n", response.Artist.Name) fmt.Printf("MBID : %v\n", response.Artist.MBID) fmt.Printf("URL : %v\n", response.Artist.URL) fmt.Printf("Listeners : %v\n", response.Artist.Stats.Listeners) fmt.Printf("Playcount : %v\n", response.Artist.Stats.Playcount)
Output: Artist : Gorillaz MBID : e21857d5-3256-4547-afb3-4b6ded592596 URL : http://www.last.fm/music/Gorillaz Listeners : 3091710 Playcount : 124649955
func (*ArtistClient) GetSimilar ¶
func (c *ArtistClient) GetSimilar(name string, mbid string, autocorrect int) (response *ArtistSimilarResponse, err error)
Get similar artists. Returns ArtistSimilarResponse or error.
Example ¶
Get Similar Artists.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetSimilar("Cher", "", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } artist := response.SimilarArtists[0] fmt.Printf("Number of matches : %v\n", len(response.SimilarArtists)) fmt.Printf("First match :\n") fmt.Printf("Artist : %v\n", artist.Name) fmt.Printf("MBID : %v\n", artist.MBID) fmt.Printf("Match : %v\n", artist.Match)
Output: Number of matches : 100 First match : Artist : Sonny & Cher MBID : 3d6e4b6d-2700-458c-9722-9021965a8164 Match : 1
func (*ArtistClient) GetTags ¶
func (c *ArtistClient) GetTags(name, mbid, user string, autocorrect int) (response *TagsResponse, err error)
Get tags for Artist who is in users directory. Returns TagsResponse structure or error. Be careful, there may be error returned from the parsing as well.
Example ¶
Get Tags for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetTags("Red Hot Chili Peppers", "", "RJ", 1) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Tags by User : %v\n", len(response.Tags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.Tags[0].Name) fmt.Printf("URL : %v\n", response.Tags[0].URL)
Output: Number of Tags by User : 2 Tag #1 : Name : funky URL : http://www.last.fm/tag/funky
func (*ArtistClient) GetTopAlbums ¶
func (c *ArtistClient) GetTopAlbums(name, mbid string, autocorrect, page, limit int) (response *TopAlbumsResponse, err error)
Get top Albums for Artist. Returns TopAlbumsResponse or error. Be careful, there may be error returned from the parsing as well.
Example ¶
Get Top Albums for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetTopAlbums("Ogonek", "", 0, 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } album := response.TopAlbums[0] fmt.Printf("Top Albums By : %v\n", album.Artist.Name) fmt.Printf("Top Album #1 : %v\n", album.Name) fmt.Printf("URL : %v\n", album.URL) fmt.Printf("Playcount: %v\n", album.Playcount) fmt.Printf("Image [%v] : %v\n", album.Image[0].Size, album.Image[0].URL)
Output: Top Albums By : Ogonek Top Album #1 : Drum And Bass Massacre URL : http://www.last.fm/music/Ogonek/Drum+And+Bass+Massacre Playcount: 26 Image [small] : http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png
func (*ArtistClient) GetTopFans ¶
func (c *ArtistClient) GetTopFans(name, mbid string, autocorrect int) (response *TopFansResponse, err error)
Get top fans for Artist. Returns TopFansResponse or error. Be careful, there may be error returned from the parsing as well.
Example ¶
Get Top Fans for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetTopFans("Ogonek", "", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } user := response.TopFans[0] fmt.Printf("Top Fan #1 : %v\n", user.Name) fmt.Printf("URL : %v\n", user.URL) fmt.Printf("Image [%v] : %v\n", user.Image[0].Size, user.Image[0].URL)
Output: Top Fan #1 : rikardo_83 URL : http://www.last.fm/user/rikardo_83 Image [small] : http://userserve-ak.last.fm/serve/34/79926153.gif
func (*ArtistClient) GetTopTags ¶
func (c *ArtistClient) GetTopTags(name, mbid string, autocorrect int) (response *TopTagsResponse, err error)
Get top tags for Artist. Returns TopTagsResponse structure or error. Be careful, there may be error returned from the parsing as well.
Example ¶
Get Top Tags for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetTopTags("Daft Punk", "", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Top Tags : %v\n", len(response.TopTags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.TopTags[0].Name) fmt.Printf("URL : %v\n", response.TopTags[0].URL)
Output: Number of Top Tags : 100 Tag #1 : Name : electronic URL : http://www.last.fm/tag/electronic
func (*ArtistClient) GetTopTracks ¶
func (c *ArtistClient) GetTopTracks(name, mbid string, autocorrect, page, limit int) (response *TopTracksResponse, err error)
Get top tracks for Artist. Returns TopTracksResponse or error. Be careful, there may be error returned from the parsing as well.
Example ¶
Get Top Tracks for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.GetTopTracks("Ogonek", "", 0, 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.TopTracks[0] fmt.Printf("Top Tracks By : %v\n", track.Artist.Name) fmt.Printf("Top Track #1 : %v\n", track.Name) fmt.Printf("URL : %v\n", track.URL) fmt.Printf("Playcount: %v\n", track.Playcount)
Output: Top Tracks By : Ogonek Top Track #1 : Starlight URL : http://www.last.fm/music/Ogonek/_/Starlight Playcount: 109
func (*ArtistClient) Search ¶
func (c *ArtistClient) Search(name string, page, limit int) (response *ArtistSearchResponse, err error)
Search for Artist by given name. Returns ArtistSearchResponse or error.
Example ¶
Search for Artist.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Artist.Search("Ogo", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } var artist lastfm.ArtistResponse fmt.Printf("Search request for : %v\n", response.Query.SearchTerms) fmt.Printf("Total results : %v\n", response.TotalResults) if response.TotalResults > 0 { artist = response.ArtistMatches[0] } fmt.Printf("First result :\n") fmt.Printf(" Artist Name : %v\n", artist.Name) fmt.Printf(" Artist MBID : %v\n", artist.MBID) fmt.Printf(" Artist Image[%v] : %v\n", artist.Image[0].Size, artist.Image[0].URL)
Output: Search request for : Ogo Total results : 22 First result : Artist Name : Ogonek Artist MBID : 971762d6-c851-499c-a656-7fa4fa055f47 Artist Image[small] : http://userserve-ak.last.fm/serve/34/26437217.jpg
type ArtistCorrectionResponse ¶
type ArtistCorrectionResponse struct { LastfmStatusResponse Corrections []ArtistResponse `xml:"corrections>correction>artist"` }
type ArtistInfoResponse ¶
type ArtistInfoResponse struct { LastfmStatusResponse Artist ArtistResponse `xml:"artist"` }
ArtistInfoResponse, used for artist.getInfo request.
type ArtistResponse ¶
type ArtistResponse struct { Name string `xml:"name"` MBID string `xml:"mbid"` URL string `xml:"url"` Image []LastfmImageResponse `xml:"image"` Streamable int `xml:"streamable"` Match float64 `xml:"match"` Stats LastfmStatsResponse `xml:"stats"` SimilarArtists []ArtistResponse `xml:"similar>artist"` Bio ArtistBioResponse `xml:"bio"` }
ArtistResponse, used where <artist> tag is present.
type ArtistSearchResponse ¶
type ArtistSearchResponse struct { LastfmStatusResponse LastfmOpenSearchResponse ArtistMatches []ArtistResponse `xml:"results>artistmatches>artist"` }
ArtistSearchResponse, used for artist.Search request.
type ArtistSimilarResponse ¶
type ArtistSimilarResponse struct { LastfmStatusResponse SimilarArtists []ArtistResponse `xml:"similarartists>artist"` }
ArtistSimilarResponse, used where <similarartists> is present.
type AuthClient ¶
type AuthClient struct {
Client
}
func (*AuthClient) GetMobileSession ¶
func (c *AuthClient) GetMobileSession(password, username string) (response *AuthSessionResponse, err error)
Example ¶
Get Session
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Auth.GetMobileSession("testPassword", "testUserName") if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Name : %s\n", response.Session.Name) fmt.Printf("SessionKey : %s\n", response.Session.Key) fmt.Printf("Subscriber : %d\n", response.Session.Subscriber)
Output: Name : MyLastFMUsername SessionKey : d580d57f32848f5dcf574d1ce18d78b2 Subscriber : 0
func (*AuthClient) GetSession ¶
func (c *AuthClient) GetSession() (response *AuthSessionResponse, err error)
Example ¶
Get Session
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Auth.GetSession() if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Name : %s\n", response.Session.Name) fmt.Printf("SessionKey : %s\n", response.Session.Key) fmt.Printf("Subscriber : %d\n", response.Session.Subscriber)
Output: Name : MyLastFMUsername SessionKey : d580d57f32848f5dcf574d1ce18d78b2 Subscriber : 0
func (*AuthClient) GetToken ¶
func (c *AuthClient) GetToken() (response *AuthTokenResponse, err error)
Example ¶
Get Token
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Auth.GetToken() if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Token : %s", response.Token)
Output: Token : fba51a644f342186ba4d579d5675a167
type AuthSessionResponse ¶
type AuthSessionResponse struct { LastfmStatusResponse Session LastfmSessionResponse `xml:"session"` }
type AuthTokenResponse ¶
type AuthTokenResponse struct { LastfmStatusResponse Token string `xml:"token"` }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client struct that holds pointer to the LastFM object.
type CompareInputResponse ¶
type CompareInputResponse struct {
Users []UserResponse `xml:"user"`
}
CompareInputResponse is the second half of the TasteometerCompareResponse.
type CompareResultResponse ¶
type CompareResultResponse struct { Score float64 `xml:"score"` // As this doesn't work in go for now, we will skip it // untill they fix the issue. Check here: // http://code.google.com/p/go/issues/detail?id=3688 //Matches int `xml:"artists>matches,attr"` Artists []ArtistResponse `xml:"artists>artist"` }
CompareResultResponse is the first half of TasteometerCompareResponse.
type FanResponse ¶
type FanResponse struct { UserResponse Weight int64 `xml:"weight"` }
FanResponse Part of TopFansResponse.
type LastFM ¶
type LastFM struct { Album AlbumClient Artist ArtistClient Tag TagClient Track TrackClient User UserClient Tasteometer TasteometerClient Auth AuthClient // contains filtered or unexported fields }
LastFM struct with all available clients.
func (*LastFM) GetSessionKey ¶
func (*LastFM) GetUserAgent ¶
func (*LastFM) HasSessionKey ¶
func (*LastFM) HasUserAgent ¶
func (*LastFM) SetSessionKey ¶
func (*LastFM) SetUserAgent ¶
type LastfmDateResponse ¶
LastfmDateResponse to parse dates from the xml responses. Holds date as string and also UTS unix timestamp.
type LastfmErrorResponse ¶
LastfmErrorResponse Holds errors in the status response, also implements error interface, so it can be returned as an error.
func (*LastfmErrorResponse) Error ¶
func (e *LastfmErrorResponse) Error() string
Return the error message.
type LastfmImageResponse ¶
LastfmImageResponse, usefull where multiple image tags are present.
type LastfmOpenSearchResponse ¶
type LastfmOpenSearchResponse struct { Query OpenSearchQueryResponse `xml:"results>Query"` TotalResults int `xml:"results>totalResults"` StartIndex int `xml:"results>startIndex"` ItemsPerPage int `xml:"results>itemsPerPage"` }
LastfmOpenSearchResponse is used for any of the xxx.search's responses. Holds data about the search request - query, total results, start index, item per page.
type LastfmResponse ¶
type LastfmResponse interface {
// contains filtered or unexported methods
}
type LastfmSessionResponse ¶
type LastfmStatsResponse ¶
type LastfmStatsResponse struct { Listeners int64 `xml:"listeners"` Playcount int64 `xml:"playcount"` }
LastfmStatsResponse is used to parse some of the artist and album stats.
type LastfmStatusResponse ¶
type LastfmStatusResponse struct { Status string `xml:"status,attr"` Error LastfmErrorResponse `xml:"error"` }
LastfmStatusResponse, used to parse the status of any response from lastfm.
type LastfmWikiResponse ¶
type LastfmWikiResponse struct { Published string `xml:"published"` Summary string `xml:"summary"` Content string `xml:"content"` }
LastfmWikiResponse is used for any of the xxx.getInfo's responses. Holds data from the <bio> or <wiki> tags.
type LovedTracksResponse ¶
type LovedTracksResponse struct { LastfmStatusResponse LovedTracks []TrackResponse `xml:"lovedtracks>track"` }
LovedTracksResponse is used where <lovedtracks> is present.
type NeighbourResponse ¶
type NeighbourResponse struct { UserResponse Match float64 `xml:"match"` }
NeighbourResponse Part of NeighboursResponse.
type NeighboursResponse ¶
type NeighboursResponse struct { LastfmStatusResponse Neighbours []NeighbourResponse `xml:"neighbours>user"` }
NeighboursResponse Used where <neighbours> tag is present.
type OpenSearchQueryResponse ¶
type OpenSearchQueryResponse struct { Role string `xml:"role,attr"` SearchTerms string `xml:"searchTerms,attr"` StartPage int `xml:"startPage,attr"` }
OpenSearchQueryResponse is part of LastfmOpenSearchResponse, holds data from the <opensearch:Query> tag.
type RecentTrackResponse ¶
type RecentTrackResponse struct { Name string `xml:"name"` ID int64 `xml:"id"` MBID string `xml:"mbid"` URL string `xml:"url"` Streamable TrackStreamableResponse `xml:"streamable"` Artist ArtistResponse `xml:"artist"` Image []LastfmImageResponse `xml:"image"` Loved int `xml:"loved"` Album AlbumInlineResponse `xml:"album"` NowPlaying string `xml:"nowplaying,attr"` Date LastfmDateResponse `xml:"date"` }
RecentTrackResponse is part of RecentTracksResponse.
type RecentTracksResponse ¶
type RecentTracksResponse struct { LastfmStatusResponse RecentTracks []RecentTrackResponse `xml:"recenttracks>track"` }
RecentTracksResponse is used where <recenttracks> is present.
type SimilarTracksResponse ¶
type SimilarTracksResponse struct { LastfmStatusResponse SimilarTracks []TrackResponse `xml:"similartracks>track"` }
SimilarTracksResponse is used where <similartracks> tag is present.
type TagClient ¶
type TagClient struct {
Client
}
TagClient Collection of methods that correspond to most of LastFM's tag\.(.+) methods. Where the name of the method is \1 in CamelCase.
func (*TagClient) GetInfo ¶
func (c *TagClient) GetInfo(tag string) (response *TagInfoResponse, err error)
Get full information for some tag. Returns TagInfoResponse or error.
Example ¶
Get full info for Tag.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetInfo("rock") if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Name : %v\n", response.Tag.Name) fmt.Printf("URL : %v\n", response.Tag.URL) fmt.Printf("Reach : %v\n", response.Tag.Reach) fmt.Printf("Taggings : %v\n", response.Tag.Taggings)
Output: Name : rock URL : http://www.last.fm/tag/rock Reach : 374178 Taggings : 3979953
func (*TagClient) GetSimilar ¶
func (c *TagClient) GetSimilar(tag string) (response *TagSimilarResponse, err error)
Get similar tags to some tag. Returns TagSimilarResponse or error.
Example ¶
Get Similar Tags.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetSimilar("rock") if err != nil { fmt.Println("Error:") fmt.Println(err) return } tag := response.SimilarTags[0] fmt.Printf("Number of matches : %v\n", len(response.SimilarTags)) fmt.Printf("First match :\n") fmt.Printf("Tag : %v\n", tag.Name) fmt.Printf("URL : %v\n", tag.URL)
Output: Number of matches : 50 First match : Tag : classic rock URL : http://www.last.fm/tag/classic%20rock
func (*TagClient) GetTopAlbums ¶
func (c *TagClient) GetTopAlbums(tag string, page, limit int) (response *TopAlbumsResponse, err error)
Get top Albums with some tag. Returns TopAlbumsResponse or error.
Example ¶
Get Top Albums for Tag.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetTopAlbums("dnb", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } album := response.TopAlbums[0] fmt.Printf("Top Album #1 : %v\n", album.Name) fmt.Printf("Artist : %v\n", album.Artist.Name) fmt.Printf("URL : %v\n", album.URL) fmt.Printf("MBID : %v\n", album.MBID) fmt.Printf("Image [%v] : %v\n", album.Image[0].Size, album.Image[0].URL)
Output: Top Album #1 : Hold Your Colour Artist : Pendulum URL : http://www.last.fm/music/Pendulum/Hold+Your+Colour MBID : 9d9b873c-fbd4-43df-9533-b401dd86081d Image [small] : http://userserve-ak.last.fm/serve/34s/41919803.png
func (*TagClient) GetTopArtists ¶
func (c *TagClient) GetTopArtists(tag string, page, limit int) (response *TopArtistsResponse, err error)
Get top Artists with some tag. Returns TopArtistsResponse or error.
Example ¶
Get Top Artists for Tag.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetTopArtists("dnb", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } artist := response.TopArtists[0] fmt.Printf("Artist #1 : %v\n", artist.Name) fmt.Printf("URL : %v\n", artist.URL) fmt.Printf("MBID : %v\n", artist.MBID)
Output: Artist #1 : Pendulum URL : http://www.last.fm/music/Pendulum MBID : 2030e776-73b2-4cf8-8c15-813e801f8151
func (*TagClient) GetTopTags ¶
func (c *TagClient) GetTopTags() (response *TopTagsResponse, err error)
Get Top Tags in Lastfm. Returns TopTagsResponse or error.
Example ¶
Get Top Tags in Lastfm.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetTopTags() if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Top Tags : %v\n", len(response.TopTags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.TopTags[0].Name) fmt.Printf("URL : %v\n", response.TopTags[0].URL) fmt.Printf("Count : %v\n", response.TopTags[0].Count)
Output: Number of Top Tags : 250 Tag #1 : Name : rock URL : www.last.fm/tag/rock Count : 3979953
func (*TagClient) GetTopTracks ¶
func (c *TagClient) GetTopTracks(tag string, page, limit int) (response *TopTracksResponse, err error)
Get Top Tracks with some tag. Returns TopTracksResponse or error.
Example ¶
Get Top Tracks for Tag.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.GetTopTracks("rock", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.TopTracks[0] fmt.Printf("Top Track #1 : %v\n", track.Name) fmt.Printf("MBID : %v\n", track.MBID) fmt.Printf("Artist : %v\n", track.Artist.Name) fmt.Printf("URL : %v\n", track.URL)
Output: Top Track #1 : Counting Stars MBID : 5e8d518e-328a-43da-a9fa-cc27513a4c86 Artist : OneRepublic URL : http://www.last.fm/music/OneRepublic/_/Counting+Stars
func (*TagClient) Search ¶
func (c *TagClient) Search(tag string, page, limit int) (response *TagSearchResponse, err error)
Search tag by some string. Returns TagSearchResponse or error.
Example ¶
Search for Tags.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tag.Search("rock", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } var tag lastfm.TagResponse fmt.Printf("Search request for : %v\n", response.Query.SearchTerms) fmt.Printf("Total results : %v\n", response.TotalResults) if response.TotalResults > 0 { tag = response.TagMatches[0] } fmt.Printf("First result :\n") fmt.Printf(" Tag Name : %v\n", tag.Name) fmt.Printf(" Tag Count : %v\n", tag.Count) fmt.Printf(" Tag URL : %v\n", tag.URL)
Output: Search request for : rock Total results : 15206 First result : Tag Name : rock Tag Count : 3979953 Tag URL : www.last.fm/tag/rock
type TagInfoResponse ¶
type TagInfoResponse struct { LastfmStatusResponse Tag TagResponse `xml:"tag"` }
TagInfoResponse, used for tag.getInfo's response.
type TagResponse ¶
type TagResponse struct { Name string `xml:"name"` URL string `xml:"url"` Reach int64 `xml:"reach"` Taggings int64 `xml:"taggings"` Streamable int `xml:"streamable"` Count int64 `xml:"count"` Wiki LastfmWikiResponse `xml:"wiki"` }
TagResponse, used where <tag> tag is present.
type TagSearchResponse ¶
type TagSearchResponse struct { LastfmStatusResponse LastfmOpenSearchResponse TagMatches []TagResponse `xml:"results>tagmatches>tag"` }
TagSearchResponse, used for tag.search's response.
type TagSimilarResponse ¶
type TagSimilarResponse struct { LastfmStatusResponse SimilarTags []TagResponse `xml:"similartags>tag"` }
TagSimilarResponse, used where <similartags> is present. For example in tag.getSimilar's response.
type TagsResponse ¶
type TagsResponse struct { LastfmStatusResponse Tags []TagResponse `xml:"tags>tag"` }
TagsResponse, used where there are multiple tags.
type TasteometerClient ¶
type TasteometerClient struct {
Client
}
Type TasteometerClient holds Compare method for user to user comparison.
func (*TasteometerClient) Compare ¶
func (c *TasteometerClient) Compare(type1, value1, type2, value2 string, limit int) (response *TasteometerCompareResponse, err error)
Compare two users or two lists of artists (up to 100 artists per list, comma separated). Returns TasteometerCompareResponse or error
Example ¶
Compare Users
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Tasteometer.Compare("user", "n3mo-", "user", "RJ", 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Compare between %v and %v :\n", response.Input.Users[0].Name, response.Input.Users[1].Name) fmt.Printf("Score : %v\n", response.Result.Score) fmt.Printf("First Artist: %v\n", response.Result.Artists[0].Name)
Output: Compare between n3mo- and RJ : Score : 0.34451797604561 First Artist: Iron Maiden
type TasteometerCompareResponse ¶
type TasteometerCompareResponse struct { LastfmStatusResponse Result CompareResultResponse `xml:"comparison>result"` Input CompareInputResponse `xml:"comparison>input"` }
TasteometerCompareResponse is used for the tasteometer.compare's response.
type TopAlbumsResponse ¶
type TopAlbumsResponse struct { LastfmStatusResponse TopAlbums []AlbumResponse `xml:"topalbums>album"` }
TopAlbumResponse, used where <topalbums> tag is present.
type TopArtistsResponse ¶
type TopArtistsResponse struct { LastfmStatusResponse TopArtists []ArtistResponse `xml:"topartists>artist"` }
TopArtistsResponse, used where <topartists> tag is present.
type TopFansResponse ¶
type TopFansResponse struct { LastfmStatusResponse TopFans []FanResponse `xml:"topfans>user"` }
TopFansResponse Used where <topfans> tag is present.
type TopTagsResponse ¶
type TopTagsResponse struct { LastfmStatusResponse TopTags []TagResponse `xml:"toptags>tag"` }
TopTagResponse, used where <toptags> is present.
type TopTracksResponse ¶
type TopTracksResponse struct { LastfmStatusResponse TopTracks []TrackResponse `xml:"toptracks>track"` }
TopTracksResponse is used where <toptracks> tag is present.
type TrackClient ¶
type TrackClient struct {
Client
}
TrackClient Collection of methods that correspond to most of LastFM's track\.(.+) methods. Where the name of the method is \` is CamelCase.
func (*TrackClient) GetCorrection ¶
func (c *TrackClient) GetCorrection(track, artist string) (response *TrackCorrectionResponse, err error)
Get correction for some track and artist. Returns TrackCorrectionResponse or error.
Example ¶
Get Track correction.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetCorrection("Clint eastwood", "Gorilas") if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Corrections : %v\n", len(response.TrackCorrections)) if len(response.TrackCorrections) > 0 { var track lastfm.TrackResponse track = response.TrackCorrections[0].Track fmt.Printf("Correction #1 :\n") fmt.Printf(" Corrected: [%v] Artist , [%v] Track\n", response.TrackCorrections[0].ArtistCorrected, response.TrackCorrections[0].TrackCorrected) fmt.Printf(" Track : %v\n", track.Name) fmt.Printf(" Artist : %v\n", track.Artist.Name) }
Output: Corrections : 1 Correction #1 : Corrected: [1] Artist , [0] Track Track : Clint Eastwood Artist : Gorillaz
func (*TrackClient) GetInfo ¶
func (c *TrackClient) GetInfo(track, artist string, optionalParams map[string]string) (response *TrackInfoResponse, err error)
Get full information for some track. Returns TrackInfoResponse or error. Be awere there may be an error from the xml decoding.
Example ¶
Get full info for Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetInfo("Kids with guns", "Gorillaz", map[string]string{"autocorrect": "1"}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Track : %v\n", response.Track.Name) fmt.Printf("MBID : %v\n", response.Track.MBID) fmt.Printf("URL : %v\n", response.Track.URL) fmt.Printf("Listeners : %v\n", response.Track.Listeners) fmt.Printf("Playcount : %v\n", response.Track.Playcount) fmt.Printf("Duration : %v\n", response.Track.Duration)
Output: Track : Kids With Guns MBID : 87fe260f-96c5-47bc-9d22-8a1c0f723475 URL : http://www.last.fm/music/Gorillaz/_/Kids+With+Guns Listeners : 609621 Playcount : 3321554 Duration : 224000
func (*TrackClient) GetSimilar ¶
func (c *TrackClient) GetSimilar(track, artist string, optionalParams map[string]string) (response *SimilarTracksResponse, err error)
Get similar tracks to some track. Returns SimilarTracksResponse or error.
Example ¶
Get Similar Tracks to Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetSimilar("Kids with guns", "Gorillaz", map[string]string{}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.SimilarTracks[0] fmt.Printf("Similar Track #1 : %v\n", track.Name) fmt.Printf("MBID : %v\n", track.MBID) fmt.Printf("Artist : %v\n", track.Artist.Name) fmt.Printf("URL : %v\n", track.URL)
Output: Similar Track #1 : Last Living Souls MBID : 14be88ec-e5a6-4b41-b999-d4ca44ac0c52 Artist : Gorillaz URL : http://www.last.fm/music/Gorillaz/_/Last+Living+Souls
func (*TrackClient) GetTags ¶
func (c *TrackClient) GetTags(track, artist string, optionalParams map[string]string) (response *TagsResponse, err error)
Get tags for some track tagged by some user. Returns TagsResponse or error.
Example ¶
Get Tags for Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetTags("Snow", "Red Hot Chili Peppers", map[string]string{"user": "n3mo-", "autocorrect": "1"}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Tags by User : %v\n", len(response.Tags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.Tags[0].Name) fmt.Printf("URL : %v\n", response.Tags[0].URL)
Output: Number of Tags by User : 2 Tag #1 : Name : snow URL : http://www.last.fm/tag/snow
func (*TrackClient) GetTopFans ¶
func (c *TrackClient) GetTopFans(track, artist string, optionalParams map[string]string) (response *TopFansResponse, err error)
Get top fans for some track. Returns TopFansResponse or error.
Example ¶
Get Top Fans for Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetTopFans("", "", map[string]string{"mbid": "87fe260f-96c5-47bc-9d22-8a1c0f723475"}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } user := response.TopFans[0] fmt.Printf("Top Fan #1 : %v\n", user.Name) fmt.Printf("URL : %v\n", user.URL) fmt.Printf("Image [%v] : %v\n", user.Image[0].Size, user.Image[0].URL)
Output: Top Fan #1 : Snerfmonster URL : http://www.last.fm/user/Snerfmonster Image [small] : http://userserve-ak.last.fm/serve/34/92047817.jpg
func (*TrackClient) GetTopTags ¶
func (c *TrackClient) GetTopTags(track, artist string, optionalParams map[string]string) (response *TopTagsResponse, err error)
Get top tags in lastfm for some track. Returns TopTagsResponse or error.
Example ¶
Get Top Tags for Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.GetTopTags("Clint Eastwood", "Gorillaz", map[string]string{"autocorrect": "1"}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Top Tags : %v\n", len(response.TopTags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.TopTags[0].Name) fmt.Printf("URL : %v\n", response.TopTags[0].URL)
Output: Number of Top Tags : 100 Tag #1 : Name : alternative URL : http://www.last.fm/tag/alternative
func (*TrackClient) Scrobble ¶
func (c *TrackClient) Scrobble(artist, track, timestamp string, optionalParams map[string]string) (response *TrackScrobbleResponse, err error)
Example ¶
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") _, err := lfm.Auth.GetSession() response, err := lfm.Track.Scrobble("Balkansky", "8.9", "1400380586", map[string]string{}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Accepted: %d\n", response.Scrobbles.Accepted) fmt.Printf("Ignored: %d\n", response.Scrobbles.Ignored) fmt.Println("Scrobbles[0]:") fmt.Printf("Artist: %s\n", response.Scrobbles.Scrobble[0].Artist.Name) fmt.Printf("Track: %s\n", response.Scrobbles.Scrobble[0].Track.Name)
Output: Accepted: 1 Ignored: 0 Scrobbles[0]: Artist: Balkansky Track: 8.9
func (*TrackClient) Search ¶
func (c *TrackClient) Search(track string, optionalParams map[string]string) (response *TrackSearchResponse, err error)
Search for some track. artist parameter is optional, you may specify it to narrow your search otherwise pass empty string.
Example ¶
Search for Track.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.Track.Search("guns", map[string]string{"artist": "Gorillaz"}) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Search request for : %v\n", response.Query.SearchTerms) fmt.Printf("Total results : %v\n", response.TotalResults) if response.TotalResults > 0 { var track lastfm.TrackResponseNoArtistStruct track = response.TrackMatches[0] fmt.Printf("First result :\n") fmt.Printf(" Track Name : %v\n", track.Name) fmt.Printf(" Artist Name : %v\n", track.Artist) fmt.Printf(" Track MBID : %v\n", track.MBID) }
Output: Search request for : guns Total results : 260 First result : Track Name : Kids With Guns Artist Name : Gorillaz Track MBID : 87fe260f-96c5-47bc-9d22-8a1c0f723475
type TrackCorrectionResponse ¶
type TrackCorrectionResponse struct { LastfmStatusResponse TrackCorrections []TrackSingleCorrectionResponse `xml:"corrections>correction"` }
TrackCorrectioNnResponse is used for the track.getCorrection's response.
type TrackInfoResponse ¶
type TrackInfoResponse struct { LastfmStatusResponse Track TrackResponse `xml:"track"` }
TrackInfoResponse is used for the track.getInfo's response.
type TrackResponse ¶
type TrackResponse struct { Name string `xml:"name"` ID int64 `xml:"id"` MBID string `xml:"mbid"` URL string `xml:"url"` Duration int64 `xml:"duration"` Streamable TrackStreamableResponse `xml:"streamable"` Listeners int64 `xml:"listeners"` Playcount int64 `xml:"playcount"` Artist ArtistResponse `xml:"artist"` Image []LastfmImageResponse `xml:"image"` UserLoved int `xml:"userloved"` Album AlbumResponse `xml:"album"` TopTags TopTagsResponse `xml:"toptags"` Wiki LastfmWikiResponse `xml:"wiki"` }
TrackResponse is used where <track> tag is present and there is a tree of tags for <artist>.
type TrackResponseNoArtistStruct ¶
type TrackResponseNoArtistStruct struct { Name string `xml:"name"` ID int64 `xml:"id"` MBID string `xml:"mbid"` URL string `xml:"url"` Duration int64 `xml:"duration"` Streamable TrackStreamableResponse `xml:"streamable"` Listeners int64 `xml:"listeners"` Playcount int64 `xml:"playcount"` Artist string `xml:"artist"` Image []LastfmImageResponse `xml:"image"` UserLoved int `xml:"userloved"` Album AlbumResponse `xml:"album"` TopTags TopTagsResponse `xml:"toptags"` Wiki LastfmWikiResponse `xml:"wiki"` }
TrackResponseNoArtistStruct is the same as TracKResponse but it is used where the <artist> tag contains only the artist's name.
type TrackScrobbleResponse ¶
type TrackScrobbleResponse struct { LastfmStatusResponse Scrobbles struct { Accepted int `xml:"accepted,attr"` Ignored int `xml:"ignored,attr"` Scrobble []TrackScrobblesResponse `xml:"scrobble"` } `xml:"scrobbles"` }
type TrackScrobblesResponse ¶
type TrackScrobblesResponse struct { Track TrackScrobbleFieldResponse `xml:"track"` Artist TrackScrobbleFieldResponse `xml:"artist"` Album TrackScrobbleFieldResponse `xml:"album"` AlbumArtist TrackScrobbleFieldResponse `xml:"albumArtist"` Timestamp int64 `xml:"timestamp"` IgnoredMessage TrackScrobbleIgnoredMessageResponse `xml:"ignoredMessage"` }
type TrackSearchResponse ¶
type TrackSearchResponse struct { LastfmStatusResponse LastfmOpenSearchResponse TrackMatches []TrackResponseNoArtistStruct `xml:"results>trackmatches>track"` }
TrackSearchResponse is used for the track.search's response.
type TrackSingleCorrectionResponse ¶
type TrackSingleCorrectionResponse struct { Index int `xml:"index,attr"` ArtistCorrected int `xml:"artistcorrected,attr"` TrackCorrected int `xml:"trackcorrected,attr"` Track TrackResponse `xml:"track"` }
TrackSingleCorrectionResponse is part of TrackCorrectionResponse.
type TrackStreamableResponse ¶
type TrackStreamableResponse struct { FullTrack int `xml:"fulltrack,attr"` Streamable int `xml:",chardata"` }
TrackStreamableResponse is part of TrackResponse.
type UserClient ¶
type UserClient struct {
Client
}
UserClients Collection of methods that correspond to part of the LastFM's user\.(.+) methods, where the name of the Go method is \1 in CamelCase.
func (*UserClient) GetInfo ¶
func (c *UserClient) GetInfo(user string) (response *UserInfoResponse, err error)
Get full user information for some user. Returns UserInfoResponse or error.
Example ¶
Get full info for User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetInfo("RJ") if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("User : %v\n", response.User.Name) fmt.Printf("ID : %v\n", response.User.ID) // In this example the user had extra space // in his "Real Name" field, we have to trim it // for the test to pass. fmt.Printf("Real Name : %s\n", strings.Trim(response.User.RealName, " ")) fmt.Printf("URL : %v\n", response.User.URL) fmt.Printf("Country : %v\n", response.User.Country) fmt.Printf("Registered : %v\n", response.User.Registered.Date)
Output: User : RJ ID : 1000002 Real Name : Richard Jones URL : http://www.last.fm/user/RJ Country : UK Registered : 2002-11-20 11:50
func (*UserClient) GetLovedTracks ¶
func (c *UserClient) GetLovedTracks(user string, page, limit int) (response *LovedTracksResponse, err error)
Get loved tracks for some user. You can specify the limit and the page for the result. Returns LovedTracksResponse or error.
Example ¶
Get Loved tracks from user.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetLovedTracks("RJ", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.LovedTracks[0] fmt.Printf("Loved Tracks by RJ\n") fmt.Printf("Track #1 : %v\n", track.Name) fmt.Printf("URL : %v\n", track.URL) fmt.Printf("Artist Name : %v\n", track.Artist.Name)
Output: Loved Tracks by RJ Track #1 : New Year URL : http://www.last.fm/music/Beach+House/_/New+Year Artist Name : Beach House
func (*UserClient) GetNeighbours ¶
func (c *UserClient) GetNeighbours(user string, limit int) (response *NeighboursResponse, err error)
Get neighbours for some user. You may specify the limit of returned users. Returns NeighboursResponse or error.
Example ¶
Get neighbours to some user.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetNeighbours("RJ", 2) if err != nil { fmt.Println("Error:") fmt.Println(err) return } user := response.Neighbours[0] fmt.Printf("Neighbour #1 : %v\n", user.Name) fmt.Printf("Match : %v\n", user.Match) fmt.Printf("URL : %v\n", user.URL)
Output: Neighbour #1 : tonyetc Match : 0.99757462739944 URL : http://www.last.fm/user/tonyetc
func (*UserClient) GetRecentTracks ¶
func (c *UserClient) GetRecentTracks(user string, page, limit int, from, to int64) (response *RecentTracksResponse, err error)
Ger recent tracks listened by some user. You may specify the period (from, to) as UNIX timestamp. Also you may pass page and limit for the request. Returns RecentTracksResponse or error.
Example ¶
Get Recent Tracks for User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetRecentTracks("RJ", 0, 0, 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.RecentTracks[0] fmt.Printf("Recent Track #1 : %v\n", track.Name) if track.NowPlaying != "" { fmt.Printf("!! Now Playing !!\n") } fmt.Printf("Loved : %v\n", track.Loved) fmt.Printf("Artist : %v\n", track.Artist.Name) fmt.Printf("Album : %v\n", track.Album.Name) fmt.Printf("URL : %v\n", track.URL)
Output: Recent Track #1 : Novacane Loved : 1 Artist : Frank Ocean Album : Novacane URL : http://www.last.fm/music/Frank+Ocean/_/Novacane
func (*UserClient) GetTopAlbums ¶
func (c *UserClient) GetTopAlbums(user, period string, page, limit int) (response *TopAlbumsResponse, err error)
Get top albums for some user. You may specify page and limit for the request. Also you may pass the period of the search. For more informacion about valid periods refer to lastfm's api documentation. Returns TopAlbumsResponse or error.
Example ¶
Get Top Albums for User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetTopAlbums("RJ", "", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } album := response.TopAlbums[0] fmt.Printf("Top Album #1 : %v\n", album.Name) fmt.Printf("Artist Name : %v\n", album.Artist.Name) fmt.Printf("URL : %v\n", album.URL) fmt.Printf("Playcount: %v\n", album.Playcount) fmt.Printf("Image [%v] : %v\n", album.Image[0].Size, album.Image[0].URL)
Output: Top Album #1 : Images and Words Artist Name : Dream Theater URL : http://www.last.fm/music/Dream+Theater/Images+and+Words Playcount: 266 Image [small] : http://userserve-ak.last.fm/serve/34s/93189941.png
func (*UserClient) GetTopArtists ¶
func (c *UserClient) GetTopArtists(user, period string, page, limit int) (response *TopArtistsResponse, err error)
Get top artists for some user. You may specify page and limit for the request. Also you may pass the period of the search. For more informacion about valid periods refer to lastfm's api documentation. Returns TopArtistsResponse or error.
Example ¶
Get Top Artists for User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetTopArtists("RJ", "", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } artist := response.TopArtists[0] fmt.Printf("Artist #1 : %v\n", artist.Name) fmt.Printf("URL : %v\n", artist.URL) fmt.Printf("MBID : %v\n", artist.MBID)
Output: Artist #1 : Dream Theater URL : http://www.last.fm/music/Dream+Theater MBID : 28503ab7-8bf2-4666-a7bd-2644bfc7cb1d
func (*UserClient) GetTopTags ¶
func (c *UserClient) GetTopTags(user string, limit int) (response *TopTagsResponse, err error)
Get top tags by some user. You may specify the limit of tags to be requested. Returns TopTagsResponse or error.
Example ¶
Get Top Tags by User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetTopTags("RJ", 2) if err != nil { fmt.Println("Error:") fmt.Println(err) return } fmt.Printf("Number of Top Tags : %v\n", len(response.TopTags)) fmt.Printf("Tag #1 :\n") fmt.Printf("Name : %v\n", response.TopTags[0].Name) fmt.Printf("Count : %v\n", response.TopTags[0].Count) fmt.Printf("URL : %v\n", response.TopTags[0].URL)
Output: Number of Top Tags : 2 Tag #1 : Name : rock Count : 19 URL : www.last.fm/tag/rock
func (*UserClient) GetTopTracks ¶
func (c *UserClient) GetTopTracks(user, period string, page, limit int) (response *TopTracksResponse, err error)
Get top tracks listened by some user. You may specify page and limit for the request. Also you may pass the period of the search. For more informacion about valid periods refer to lastfm's api documentation. Returns TopTracksResponse or error.
Example ¶
Get Top Tracks for User.
lfm := lastfm.New("api_key_for_testing", "api_secret_for_testing") response, err := lfm.User.GetTopTracks("RJ", "", 0, 0) if err != nil { fmt.Println("Error:") fmt.Println(err) return } track := response.TopTracks[0] fmt.Printf("Top Track #1 : %v\n", track.Name) fmt.Printf("Artist Name : %v\n", track.Artist.Name) fmt.Printf("URL : %v\n", track.URL) fmt.Printf("Playcount: %v\n", track.Playcount)
Output: Top Track #1 : Sultans of Swing Artist Name : Dire Straits URL : http://www.last.fm/music/Dire+Straits/_/Sultans+of+Swing Playcount: 78
type UserInfoResponse ¶
type UserInfoResponse struct { LastfmStatusResponse User UserResponse `xml:"user"` }
UserInfoResponse Used for the user.getInfo's response.
type UserResponse ¶
type UserResponse struct { ID int64 `xml:"id"` Name string `xml:"name"` RealName string `xml:"realname"` URL string `xml:"url"` Image []LastfmImageResponse `xml:"image"` Country string `xml:"country"` Age int `xml:"age"` Gender string `xml:"gender"` Subscriber int `xml:"subscriber"` Playcount int64 `xml:"playcount"` Playlists int `xml:"playlists"` Bootstrap int `xml:"bootstrap"` Registered LastfmDateResponse `xml:"registered"` }
UserResponse Used where <user> tag is present.