#!/bin/sh
if [ `dcop amarok player isPlaying` = false ]; then
	echo "Not playing anything." >&2
	exit 1
fi

ARTIST=`dcop amarok player artist`
TITLE=`dcop amarok player title`
TRACK=`dcop amarok player track`
ALBUM=`dcop amarok player album`
TOTALTIME=`dcop amarok player totalTime`
CURRENTTIME=`dcop amarok player currentTime`
GENRE=`dcop amarok player genre`
YEAR=`dcop amarok player year`
COMMENT=`dcop amarok player comment`
BITRATE=`dcop amarok player bitrate`
SAMPLERATE=`dcop amarok player sampleRate`
SCORE=`dcop amarok player score`
URI=`dcop amarok player encodedURL`

if [ -z "$ARTIST" ]; then
	ARTIST="Unknown"
fi

if [ -z "$ALBUM" ]; then
	ALBUM="Unknown Album"
fi

if [ ! -z "$YEAR" -a "$YEAR" != 0 ]; then
	YEARTEXT=", $YEAR"
fi

if [ ! -z "$GENRE" ]; then
	GENRETEXT="/$GENRE"
fi

if [ ! -z "$TRACK" -a "$TRACK" != 0 ]; then
	TRACKTEXT=", Track $TRACK"
fi

if [ ! -z "$TOTALTIME" ]; then
	TOTALTEXT="/$TOTALTIME"
fi

RATE_KHZ=`echo "scale=1;$SAMPLERATE / 1000" | bc`
EXTENSION=`echo "$URI" | tr '.' '\n' | tail -n 1`

dcop amarok playlist popupMessage "Current info fetched by script (ca)"
printf "[aK] %s: %s (%s%s%s%s) [%s] %.1fkhz.%s.%s%s\n" "$ARTIST" "$TITLE" "$ALBUM" "$YEARTEXT" "$GENRETEXT" "$TRACKTEXT" "$EXTENSION" "$RATE_KHZ" "$BITRATE" "$CURRENTTIME" "$TOTALTEXT"
