Listen to Pandora in your terminal via Pianobar

April 26, 2011 by . 16 comments

I constantly listen to Pandora (even while I sleep). However one thing I’ve always disliked about Pandora was that it required Flash. You remember Flash, it’s that enormous resource hog that’s constantly crashing. Then I discovered Pianobar, the open-source Pandora client that runs in your terminal. Pianobar is chock full of features:

  • play and manage (create, add more music, delete, rename, …) your stations
  • rate played songs and let Pandora explain why they have been selected
  • show upcoming songs/song history
  • configure keybindings
  • last.fm scrobbling support (external application)
  • proxy support for listeners outside the USA

If you’re running Ubuntu, you can install Pianobar simply by typing sudo apt-get install pianobar, and to launch it type pianobar. If your on OS X there a few more steps:

curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
This will install the Homebrew package manager. Homebrew is like apt-get, except for OS X. Now type brew install pianobar to install Pianobar. That’s it! You can start enjoying music in your terminal.

Customization

We’re Super User’s, and that means we have a need to customize everything. That’s why you have that unicorn wallpaper. So how can we customize Pianobar? Well first of all, typing in your username and password every time you want to listen to music is annoying. Luckily you can create a config file for Pianobar to avoid this. Open your favorite text editor (cough gedit) and enter this:

user = lucas@ponyoverflow.com
password = ilikeunicorns
audio_format = mp3-hifi
This is pretty self explanatory. The first line is where your username will go and line two is for your password. The third option tells Pianobar to download high quality audio; if your on a slow connection you can omit this option. You’ll need to save this file in ~/.config/pianobar/ as config.

One feature I really like about the AdobeAIR client for Pandora are the notifications on song change. We can replicate this on Ubuntu using libnotify-bin (download via sudo apt-get install libnotify-bin) or on OS X by using Growl (brew install growlnotify). Now reopen the config file and add this line at the bottom:

Ubuntu:
event_command = /home/myuser/bin/pianobar-notify
OS X:
event_command = /Users/yourusername/bin/pianobar-notify.rb
Grap the correct file for your operating system here: Ubuntu / OS X

Now that we have working notifications, it would be nice if we didn’t need that extra terminal window open all the time. To avoid this you can install Tilda. Tilda is a terminal that runs in the background; when you need it just press a shortcut key and you have a terminal, press again and it’s gone. To get Tilda just type sudo apt-get install tilda.

Now we have successfully cut the cord that connected Mother Flash and Baby Pandora; in the process reclaiming precious memory.

Filed under Software

16 Comments

Subscribe to comments with RSS.

  • Sathya says:

    And Pithos is most excellent if you want a GUI tool.

  • Actually, you can install pianobar on Mac OS X via MacPorts.

    sudo port install pianobar

  • says:

    @KronoS: I’m not sure about Windows. I guess you could try it with cygwin.

  • Bruce Connor says:

    I keep getting /!\ Cannot start eventcmd. (Permission Denied) for my notifications. I’ve tried marking the file as executable, but then I get /!\ Cannot start eventcmd. (Exec format error)

    am I doing something wrong here?

  • Bruce Connor says:

    Hm… After inserting a blank line in the file and renaming it to .sh I managed to get rid of the error messages, but notifications are simply not showing up.

  • Bruce Connor says:

    @KronoS I will =). I just wanted to poke around a little more before going there.

  • Brian says:

    Bruce, if you use the download button then the script contains invalid characters (windows new lines). You can remove them easily with vi: at a shell, type: vi ~/.config/pianobar/config Press : (colon) Type ‘% s/’ Press Ctrl+V, then Ctrl+M Type ‘//’

    The bottom of the vi window should look like ‘:% s/^M//’ Then press enter. All the ^M’s should go away.

    Type ‘:wq’ and press enter again to quit.

    If you aren’t comfortable with vi then just copy & paste the script into gedit instead of using the download button.

  • Eric says:

    Thanks for the tip Brian, I’m not Bruce (the original poster with this problem) but I’m still getting the error: /!\ Cannot start eventcmd. (Permission denied) even after ensuring I don’t have any wierd hidden characters in my config file or my .rb file.

  • Eric says:

    My “/!\ Cannot start eventcmd” problem was just that I hadn’t added execute permissions to the .rb file.

    I’ve since discovered: https://gist.github.com/832632/6bb39b85dda8f8212dc4b8bc6e7acd6b8c45d6eb which does both growl notifications and last.fm scrobbling.

  • Andrew Rich says:

    Thank you for this! I used your instructions combined with a bit from the shell script from Isaac Hodes’ blog post (http://copperthoughts.com/p/lovely-pianobar/) and a Pandora icon I found on Google images (http://blog.caranddriver.com/wp-content/uploads/2011/01/Pandora-App-Icon.png) to add the album name and Pandora icon to the Growl notification.

    Just drop the Pandora icon in .config/pianobar and change the growlnotify line to:

    growlnotify -t "Now Playing" -m "#{songinfo['title']} on #{songinfo['album']}nby #{songinfo['artist']}" --image=/Users/yourusername/.config/pianobar/Pandora-App-Icon.png

    Thanks again!

  • Great work! I just updated this script to include the album art from Pandora. Feedback welcome.

    https://gist.github.com/1668755

  • Andrew Rich says:

    Any thoughts on adding a “Tweet this song” menu option? It is available in the Flash player.

  • Josh says:

    no need for all the growlnotify stuff. Try this notify script instead:

    http://pastebin.com/gWie2TJq

  • Comments have been closed for this post