#!/bin/bash
#
#Change this pipe to reflect yours
pipe="/var/tmp/g15fifo"

sec2time ()
{
    min=`expr $1 / 60`
    sec=`expr $1 % 60`

     SEC2TIME=`printf "%d:%02d" $min $sec`
}

remtime ()
{
    cur=$1
    total=$2

    rem=`expr $total - $cur`

    sec2time $rem
    REMTIME=$SEC2TIME
}


while /bin/true;
do
    # test whether Amarok is running and playing something
    is_playing=`dcop amarok player isPlaying 2> /dev/null`

    if [ $? -eq 0 ]; then
        if [ "$is_playing" == "false" ]; then
            line="TL \"\" \"\" \".. Amarok paused ..\""
        else
            title=`dcop amarok player title`
            artist=`dcop amarok player artist`
            currentTime=`dcop amarok player trackCurrentTime`
            totalTime=`dcop amarok player trackTotalTime`

            remtime $currentTime $totalTime
            ctime=$REMTIME
            sec2time $totalTime
            ttime=$SEC2TIME

            line="TL \"$title\" \"$artist\" \"$ctime - $ttime\""
        fi
    else
        line="TL \"\" \"\" \"... Not running ...\""
    fi

    echo $line > $pipe
    sleep 5
done;


