Last.fm

From Indie IT Wiki
Revision as of 08:52, 20 October 2015 by imported>Plittlefield (→‎HOWTO: Show Top Artists Via Command Line)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

HOWTO: Show Top Artists Via Command Line

I wanted to write my own Tweekly-type script to automatically tweet my Top 3 Artists each week.

  1. Find out where the charts are
  2. Find the handy XML feed
  3. Write a PERL script to parse the XML and output
  4. Install a Ruby script to tweet via BASH
  5. Write a BASH script to combine it all
  6. Add that BASH script to my weekly cron job on my Linux server (always on)

Here we go...

RUBY Script

Twitter#How_To_Tweet_Via_The_Command_Line

PERL Script (lastfm.pl)

#!/usr/bin/perl

# load perl modules
use LWP::Simple qw(!head);
use XML::Simple;
use utf8;

# create URL object
$urlcurrent = get('http://ws.audioscrobbler.com/2.0/user/paullittlefield/weeklyartistchart.xml');

# create XML object
$xml = new XML::Simple;

# read XML file and set key attribute
$data = $xml->XMLin("$urlcurrent",KeyAttr=>1);

# show artists
foreach $entry (@{$data->{artist}}) {
  push(@artists,$entry->{'name'});
  push(@playcounts,$entry->{'playcount'});
}
print "My Top 3 #lastfm Artists: $artists[0] ($playcounts[0]), $artists[1] ($playcounts[1]), $artists[2] ($playcounts[2])";

# exit nicely
exit;

BASH Script (lastfm.sh)

#/bin/bash
LASTFM=$(/home/paully/Bin/lastfm.pl | strings |tr -d '\n')
/usr/local/bin/tweet update "$LASTFM"

CRON Tab

@weekly ~/Bin/lastfm.sh

Total time taken: 1 hour :-)

HOWTO: Scrobble With MPD Music Player Daemon

Install the background mpdscribble daemon...

sudo aptitude install mpdscribble

Now stop the system service version...

sudo service mpdscribble stop
sudo update-rc.d -f mpdscribble remove

Create your own configuration file...

mkdir ~/.mpdscribble
nano ~/.mpdscribble.conf
...
[mpdscribble]
 host = localhost
 port = 6600
 log = /home/user/.mpdscribble/mpdscribble.log
 verbose = 2
 sleep = 1
 musicdir = ~/Music
 proxy = none
[last.fm]
 url = http://post.audioscrobbler.com/
 username = user
 password = 34534524524tefevdfgaseRQ
 journal = /home/user/.mpdscribble/lastfm.journal

Start the daemon...

mpdscribble

Add it to your Desktop's Startup and Session in XFCE

Applications > Settings Manager > System > Session and Startup > Application Autostart > Add > mpdscribble

HOWTO: Scrobble With VLC Media Player

Install the background scrobbler daemon...

sudo aptitude install -y lastfmsubmitd
sudo update-rc.d lastfmsubmitd defaults
sudo service lastfmsubmitd restart

In VLC...

Tools > Preferences > Show Settings > All
Interface > Control Interfaces > Tick 'Submission of played songs to Last.fm'
Audioscrobbler > Username + Password + Scrobbler URL - http://post.audioscrobbler.com/
Save
Restart VLC