I put up on my web page what I am listening to at the moment. This article tells how I do that.
I listen to music through the Squeezebox, a fabulous device made by SlimDevices that plays MP3s you have on your computer through your stereo system. “SlimServer” is the server that runs on whatever computer you have handy, that you talk to through a web interface, and feeds the music wirelessly to the Squeezebox. SlimServer can also report its current status, including the current song being played, in XML format, which turns out to be useful, via the URL:
http://slimserver:9000/xml/status.html
Using wget or lwp-request, I grab this data and then process it through XSLT to get a simple string of the form SONG by ARTIST from ALBUM:
<?xml version="1.0"?>
<!-- slim-putsong.xsl:
transform slimserver XML status output into SONG by ARTIST from ALBUM -->
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sl="http://www.slimdevices.com/slimserver/xml"
version="1.0"
>
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="sl:status/sl:player_status/sl:current_song/sl:song">
<b><xsl:value-of select="sl:title"/></b> by
<b><xsl:value-of select="sl:artist"/></b> from
<b><xsl:value-of select="sl:album"/></b>
</xsl:for-each>
</xsl:template>
</xsl:transform>
With Slimserver 6.x, the XML format was changed. 🙁 The “sl:song” portion of the for-each statement above needs to be removed.
You can apply this XSLT through a tool such as xsltproc.
I wrote a little shell script which grabs the URL, transforms it, and FTPs it to my server:
#!/bin/sh
# shell script to create HTML of current song playing on Squeezebox,
# and ftp'ing a file containing that information to bob's blog.
wget --quiet --output-document=- http://localhost:9000/xml/status.xml | \
xsltproc --novalid slim-putsong.xsl - > slim-putsong.html
ftp -i -n my.host.name <<EOF
user user password
cd /some/directory/
put slim-putsong.html
bye
EOF
To prevent FTP’ing an unchanged file, precede the ftp line with
diff slim-putsong.html prev-slim-putsong.html > /dev/null ||
Run this script from cron however often you want.
All that remains is to include the HTML file into the web page you want the info to appear on, with something like
<? include 'slim-putsong.html'; ?>