Coder Social home page Coder Social logo

lastfm-go's Introduction

Lastfm-go

Golang wrapper for the Last.fm API 2.0

https://www.last.fm/api/

Setup

Get the source codes from github :

% go get github.com/shkh/lastfm-go/lastfm

Import the package :

import "github.com/shkh/lastfm-go/lastfm"

Usage

First, create an API instance with your API KEY and API SECRET.

api := lastfm.New (ApiKey, ApiSecret)

Note that some API methods require your user's permission, so make sure that your requests are authenticated before calling these methods. See "Authentication" section.

API instances contain the structs which represent API classes, and each struct has methods corresponding to their API methods. So you can call artist.getTopTracks for example as following:

result, _ := api.Artist.GetTopTracks(lastfm.P{"artist": "Avicii"}) //discarding error
for _, track := range result.Tracks {
	fmt.Println(track.Name)
}

Methods that fetch some data return their result as a struct named ClassMethod (e.g. api.User.GetInfo returns its result of type UserGetInfo). They can be found in class_result.go. Please look at the file to see which fields are exported.

You can use lastfm.P for arguments. It's just an alias to map[string]interface{}, but values must be string, int, int64 (for unix timestamp) or []string. Slice of string, []string, can be used for passing multiple values for a key.

//album.addTags (auth required)
api.Album.AddTags(lastfm.P{ //discarding error
	"artist": "Kaene",
	"album":  "Strangeland",
	"tags":   []string{"britpop", "alternative rock", "2012"},
})

Authentication

There are three ways to authenticate your requests, which to choose depends on what kind of application you are making.

  • for Mobile Apps

      err = api.Login (username, password)
    
  • for Desktop Apps

      token, _ = api.GetToken () //discarding error
      authUrl = api.GetAuthTokenUrl (token)
      //Send your user to "authUrl"
      //Once the user grant permission, then authorize the token.
      api.LoginWithToken (token) //discarding error
    
  • for Web Apps

      callback = "https://spam.hum"
      authUrl, _ = api.GetAuthRequestUrl (callback)
      //Send your user to "authUrl"
      //Get the token embeded in the redirected URL, then authorize the token.
      api.LoginWithToken (token) //discarding error
    

Supported APIs

Album

Artist

Auth

Chart

Geo

Library

Tag

Track

User

Licence

MIT Licenced. See LICENCE.

lastfm-go's People

Contributors

cfstras avatar djelic avatar jacobwgillespie avatar mborho avatar plasticmacaroni avatar shkh avatar tb0hdan avatar zaybiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lastfm-go's Issues

User.GetFriends xml conflict

Trying to fetch user's friends give the following error:
field "Image" with tag "image" conflicts with field "Images" with tag "image"

Editing UserGetFriends struct solved the problem for me. This should be fixed i guess?

Thanks.

Support Music Brainz ID

It would be nice to add support for the Music Brain ID's. Always usefull to retreive more data about the given ID. And they are so many other use for this...

I changed this myself locally, in a small part of the code, but I couldn't understand how your test where working...

Thanks for the lib !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.