Friday, March 21, 2008

(Grease) Monkey Business

I've been reading David Byrne's journal (of the Talking Heads fame) since before I heard about blogs and blogging. In an ocean of software blogs that flood my Google Reader, it's one of the few that remind me that I have other interests besides computers. From this journal I found out that he also hosts an internet radio station that I've been often enjoying while at work or sometimes at home.

For this task I've been using iTunes on my Mac at home and Rhythmbox on Linux at work. Besides the easier subscription to the station, the one thing I miss from iTunes while at work is seeing the currently playing song on Rhythmbox. I don't know how iTunes does it, but it's always showing the correct song title and artist, while on Rhythmbox all I see is the station name.

Therefore I had resorted to having a tab open in Firefox all day that displayed the radio home page that shows the playlist and refreshes each time a new song begins. I still had to switch to the browser from whatever I was doing when a new song started, in order to glance on its title and performer. A few days ago I thought to myself: "wouldn't it be nice to have the Firefox title bar display that information and only take my eyes off what I'm currently doing and not my fingers too?".

It turns out that I'm very persuasive when I'm talking to myself, so I set off to make my wish come true. I've been also trying to find an excuse to learn more about Greasemonkey for some time and it seemed like the right time to do it. So after I spent some time reading up stuff from the web, I came up with something that made me happy:

(function() {
window.addEventListener("load", function(e) {

var PLAYLIST_URL = '';

(function fetchCurrentSong() {
method: "GET",
onload: function(details) {
var xmlString = details.responseText;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlString, "application/xml");
var refresh = xmlDoc.getElementsByTagName('Refresh')[0].textContent;
var artist = xmlDoc.getElementsByTagName('Artist')[0].textContent;
var album = xmlDoc.getElementsByTagName('Album')[0].textContent;
var title = xmlDoc.getElementsByTagName('Title')[0].textContent;
var label = title+' by '+artist+' from '+album;
document.title = label;
setTimeout(fetchCurrentSong, refresh);

}, false);

It's amazing what 20 lines of JavaScript can do. You can install this user script by clicking here, assuming you have Greasemonkey installed and enabled. If you don't have Greasemonkey or prefer to install a firefox extension that does not require it, click this link instead. It was automagically created with the very nifty User Script Compiler.

This is what I see now when I'm listening to David's playlist (although many times I just glance at the title in the minimized button on the bottom panel):

Remixing the web, indeed.

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.
Creative Commons License Unless otherwise expressly stated, all original material in this weblog is licensed under a Creative Commons Attribution 3.0 License.