#!/mnt/us/extensions/pianobar/bin/bash
# create variables
while read L; do
k="`echo "$L" | cut -d '=' -f 1`"
v="`echo "$L" | cut -d '=' -f 2`"
export "$k=$v"
done < <(grep -e '^\(title\|artist\|album\|stationName\|songStationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|coverArt\|stationCount\|station[0-9]*\)=' /dev/stdin) # don't overwrite $1...
case "$1" in
       songstart)
       # download cover art
       wget -O /tmp/cover.jpg "$coverArt"

       # display
       WebReaderViewer ///tmp/cover.jpg image &

       # kill it after 30 seconds
       /mnt/us/extensions/pianobar/bin/kpic &

       # download lyrics and display
       curl -s -G --data-urlencode "artist=$artist" --data-urlencode "title=$title" "http://makeitpersonal.co/lyrics"
       [[ -n $songStationName ]] && echo "Now playing: $title by $artist @ $songStationName" ||  echo "Now playing: $title by $artist @ $stationName"
       ;;
       songfinish)

       # display battery life after every 5 songs

       read count < /tmp/count
       (( count += 1 ))
       echo $count > /tmp/count
       [[ $count -eq 5 ]] && { echo 0 > /tmp/count; sleep 10;/mnt/us/extensions/pianobar/bin/bat; }
       ;;
esac