====== Display playing music title on website ====== I wrote my own script based on [[linux:ubuntu:alexaremotecontrol|Alexa Remote Control]] to display the current music title played by my Echo device on my website. Check my updated version [[linux:ubuntu:alexamusictodatabase|here]] {{:linux:ubuntu:pasted:20191005-132910.png}} **Update 2021-12-29:** Amazon redesigned the output via alexa.amazon.de, the string for "album" is now always empty, so can only get the state, artist and title at the moment. If you use Spotify you might want to check out my Spotify script. I also thought about a way to get an album via artist and track out of a musicdatabase (like musicbrainz) but I dont know yet if this will work. ===== Script ===== ==== Webcode ==== The script will create a php file, add this as iframe whereever you want your music to be shown ==== Bashscript ==== The script will execute the the "Alexa Remote Control" with "-q / query queue" to get the current tracks, then cuts out the playing song with all its info and albumcover to pipe it into the php file. #!/bin/bash TMPFILE=/tmp/audio.txt WEBFILE=/var/www/mysite/audio.php /alexa-remote-control/alexa_remote_control.sh -q > $TMPFILE #OFFLINE=`grep -m1 'message' $TMPFILE | cut -d '"' -f 3 | cut -d ' ' -f 2` OFFLINE=`grep -m1 'message' $TMPFILE | awk 'BEGIN{FS=" "}{gsub(",",""); print $2}'` STATE=`grep -m1 'state' $TMPFILE | cut -d '"' -f 4` STATENULL=`grep -m1 'state' /tmp/audio.txt | awk 'BEGIN{FS=" "}{gsub(",",""); print $2}'` ARTIST=`grep -m1 'subText1' $TMPFILE | cut -d '"' -f 4` TITLE=`grep -m1 'title' $TMPFILE | cut -d '"' -f 4` ALBUM=`grep -m1 'subText2' $TMPFILE | cut -d '"' -f 4` IMG=`grep -m1 'url' $TMPFILE | cut -d '"' -f 4` echo "" > $WEBFILE if [ "$OFFLINE" != "null" ] && [ "$STATENULL" != "null" ]; then echo "
" >> $WEBFILE echo "State: $STATE
" >> $WEBFILE echo "Artist: $ARTIST
" >> $WEBFILE echo "Title: $TITLE
" >> $WEBFILE echo "Album: $ALBUM" >> $WEBFILE echo "
" >> $WEBFILE echo "albumcover" >> $WEBFILE echo "
" >> $WEBFILE else echo "Iam not listening to music right now..." >> $WEBFILE fi
==== Automation ==== The bashscript can be automated via crontab (example runs every 2 minutes). */2 * * * * /alexa-remote-control/copyTrack.sh >/dev/null 2>&1