HOST=localhost
PORT=12002
ROOT=control

setplaylist () {
	wget --post-file $1 http://$HOST:$PORT/$ROOT/setplaylist -O /dev/null
}

xmlifyplaylist () {
        filename=$1
        echo '<tracks>' > $filename
        cat /dev/stdin | perl -pe 's{&}{&amp;}g; s{<}{&lt;}g; s{>}{&gt;}g; s{^(.*)$}{<track>$1</track>}g' >> $filename
        echo '</tracks>' >> $filename
}

pipesetplaylist () {
        filename=`tempfile`
        xmlifyplaylist $filename
        wget --post-file $filename http://$HOST:$PORT/$ROOT/setplaylist -O /dev/null
        rm $filename
}

getplaylist () {
	wget -q http://$HOST:$PORT/$ROOT/getplaylist -O -
}

nexttrack () {
	wget --post-data "" http://$HOST:$PORT/$ROOT/next -O /dev/null
}

prevtrack () {
	wget --post-data "" http://$HOST:$PORT/$ROOT/previous -O /dev/null
}

appendplaylist() {
	wget --post-file $1 http://$HOST:$PORT/$ROOT/append -O /dev/null
}

pipeappendplaylist() {
        filename=`tempfile`
        xmlifyplaylist $filename
        wget --post-file $filename http://$HOST:$PORT/$ROOT/append -O /dev/null
        rm $filename
}

insertplaylist() {
	wget --post-file $1 http://$HOST:$PORT/$ROOT/insert -O /dev/null
}

pipeinsertplaylist() {
        filename=`tempfile`
        xmlifyplaylist $filename
        wget --post-file $filename http://$HOST:$PORT/$ROOT/insert -O /dev/null
        rm $filename
}

position() {
        wget --post-data "<position>$1</position>" http://$HOST:$PORT/$ROOT/position -O /dev/null
}


