PDA

View Full Version : Publicradiofan.com Slimserverize Greasemonkey Script



bklaas
2006-01-05, 15:10
Man is that a mouthful. So, as Tom Malsbury described in a different thread (http://forums.slimdevices.com/showpost.php?p=75612&postcount=97), the handy publicradiofan.com plugin works great via the remote but, by request of the site owner, has no slimserver browser access. In light of that, I wrote up a greasemonkey script that does the following when installed:
any page loaded from publicradiofan.com will reformat all mp3 stream links to immediately stream to the squeezebox (via the 'radio tune-in' URL logic of the slimserver).

You will need to do several things before you get this working for you:

* use firefox/mozilla as your browser (there are so many other reasons for this; just make the jump)
* install greasemonkey
* download the script from http://benklaas.com/slimserver/slimserverize.user.js and edit in the correct mac addr and ip address for your slimserver
* point your web browser to the directory where your edited script is (hint: use file://path_to_dir if you have it in a local directory)
* right-click on the file and select 'install user script...'
* make sure your slimserver server settings has Security->CSRF set to NONE, or else you will get a 403 error from slimserver

This is a first pass, so if you try it out and have suggestions for improvement, I'm all ears.

most of this text is more or less reprinted at http://benklaas.com/slimserver/

cheers,
#!/ben

malsbury
2006-01-05, 15:17
This is a first pass, so if you try it out and have suggestions for improvement, I'm all ears.

most of this text is more or less reprinted at http://benklaas.com/slimserver/
I just have to wonder if you are getting any sleep with the amount of work you have been doing on your skin and now this....

I'll give it a shot and let you know how it goes.

--Tom Malsbury

bklaas
2006-01-05, 16:23
thanks, Tom. Actually it's my 2-year-old daughter and her new-found penchant for waking up for the day at 5am that is cutting most into my sleep. Not to say that I haven't been spending quite a bit of time on slimserver stuff (I'm embarassed to tell you how long it took me to write the 15 or so lines in that greasemonkey script). I wouldn't be doing it if it wasn't fun (and fun to use as well).

I should note that while this script is specific to publicradiofan.com, the possibility of this to be generic to all sites exists, and would extend the appeal immeasurably. Ideally, what I'd like to see is what Steve Baumgarten mentioned on the Nokia770 thread-- a right-click on any link that gives you an option to "stream directly to slimserver". That would require this to work as an extension rather than a greasemonkey script, but there is a pretty clear path documented on how to push a greasemonkey script into a full-fledged XPI extention.

Would that be cool or what...

ramble on,
#!/ben

chrisla
2006-01-05, 16:46
That would be a great feature indeed!
I'd pay to see that.

-Chris
On 1/5/06, bklaas <bklaas.216qbz (AT) no-mx (DOT) forums.slimdevices.com> wrote:
>
> thanks, Tom. Actually it's my 2-year-old daughter and her new-found
> penchant for waking up for the day at 5am that is cutting most into my
> sleep. Not to say that I haven't been spending quite a bit of time on
> slimserver stuff (I'm embarassed to tell you how long it took me to
> write the 15 or so lines in that greasemonkey script). I wouldn't be
> doing it if it wasn't fun (and fun to use as well).
>
> I should note that while this script is specific to publicradiofan.com,
> the possibility of this to be generic to all sites exists, and would
> extend the appeal immeasurably. Ideally, what I'd like to see is what
> Steve Baumgarten mentioned on the Nokia770 thread-- a right-click on
> any link that gives you an option to "stream directly to slimserver".
> That would require this to work as an extension rather than a
> greasemonkey script, but there is a pretty clear path documented on how
> to push a greasemonkey script into a full-fledged XPI extention.
>
> Would that be cool or what...
>
> ramble on,
> #!/ben
>
>
> --
> bklaas
> ------------------------------------------------------------------------
> bklaas's Profile: http://forums.slimdevices.com/member.php?userid=58
> View this thread: http://forums.slimdevices.com/showthread.php?t=19751
>
>

dwc
2006-01-05, 17:37
"edit in the correct mac addr and ip address for your slimserver"

To be clear, this is the mac and ip of the slimserver PC nic, and not the mac/ip of the Squeezebox. (right?)

Thanks,
Dan

bklaas
2006-01-05, 18:09
sorry, should have been clear there.

mac address of the squeezebox (you should be able to glean this information from one of the slimserver web interface urls)
ip address of the server

that should get you there...

cheers,
#!/ben

malsbury
2006-01-05, 20:42
I should note that while this script is specific to publicradiofan.com, the possibility of this to be generic to all sites exists, and would extend the appeal immeasurably. Ideally, what I'd like to see is what Steve Baumgarten mentioned on the Nokia770 thread-- a right-click on any link that gives you an option to "stream directly to slimserver". That would require this to work as an extension rather than a greasemonkey script, but there is a pretty clear path documented on how to push a greasemonkey script into a full-fledged XPI extention.

Installation went well. Here are a few notes from my install. You should mention that that you should save the file locally, edit it for the server and mac address, then "revisit" the script locally.

I installed greasemonkey then "revisted" the script on your page assuming that I would get to edit the user defined parameters upon install. It wasn't a problem, just not clear for a first time greasemonkey user.

I also didn't realize at first that I had to point directly at the mp.gif to find the altered url. Once that was found and I clicked on the link, I got the following message:

403 Forbidden: status.html

In order to request this URL from a Bookmark/Favorite, or some
means other than following a link from the SlimServer web
interface, you will need to use a URL with a \"cauth\" security
parameter. If you received this error when following a link from
the SlimServer web interface, you will want to make sure your web
browser software (including proxy servers and spyware/privacy
software) is allowing \"Referer\" headers to be sent. Below is
the appropriate URL for the URL you attempted.

http://centos:9000/status.html?p2=http%3A%2F%2F209.165.135.138%3A8000 %2Flisten.pls&p0=playlist&p1=play&player=00:04:20:04:02:f4;cauth=00ac3b1d2a6b356f3e7 b53a8b0a60c65

Because your CSRF protection level is set at 'MEDIUM', you can
use the same ";cauth=" value for any URL; this means you should
be more careful who you share your URLs with.
Once I clicked on the suggested reformatted url my SliMP3 fired right up. I guess you might need to add a "cauth" security parameter to the reformatted url, whatever that might be. Is this something that you have encountered on your system? I am using CentOS 4.1 (Redhat EL4 based) with Slimserver 6.5 (12/30 nightly) and making the request from XP SP2 using Firefox 1.5, Greasemonkey 0.6.4.

I was also interested how difficult it would be able to also alter the urls for WMA and RA/RAM files since these can get transcoded thanks to AlienBBCs mplayer.sh. Just a thought.

I have to agree that an extension does get the mind going....

I'll bang on it a little more and let you know how it goes.

--Tom Malsbury

malsbury
2006-01-05, 21:10
I guess you might need to add a "cauth" security parameter to the reformatted url, whatever that might be. Since it said I could use the same "cauth" value for any request I edited the script and added this:
var urlStubTwo = '&p0=playlist&p1=play&player=' +macAddr + ';cauth=00ac3b1d2a6b356f3e7b53a8b0a60c65';It is now working fine for me when I click on any mp.gif link without the warning message.


I was also interested how difficult it would be able to also alter the urls for WMA and RA/RAM filesAnswered my own question, no very hard at all... I simply repeated your mp.gif search for the other two.
if (parent.href) {
// see if the img src is mp.gif, (which indicates an mp3 stream), rm.gif (which indicates a RealAudio stream), or wm.gif (which indicates a Windows Media stream).
var match = thisElement.src.match(/mp\.gif/);
if (match) {
// append href of link to stub
var urlStubThree = encodeURIComponent(parent.href);
var rewrite = urlStubOne + urlStubThree + urlStubTwo;
// remove current href link
parent.removeAttribute('href');
// add new one
parent.setAttribute('href', rewrite);
}
var match = thisElement.src.match(/rm\.gif/);
if (match) {
// append href of link to stub
var urlStubThree = encodeURIComponent(parent.href);
var rewrite = urlStubOne + urlStubThree + urlStubTwo;
// remove current href link
parent.removeAttribute('href');
// add new one
parent.setAttribute('href', rewrite);
}
var match = thisElement.src.match(/wm\.gif/);
if (match) {
// append href of link to stub
var urlStubThree = encodeURIComponent(parent.href);
var rewrite = urlStubOne + urlStubThree + urlStubTwo;
// remove current href link
parent.removeAttribute('href');
// add new one
parent.setAttribute('href', rewrite);
}
}--Tom Malsbury

bklaas
2006-01-05, 21:30
hi Tom--

couple of notes in response...

the cauth thing...you need to go to your slimserver server settings, click on the security link, and select 'none' for CSRF security (should be at the bottom of that page). After that, there is no need for a cauth param on your URL.

on your code to add wm and rm support-- instead of making three matches and corresponding js blocks, I would instead making a one line change to the script--
this:
var match = thisElement.src.match(/mp\.gif/);
to this:
var match = thisElement.src.match(/(mp|wm|rm)\.gif/);

the updated line matches on all three gifs, rather than just the one. (For those that haven't hacked in real support, remove the |rm part)

cheers,
#!/ben

kdf
2006-01-05, 21:32
On 5-Jan-06, at 8:10 PM, malsbury wrote:

>
> malsbury Wrote:
>> I guess you might need to add a "cauth" security parameter to the
>> reformatted url, whatever that might be. Since it said I could use
>> the same "cauth" value for any request I
> edited the script and added this:
> Code:
> --------------------
> var urlStubTwo = '&p0=playlist&p1=play&player=' +macAddr +
> ';cauth=00ac3b1d2a6b356f3e7b53a8b0a60c65';
> --------------------
>
I believe that cauth won't the same for every system, however.
-k

malsbury
2006-01-06, 06:16
On 5-Jan-06, at 8:10 PM, malsbury wrote:

>> I guess you might need to add a "cauth" security parameter to the
>> reformatted url, whatever that might be. Since it said I could use
>> the same "cauth" value for any request I edited the script

I believe that cauth won't the same for every system, however.
-kSorry, I realized that was probably the case, and ment to give my change as an example of what worked on my system. Not as a fix for everyone.

--Tom Malsbury