#!/bin/bash

MINBIN=/usr/local/minerva/bin
VARLOG=/var/log/minerva

date +"%F %H:%M CMD $0 $*" >>$VARLOG/bearskin/`basename $0` 2>/dev/null

DEVICE=$1
DETAIL=$2
STATUS=

if [ "$DEVICE" == "" ]; then
   DEVICE=default
fi

if [ "`$MINBIN/cdplayer $DEVICE isplaying`" == 1 ]; then
   TRACK=`$MINBIN/cdplayer $DEVICE current`
   TRACK_NAME=`$MINBIN/cdplayer $DEVICE currentname`
   ALBUM=`$MINBIN/cdplayer $DEVICE discname`

   STATUS=$STATUS"The CD is playing track "$TRACK" of "$ALBUM" called "$TRACK_NAME"\n"
else
   if [ "$DETAIL" == "full" ]; then
      STATUS=$STATUS"The CD is not playing\n"
   fi
fi

if [ `$MINBIN/mp3player $DEVICE isplaying` == 1 ]; then
   INFO="The MP3 "`$MINBIN/mp3player $DEVICE current`
   ARTIST="`$MINBIN/mp3player $DEVICE artist`"
   ALBUM="`$MINBIN/mp3player $DEVICE album`"
   if [ "$ARTIST" != "" ]; then
      INFO=$INFO". by ${ARTIST}" 
   fi
   if [ "$ALBUM" != "" ]; then
      INFO=$INFO" from the album ${ALBUM}"
   fi

   STATUS=$STATUS$INFO
   STATUS=$STATUS" is playing"
   if [ "$DETAIL" == "full" ]; then
     STATUS=$STATUS"  Length of "`$MINBIN/mp3player $DEVICE length`"\n"
     STATUS=$STATUS"  The full path is "`$MINBIN/mp3player $DEVICE fullname`"\n"
   fi
else
   if [ "$DETAIL" == "full" ]; then
      STATUS=$STATUS"The MP3 player is not playing\n"
   fi
fi

if [ "`pgrep mpg123`" != "" ]; then
   if [ -f $VARLOG/mpg123.trk ]; then
     STATUS=$STATUS`cat $VARLOG/mpg123.trk`
   fi
else
   if [ "$DETAIL" == "full" ]; then
      STATUS=$STATUS"The MPG movie player is not playing"
   fi
fi

if [ "$STATUS" == "" ]; then
   echo No media is playing
else
   echo -e $STATUS
fi

