Site Tools


linux:ubuntu:alexamusictitleonwebsite

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
linux:ubuntu:alexamusictitleonwebsite [2019/10/05 13:41] – created lunetikklinux:ubuntu:alexamusictitleonwebsite [2019/11/24 22:11] lunetikk
Line 1: Line 1:
 ====== Display playing music title on website  ====== ====== Display playing music title on website  ======
  
-I wrote my own script based on [[linux:ubuntu:alexaremotecontrol|Alexa Remote Control]] to diplay the current music title played by my Echo device on my 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}} {{:linux:ubuntu:pasted:20191005-132910.png}}
Line 10: Line 10:
  
 The script will create a php file, add this as iframe whereever you want your music to be shown The script will create a php file, add this as iframe whereever you want your music to be shown
 +<code html websnipped.php>
 +<iframe id="frame1" src="audio.php" width="650" height="100"></iframe>
 +</code>
  
 ==== Bashscript ==== ==== Bashscript ====
Line 15: Line 18:
 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. 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.
  
-<code shellscript copyTracks.sh>+<code bash copyTracks.sh>
 #!/bin/bash #!/bin/bash
-/alexa/alexa-remote-control/alexa_remote_control.sh -q > /tmp/audio.txt 
  
 TMPFILE=/tmp/audio.txt TMPFILE=/tmp/audio.txt
 WEBFILE=/var/www/mysite/audio.php WEBFILE=/var/www/mysite/audio.php
  
-OFFLINE=`grep -m1 'message' $TMPFILE | cut -d '"' -f 3 | cut -d ' ' -f 2`+/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` 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` ARTIST=`grep -m1 'subText1' $TMPFILE | cut -d '"' -f 4`
 TITLE=`grep -m1 'title' $TMPFILE | cut -d '"' -f 4` TITLE=`grep -m1 'title' $TMPFILE | cut -d '"' -f 4`
Line 31: Line 37:
 echo "" > $WEBFILE echo "" > $WEBFILE
  
-if [ "$OFFLINE" != "null" ]; then +if [ "$OFFLINE" != "null" ] && [ "$STATENULL" != "null" ]; then 
-echo "<table style="width:100%"><tr><td>" >> $WEBFILE+echo "<table style='width:100%'><col style='width:90%'><col style='width:10%'><tr><td>" >> $WEBFILE
 echo "State: $STATE </br>" >> $WEBFILE echo "State: $STATE </br>" >> $WEBFILE
 echo "Artist: $ARTIST </br>" >> $WEBFILE echo "Artist: $ARTIST </br>" >> $WEBFILE
Line 43: Line 49:
 echo "Iam not listening to music right now..." >> $WEBFILE echo "Iam not listening to music right now..." >> $WEBFILE
 fi fi
 +</code>
 +
 +==== Automation ====
 +
 +The bashscript can be automated via crontab (example runs every 2 minutes).
  
 +<code>
 +*/2 * * * * /alexa-remote-control/copyTrack.sh >/dev/null 2>&1
 </code> </code>
linux/ubuntu/alexamusictitleonwebsite.txt · Last modified: 2021/12/29 00:15 by lunetikk