Giter Club home page Giter Club logo

lastfmapi's Introduction

lastfmAPI

Script to use the lastFM API
Written by: Hubert Léveillé Gauvin
Date: 27 December 2017, last revised: 29 December 2017

Getting Started:

To use the lastFM API, you first need to create an API account at:

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

Use your regular lastFM username and password to create your developper app. The app can be called anything.

Open ./lastfmAPI.sh and modify the file by entering your lastFM developper information, including your lastFM API key. You can also modify default options, like the the page number to fetch, the number of results per page, and the format (json or xml). Once this is done, save the file.

Make lastfmAPI.sh executable

chmod +x ./lastfmAPI.sh

Using the API for the first time:

Every time you use this script, your client key is used to send a request to the lastFM API. This is done silently but can sometimes take a few seconds.

Choose one of the API methods and enter the required information as prompted. For more information about the different methods, visit: https://www.last.fm/api

The MORE option allows you to manually enter a URL. This can be useful if the method your are looking for is not available from the list, want to search using mbid, or if you want to momentarily change the format rom json to xml (or vice versa).

Accessing your results

The results of your last query are automatically saved in a file called lastOutput.json or lastOutput.xml. To retrieve specific info from your last query, you can use cat lastOutput.json | jq '<YOURCOMMAND>' , or cat lastOutput.xml

Example:

cat lastOutput.json | jq '.tempo'

For more info about jq, visit: https://stedolan.github.io/jq/

Examples

  1. Create a csv file with songs and artists based on a tag
  method=tag.getTopTracks
  tag=Disco
  
  jq '.tracks.track | .[] | [.name, .artist.name] | @csv' lastOutput.json | sed 's/^"//g' | sed 's/"$//g' | sed s'/\\//g'
  1. Create a csv with the most popular tags and their count for for a specific song
	method=track.getTopTags
	artist=The Beatles
	track=Michelle

	jq '.toptags.tag | .[] | [.name, .count] | @csv' lastOutput.json | sed 's/^"//g' | sed 's/"$//g' | sed s'/\\//g'

lastfmapi's People

Contributors

hleveillegauvin avatar

Watchers

 avatar

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.