Last Updated: February 25, 2016
·
313
· niedzielski

Mine Data from Last.fm

Casually exercise the Last.fm API from the command line by adding the following to your .bashrc:

fm()
{
  declare API_KEY=... # TODO: get API key.
  curl -s \
    -d"api_key=$API_KEY" \
    ${1:+"-dmethod=$1"} \
    ${2:+"-d$2"} ${3:+"-d$3"} ${4:+"-d$4"} ${5:+"-d$5"} \
    ${6:+"-d$6"} ${7:+"-d$7"} ${8:+"-d$8"} ${9:+"-d$9"} \
  'http://ws.audioscrobbler.com/2.0'
}

Examples:

# Find artists similar to Surfer Blood.
$ fm artist.getSimilar artist=Surfer\ Blood|grep '<name>'
    <name>Wavves</name>
    <name>Real Estate</name>
    <name>Smith Westerns</name>
...

# Read insightful track comments.
$ fm track.getShouts track=Yesterday artist=The\ Beatles
    <shout>
    <body>YESTEHDAYYYY, ALL MY TROUBLES SEEMED SO FAR AWAYYYYYYYY... lol</body>
    <author>alexia_N</author>
    <date>Fri, 6 Apr 2012 04:44:56</date>
</shout>
...