#!/bin/bash PLAYER="00:04:20:xx:xx:xx" if [ "$1" == "work" ]; then PLAYER="127.0.0.1" fi XML="http://localhost:9000/xml/status_header.xml?player=${PLAYER}" TMP=`mktemp /tmp/curtrack.XXXXXX` || die "couldn't create $TMPDIR" wget -O - -q "$XML" | sed -e 's#xmlns="http://www.slimdevices.com/slimserver/xml"##' > $TMP TITLE=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "title" $TMP` ALBUMARTIST=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -c "albumartist" $TMP | sed -e "s/<[^>]*>/,/g" -e 's/^,//' -e 's/,$//' -e 's/,,/,/g' -e 's/,/ \& /g'` ARTIST=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -c "artist" $TMP | sed -e "s/<[^>]*>/,/g" -e 's/^,//' -e 's/,$//' -e 's/,,/,/g' -e 's/,/ \& /g'` if [ ! "$ARTIST" ]; then ARTIST="$ALBUMARTIST" fi if [ "$ALBUMARTIST" != "" ] && [ "$ALBUMARTIST" != "$ARTIST" ]; then ARTISTSTR="$ALBUMARTIST ($ARTIST)" else ARTISTSTR="$ARTIST" fi ALBUM=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "album" $TMP` TRACKNO=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "track" $TMP` GENRE=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "genre" $TMP` YEAR=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "year" $TMP` PLAYEDSECS=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "seconds_elapsed" $TMP` TOTALSECS=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "seconds_total" $TMP` DURATION=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "duration" $TMP` BITRATE=`xmlstarlet sel -t -m "status" -m "player_status" -m "current_song" -v "bitrate" $TMP` BITRATEK=`echo "$BITRATE 1000 /" | rpncalc 2>/dev/null | awk '{print $2;}'` PERCENTDONE=`echo "$PLAYEDSECS 100 * $TOTALSECS /" | rpncalc 2>/dev/null | awk '{print $2;}'` echo "np: ${ARTISTSTR} - ${ALBUM} - ${TITLE} [${YEAR}|${PERCENTDONE}% of ${DURATION}|${BITRATEK}kbps]" | sed -e 's#\&#\&#g' rm -f $TMP