#!/bin/sh
# Simple Shoutcast track title updater - link this into the song change
# plugin in xmms and you'll be able to run darkice without people moaning ;)
# and without having to bother with the oddcast xmms thing.
#
# Depends on the built-in xmms song-change plugin with the following command:
# '/path/to/shoutcast-titles.sh "%s"'
#
# (c) 2003 Andrew Humphries

#----- Configuration -- (Currently only allows one shoutcast server) ----

# Shoutcast server name
SC_SERVER=fill-in-server-name-here
# Shoutcast server port
SC_PORT=fill-in-port-number-here
# Shoutcast source/admin password
SC_PASSWORD=source-password
# Icecast mount point (uncomment 2nd GET line below, and comment the 1st GET)
ICE_MOUNT=null

#----- Please don't edit below this line --------------------------------
# URL-encode any non-alphanumeric characters for http transmission
SONG_TITLE=$(echo $1 |sed \
-e "s/%/\%25/g" \
-e "s/;/\%3B/g" \
-e "s/\//\%2F/g" \
-e "s/?/\%3F/g" \
-e "s/:/\%3A/g" \
-e "s/@/\%40/g" \
-e "s/&/\%26/g" \
-e "s/=/\%3D/g" \
-e "s/+/\%2B/g" \
-e "s/ /\%20/g" \
-e "s/\"/\%22/g" \
-e "s/#/\%23/g" \
-e "s/</\%3C/g" \
-e "s/>/\%3E/g" \
-e "s/!/\%21/g" \
-e "s/*/\%2A/g" \
-e "s/'/\%27/g" \
-e "s/,/\%2C/g" \
-e "s/)/\%29/g" \
-e "s/(/\%28/g")

if [ "" != "$SONG_TITLE" ]; then
 echo "TITLE:     "$SONG_TITLE
 echo "MEANING:   "$1

 # Check if darkice program is running - i.e. don't update titles if it isn't
 if (ps cax|grep darkice|grep -v grep>/dev/null); then 

# Send title to SHOUTCAST server  (comment out all this for ICECAST)
 (echo "GET /admin.cgi?pass=$SC_PASSWORD&mode=updinfo&song=$SONG_TITLE HTTP/1.0
User-Agent: (Mozilla Compatible)
"|nc $SC_SERVER $SC_PORT)&

# for ICECAST support, uncomment below (but comment the above too)
#(echo "GET /admin.cgi?pass=$SC_PASSWORD&mode=updinfo&mount=$ICE_MOUNT&song=$SONG_TITLE HTTP/1.0
#User-Agent: (Mozilla Compatible)
#"|nc $SC_SERVER $SC_PORT)&

  echo "UPDATE:    Updated track title on "\[$SC_SERVER\] at $(date)
 else
  echo "NO UPDATE: Not updating server this time."
 fi
fi

