Skip to content

Archive for

2
Feb

Pandora from the Command Line

I like having Pandora going pretty much all the time, be it Bach when I’m coding, Techno for sysadmin tasks, or indulging my shameful pop music addiction.  I wanted a way to control Pandora without having to drop out of the shell.  I wanted it for my Mac, but lucked out and found one that works across all the platforms I use.  Pianobar is a command line Pandora client and it works in Mac and Linux. (And Windows too.)

I was having a little trouble building it in Snow Leopard using the instructions from here, when I discovered that it’s already available in MacPorts.  So I installed it with:

sudo port install pianobar

In Linux, you can find links to the repos for your distro of choice on the Pianobar website.

Next, I wanted it to login automatically and start playing when I launched it.  On Mac, you can create a config file at ~/.config/pianobar/config, with contents similar to the following:

autostart_station = 1234567890
password = s3cR3t_sQu1RR3L
user = johnny.chimpo@afghanistanimation.org

To get the station ID for the autostart_station parameter:

  1. Run pianobar
  2. Log in manually
  3. Launch your favorite station
  4. Hit i to see the station and song info.
  5. The station ID will be in parentheses after the station name.

After you’ve got your file saved, you should be able to launch pianobar and have it start playing auto-magically.

Now, my next step was to use at so I could start pianobar at a given time and use it as an alarm clock.

You need to enable atrun on your Mac to use at to schedule jobs. (It’s enabled by default on most Linux distros.)  You can schedule the launch like so:

at 5:30am tomorrow #hit enter
pianobar #hit enter
#hit Ctl+D

If you start pianobar with at, it’s not on an interactive shell so you have no way to interact with it, or so I thought.  You can create a fifo file to pass controls to the process:

mkfifo ~/.config/pianobar/ctl

Once you have that, you can control pianobar by echoing commands into the fifo:

#To pause:
echo p > ~/.config/pianobar/ctl
#To quit:
echo q > ~/.config/pianobar/ctl
#etc. etc.

Hopefully that’s food for though enough to get you started.  Enjoy.