Site Tools


linux:ubuntu:alexamusictitleonwebsite

This is an old revision of the document!


Display playing music title on website

I wrote my own script based on Alexa Remote Control to display the current music title played by my Echo device on my website

Script

Webcode

The script will create a php file, add this as iframe whereever you want your music to be shown

<iframe id="frame1" src="audio.php" width="650" height="100"></iframe>

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`
STATE=`grep -m1 'state' $TMPFILE | cut -d '"' -f 4`
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" ]; then
echo "<table style="width:100%"><tr><td>" >> $WEBFILE
echo "State: $STATE </br>" >> $WEBFILE
echo "Artist: $ARTIST </br>" >> $WEBFILE
echo "Title: $TITLE </br>" >> $WEBFILE
echo "Album: $ALBUM" >> $WEBFILE
echo "</td><td>" >> $WEBFILE
echo "<img src='$IMG' alt='albumcover' style='width:64px;height:64px;'>" >> $WEBFILE
echo "</td></tr></table>" >> $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

linux/ubuntu/alexamusictitleonwebsite.1570276024.txt.gz · Last modified: 2019/10/05 13:47 by lunetikk