Thursday, December 07, 2006

musicindiaonline and greasemonkey

musicindiaonline has tons of indian music. The problem is that on linux, their javascript does not work well (I see some errors in the JS console).

I went ahead and wrote some greasemonkey based code that finds the links that point to music clips, performs some transformation on them(this, I learnt from their scripts) and finally pops up a popup window that works well with realplayer 10 on linux (you will still face the code problems with some of thier clips. That is beyond this solution).

Here is the code
----------------



function scanForMusicLinks()
{
var menuDiv = document.getElementById('divMenu');


var musicRE = /\/p\/x\//;

var anchors = document.getElementsByTagName('A');

var nLinks = 0;

var anchorData = [];

for(var i = 0; i< anchors.length;i++)
{
if(musicRE.exec(anchors[i].href))
{
var href = anchors[i].href + 'play.smil';


href = href.replace('/p/x/','/g/r/');

var content = anchors[i].innerHTML;

anchorData.push({href:href,content:content});


}
}

if(anchorData.length > 0)
{
processAnchorData(anchorData);
}

}

function playThis(index)
{
var playerSpan = document.getElementById("playerSpan");


playerSpan.innerHTML = '<EMBED TYPE="audio/x-pn-realaudio-plugin" NAME="RAPlayer" SRC="' +
anchorData[index].href
+ '" AUTOSTART="TRUE"></EMBED>';

}

function processAnchorData(anchorData)
{
var html = '<HTML><HEAD><SCRIPT language="JavaScript1.2">';

html += 'var anchorData = [';

for(var i = 0; i< anchorData.length;i++)
{
if(i > 0)
{
html += ',';
}

html +=
'{href:"' + anchorData[i].href +
'",content:"' + anchorData[i].content + '"}';

}

html += '];';

html += playThis;

html += '</SCRIPT></HEAD><BODY>' +
'<SPAN id="playerSpan">' +
'Player will appear here</SPAN><OL>';

for(var i = 0; i< anchorData.length;i++)
{
html += '<LI><A href="javascript:playThis(' + i + ');">' +
anchorData[i].content + '</A></LI>';
}

html += '</UL></BODY></HTML>';


var popup = window.open('','Play list','width=200,height=500,toolbar=0');

popup.document.open();

popup.document.write(html);

popup.document.close();
}

window.addEventListener('load',scanForMusicLinks,true);



----------------

To get this working for you:
  • install greasemonkey
  • save the above content into a file (say musicindiaonline.user.js) : make user the name matches .*\.user.js
  • in your browser(firefox, of course) type the address of that file like 'file:///home/foobar/tmp/musicindiaonline.user.js' and hit enter(or simply browse to that file using file browsing capabilities of firefox)
  • greasemonkey pops up some controls on the top of your window - click Install.
  • Map the newly installed script to http://www.musicindiaonline.come/music/* and you are ready to go.

1 Comments:

Anonymous Anonymous said...

Hey, try http://www.hummaa.com It has integrated falsh player that give sit advantage over other streaming sites in addition it has super sound quality with music cotents in all Indian languages.

6:07 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home