Monday, January 3, 2011

Pianobar, iTunes, and GeekTool

For those of you who haven't seen Pianobar, it's a great little terminal-based player for Pandora.  It was featured on Lifehacker as a Flash-free player for Mac and Linux (and Cygwin-based Windows installations).

Of course, being the fan of Conky that I am, my first thoughts were to find a way to parse out the content from Pianobar and display them on the desktop.  This, it turns out, was a bit harder than it seemed.  The content streaming into the terminal is littered with extra characters, which are great when viewing from the console.  These characters, however, need to be extracted from the content so the raw data is accessible.  Moreover, Pianobar has a nice feature which prints the time remaining for the currently playing song.  This information is printed to the console using the '\r' character so the time overwrites itself.  When diverted to a file, this results in excessively long lines which need to be parsed.

With this in mind, I started my latest project was to extract this information and print it so tools like Conky and GeekTool could print them to the desktop while they are running.  The result, though a bit hacky, was fairly nice.

Once this was finished, however, another idea struck me: what if I'm playing iTunes rather than Pianobar?  I'd still like to display this content on the desktop.  What's more, I'd like to use the same program to do both.

So, my next project was to extend this script so it could handle multiple musical inputs.

I've posted the results to SourceForge.  Let me know what you think!