#!/bin/sh

PORT=$1
SERVER=$2
TARGET=$3

if [ ! `dcop amarok` ];
then
  dcop $PORT Konversation error "Amarok not running."
  exit;
fi

if [ ! $TARGET ]
then
  dcop $PORT Konversation error "Can't write into status view."
else
  TITLE=`dcop amarok player title`
  
  if [[ ${TITLE//[[:space:]]} = "" ]]
  then
    dcop $PORT Konversation error "Nothing's playing in Amarok."
  else  
    ALBUM=`dcop amarok player album`
    ARTIST=`dcop amarok player artist`
    TOTAL=`dcop amarok player trackTotalTime`

    dcop $PORT Konversation say $SERVER "$TARGET" "/me is playing $TITLE by $ARTIST on $ALBUM"
  fi
fi
