View Full Version : Adventures In Reinventing the Wheel

2006-04-02, 13:37
Several forum members are using the WebLogger plugin to display what’s currently playing on their Squeezeboxes on their personal web sites.

My philosophy: Why spend five minutes implementing a perfectly functional existing solution when you can spend 30 or 40 hours doing a substandard version of the same thing from scratch?

I’m not a PERL programmer, but I deduced from looking at the scripts for WebLogger that it relied on a technique to similar to the one employed in KDF’s Execute Script plugin to ascertain when SlimServer played files. The Execute Script plugin listens for various SlimServer events and then executes scripts when the events fire. I was already using Execute Script, and it seemed like it would be fairly straightforward to write a script to update a page on our web site that would execute on SlimServer’s Play, Stop and Squeezebox Power Off events.

Taking a look at the Technical Information link on the SlimServer web interface, I learned about SlimServer’s XML skin. By browsing to: http://localhost:9000/xml/status.xml, I found that the XML returned from this URL contained all of the information that I wished to display on our web site. So, I set about writing a script that would read the current “status” XML, extract the desired data, insert the data into a much simplified XML structure, post the XML to our web site, and then FTP the current cover image, should one exist. It took quite a while to debug, but the script itself was not too difficult to produce. Getting it to run with the Execute Script plugin was another story. It simply would not work. Double-clicking on the script worked fine, but using the Execute Script plugin, my script hung trying to load the XML from status.xml. I still don’t know what the issue is (although I assume it’s permissions-related), but eventually I had to look for a workaround.

I tried all sorts of options, calling my script in a batch file, moving the portion of my code that would not run into an executable, etc., but all attempts failed. Finally, I focused on the Task Scheduler. I had discovered earlier that running the script as a Scheduled Task worked. I started looking around for information about scripting the task scheduler. My plan was to have the Execute Script plugin execute a script that instructed the Task Scheduler to launch my script.

My SlimServer is running on a Windows 2000 box. Scripting the Task Scheduler on Windows 2000 is possible, but not extremely pretty. And while I found how script the creation of a task, I couldn’t find a means of scripting a command to “run this task now.” XP, however, includes an application called schtasks.exe that can be scripted to run a task immediately. Officially, this program runs only on XP and higher, but I found a tip about using a hex editor to make a slight change to the program that allows it to run under Windows 2000.

Once I got the task scheduling and executing squared away, I had a little trouble getting Execute Script to recognize the Play event. KDF helped me through that issue with some changes to the Execute Script plugin. I also made a few changes myself such as adding a handler for the Power Off event and suppressing the attempts by the script to display what it’s doing on the Squeezebox’s display.

The one issue that I was not able to resolve other than through brute force was to update our web site when the Squeezebox had either stopped or was turned off. This is possible by using the CLI, but I have no knowledge in that area right now, so my brute force method is simply to check the Squeezebox every five minutes (with another task and script) to see if it’s either stopped or off.

Here’s the finished product. Hopefully, we’re playing something interesting if and when you have a look:


In the ZIP file below, I’ve included all of the files for this status monitor in case anyone else wants to play with them. This is a Microsoft IIS/ASP/VBScript-based project.

UPDATE_SLIMSERVER_STATUS.vbs: This is the main script that loads the “status” XML, extracts the needed data, inserts the data into a much simplified XML structure, posts the XML to our web site, and then FTPs the current cover image. It's scheduled to run at system startup and just sits there otherwise until called upon.

UPDATE_NONPLAYING_STATUS.vbs: This script notifies our web site if the Squeezebox has either stopped or is off. It runs from a scheduled task every five minutes.

LAUNCH_UPDATE_TASK.vbs: This script instructs the Task Scheduler to run the UPDATE_SLIMSERVER_STATUS.vbs script immediately.

Execute.pm: My modified version of KDF’s script (1.7) for SlimServer 6.2.x that includes an extra event to listen for: Power OFF and also changes 1) to listen for the Play event, and 2) activate the script on initialization. KDF has a different version of the script for SlimServer 6.5.

On our web site:

now_playing.xml: The XML file that contains data about SlimServer’s status.

recently_played.xml: I’m also tracking the last 20 items played on the Squeezebox.

update_now_playing_xml.asp: This page accepts the posted XML from the UPDATE_SLIMSERVER_STATUS.vbs script and saves it to now_playing.xml.

now_playing.asp: This is a two-frame frameset document. It is designed to appear in a 383px by 425px iframe on another page (in my case, slimserver_status.asp).

now_playing_details.asp: This document displays SlimServer’s “now playing” status and loads into the top frame of now_playing.asp. It includes code to make every attempt to always load fresh stuff and not rely on the browser’s cache.

now_playing_monitor.asp: This page resides in the bottom 0px frame of now_playing.asp, and is invisible to the user. It reloads every ten seconds and compares the state of now_playing.xml with values stored in Session variables. If it detects a change, it forces now_playing_details.asp to reload. If everything works as it’s supposed to, our web site is never more than ten seconds behind what’s actually happening on the Squeezebox.

recent_selections.asp: This page displays the 20 most recently played selections.

Mark Lanctot
2006-04-02, 17:25
That sounds pretty cool, thanks for all the hard work, Jon!

The really cool part would be if you could use this to display what's playing on your Squeezebox in a sig file which could be displayed on these forums. The forum isn't currently set up to display sigs, but most vBulletin forums are, so it's merely a matter of turning it on.

Any ideas if this script could do this?

'Course not everything I play on my Squeezebox I want people to know about. Some of it is pretty embarassing. :-P

2006-04-02, 19:12
Like the music you play when on the bicycle?

Mark Lanctot
2006-04-02, 19:26
Like the music you play when on the bicycle?

I was listening to some fast Chemical Brothers stuff yesterday.

I was averaging over 35 kph, reaching 40 kph. I sustained that for 16 minutes, 10 km.

Needless to say, quite a workout.

But I'm really starting to like exercising while listening to the Squeezebox. Gets me in shape and gives me some quality time with my favourite toy. I like Random Mix - "what's it going to play next?"

That's not embarassing though. I have some stuff just because I like it but I'd rather not have anyone else know. :-)

2006-04-03, 05:44
Should I be embarrassed if someone notices we're playing Raffi from time to time?

2006-04-03, 09:45
jonheal wrote:
> Should I be embarrassed if someone notices we're playing Raffi from time
> to time?
just retag it "Raffi - this is my wife's fault".

Me: "why did you buy that?"
Wife: "The kids like it."
Me: "They also like the Pogues, did we have to introduce Raffi too?"

Jack at Monkeynoodle dot Org: It's a Scientific Venture...
Riding the Emergency Third Rail Power Trip Since 1996