A couple weeks ago, my wife introduced me to Blip.fm — that’s a whole blog post in itself, as I’ve got mixed feelings about it.

rhythmboxNevertheless, it made me curious about ways I could integrate blip.fm or something similar into my awesometop. I currently use Rhythmbox Music Player to play all of my music; It’s kind of like iTunes — in fact the only noticeable difference I’ve found is that when you import a CD you can’t select specific songs: it’s just all or nothing.

One thing that it does have that I don’t think iTunes has is the ability to load plugins (and write your own!!!).  A plugin that caught my eye was the “Rhythm for Web” plugin, which takes the currently playing song data and sends it off to a URL of your choosing. The destination URL can be a widget, a website, an API call, whatever. The author’s website provides sample code to use, but I wanted to do it a little differently than he did. I also made some slight modifications to the plugin itself, in order to make it more clean.

To install the plugin, unzip the tar.gz file to ~/.gnome2/rhythmbox/plugins/RhythmToWeb/. Then load Rhythmbox, click on “Edit”->”Plugins” and locate “RhythmToWeb” in the list. Click on “Configure”.

For “URL” type in the URL of where you will have your handler script. For “Secret” type in any password or string of characters you want to use  (1two3four5six would work, for example, or perhaps your birthdate and name — try to not use spaces of #’s.). Make sure you jot it down for a moment, because you’ll need to use it in the server script below. (Leave “interval” at 2… I’ve never had reason to change that.)

Felix, the original author, liked my “multiple song” tracking and has updated his code to use it.  Nice work!

My PHP server-side code is below.

For this to work, you need two things: a handler and a place to store the data. Since I’m only interested in the “now playing” data, and not tracking historical playing data (that would certainly be doable though!), I just have it write the datastream out to a file.

Download this file, rename the extension to .php, and upload it to your server: rhythmbox.phps

You’ll need to edit the rhythmbox.php file that you’ve just uploaded and change the third line:

define(‘SECRET’, ”);

to reflect whatever you chose to use for your secret code, earlier. For example:

define(‘SECRET’, ’1two3four5six’);

Once that’s done, you should be ready to go! All you need to do is just include the rhythmbox.php file whereever you want to display the data, and it will automatically update! The song data will be stored in a JSON file (created automatically).

That’s it!

RhythmToWeb was first written by Felix Oghina, and the original source is on his website. Thanks to him for writing it initially!

Popularity: 5% [?]