#!/bin/bash

echo `pwd`;

#The following five variables should be set according to your needs.
TEMPFILE="/tmp/lastsong.txt"
USER="user"
PASSWORD="YOURPASSPHRASE"
IP="192.168.0.0"
PORT="8000"

# Source: SpinPapi API; song, artist, and album [and whatever else you want]
CURRENT=`php -f get-spinpapi-data.php`
OLD=`touch $TEMPFILE; cat $TEMPFILE`

if [[ "$CURRENT" != "$OLD" ]]
then 
        # --get makes the data requests in the form of GET, required by
        # SHOUTcast.
        # --silent silences it (duh).
        # --user-agent sets the user agent, which SHOUTcast also requires.
        # --user authenticates the script.
        # --data mode=updinfo puts SHOUTcast into info update mode.
        # --data song=$CURRENT sends the actual data.

	curl --get --silent --user-agent "Mozilla/4.0 (cURL Script)" --user $USER:$PASSWORD --data mode=updinfo --data song=$CURRENT http://$IP:$PORT/admin.cgi
    #Insert copies of last line with different ports for multiple streams	

	rm "$TEMPFILE"
	echo "$CURRENT" >> "$TEMPFILE"
fi
