"Last Song" Played XMMS Script

My good friend Bandman has this really neat gimmick on his website, where it shows what song he's listening to on his computer at the moment. I always liked it, and he posted a neat little how to for it on the MOVLUG Forums a while back. I decided to take his code, and modify it to use a more secure method, using stored keys and sftp, instead of storing a user name and password in a script.

Step One, you have to create the script to be run on your computer. You can copy and past this one, it seems to do the job. All you need to do is change the last line of the code to your username and your host, whatever they may be. Also, make sure that you change the "cd" command to reflect the folder where you want to upload the file to.

Here's the scipt.

#!/bin/bash

tmpfile="/tmp/lastsong"

if ["$1" == ""];then
exit
else
echo $1 > $tmpfile
echo "
cd public_html
put $tmpfile lastsong.txt
" | sftp user@host.com

Step Two, you have to tell XMMS to use this script. Open XMMS, then goto Preferences. ctrl+p if memory serves and you like shortcuts. Click the tab for "General Plugins" and look for one called "Song Change." If you don't have it, go get it from xmms.org or google or something. I'm not entirely sure where to get it, because I've never seen XMMS NOT have it.

Click configure, and enter this for the command:

/home/user/lastsong.sh "%s"

Just make sure to change the directory to wherever you decided to save your script to. Click ok, then make sure there is a checkmark next to "Enable Plugin" down at the bottom of the screen.

Step Three, make it show up on your website. There's as many ways to add the file this stuff creates to your website as there are people reading this article. I write most of my web stuff in php, so I'm going to assume that you are too. My prefered method is with an "include" statement.

<?php
include("lastsong.txt")
?>

Just be sure to change the filename to whatever your script is saving the file as. Unless you changed it earlier, this will work.

With a little luck and a lot of patience, this should give you a nice little song indicator, much like what I and Bandman, and plenty of others, have on our webpages.