Scrobble to Last.fm with Pianobar

by Hunter Haugen

Pianobar is an excellent command-line Pandora client. It has support for calling external commands when songs play, pause, skip, et cetera via the event_command directive. With this, we can add a little scrobbling script and get our listening tracks sent to Last.fm.

First, cd to ~/.config/pianobar (or mkdir if it doesn’t exist) and paste https://gist.github.com/833064 in as scrobble.py, and chmod +x it. You’ll have to open scrobble.py and add your Last.fm API key (get one from http://www.last.fm/api) and username/password.

Next, go to pylast and get pylast.py and put it in the same directoy as scrobble.py.

Finally, open or create ~/.config/pianobar/config and put in these lines:

user = email@domain.com
password = somethinglong
event_command = /Users/username/.config/pianobar/scrobble.py

Bonus: If you’re a Pandora One subscriber, you can get the high-quality stream by adding the audio_format = mp3-hifi directive.

(Note: Due to shortcomings in pianobar, your password can’t have funny characters like & in it.)

When you start pianobar, it should start showing up on Last.fm after the first song finishes. If there are problems then pianobar should print them to stderr.

Edit 2011-06-02: The gist has been updated to support Now Playing. Update your scrobble.py with the new version and pianobar should automatically start updating last.fm with Now Playing.