From 7ec60e720d2bf825eb57f9920cc9144b95226473 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Jan 2019 00:07:58 +0100 Subject: [PATCH] repeat command and environment variable parsing * added repeat command * added environment variable parsing --- alexa_remote_control.sh | 49 ++++++++++++++++++++++++----------- alexa_remote_control_plain.sh | 49 ++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/alexa_remote_control.sh b/alexa_remote_control.sh index 6abdad9..4e81e58 100644 --- a/alexa_remote_control.sh +++ b/alexa_remote_control.sh @@ -34,7 +34,8 @@ # https://github.com/openhab/openhab2-addons/tree/master/addons/binding/org.openhab.binding.amazonechocontrol # (thanks to Ralf Otto for implementing this feature in this script) # 2018-06-13: v0.10a added album play of imported library -# 2018-06-18: v0.10b added Alex routine execution +# 2018-06-18: v0.10b added Alexa routine execution +# 2019-01-22: v0.11 added repeat command, added environment variable parsing # ### # @@ -45,35 +46,50 @@ # ########################################## -EMAIL='amazon_account@email.address' -PASSWORD='Very_Secret_Amazon_Account_Password' +SET_EMAIL='amazon_account@email.address' +SET_PASSWORD='Very_Secret_Amazon_Account_Password' -LANGUAGE="de-DE" -#LANGUAGE="en-US" +SET_LANGUAGE="de-DE" +#SET_LANGUAGE="en-US" -AMAZON='amazon.de' -#AMAZON='amazon.com' +SET_AMAZON='amazon.de' +#SET_AMAZON='amazon.com' -ALEXA='layla.amazon.de' -#ALEXA='pitangui.amazon.com' +SET_ALEXA='alexa.amazon.de' +#SET_ALEXA='pitangui.amazon.com' # cURL binary -CURL='/usr/bin/curl' +SET_CURL='/usr/bin/curl' # cURL options # -k : if your cURL cannot verify CA certificates, you'll have to trust any # --compressed : if your cURL was compiled with libz you may use compression # --http1.1 : cURL defaults to HTTP/2 on HTTPS connections if available -OPTS='--compressed --http1.1' -#OPTS='-k --compressed --http1.1' +SET_OPTS='--compressed --http1.1' +#SET_OPTS='-k --compressed --http1.1' # browser identity -BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0' +SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:1.0) bash-script/1.0' +#SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0' + +# tmp path +SET_TMP="/tmp" ########################################### # nothing to configure below here # -TMP="/tmp" + +# retrieving environment variables if any are set +EMAIL=${EMAIL:-$SET_EMAIL} +PASSWORD=${PASSWORD:-$SET_PASSWORD} +AMAZON=${AMAZON:-$SET_AMAZON} +ALEXA=${ALEXA:-$SET_ALEXA} +LANGUAGE=${LANGUAGE:-$SET_LANGUAGE} +BROWSER=${BROWSER:-$SET_BROWSER} +CURL=${CURL:-$SET_CURL} +OPTS=${OPTS:-$SET_OPTS} +TMP=${TMP:-$SET_TMP} + COOKIE="${TMP}/.alexa.cookie" DEVLIST="${TMP}/.alexa.devicelist.json" @@ -102,7 +118,7 @@ LASTALEXA="" usage() { - echo "$0 [-d |ALL] -e > |" + echo "$0 [-d |ALL] -e > |" echo " -b [list|<\"AA:BB:CC:DD:EE:FF\">] | -q | -r <\"station name\"|stationid> |" echo " -s | -t | -u | -v | -w |" echo " -i | -p | -P | -S | -a | -m [device_1 .. device_X] | -lastalexa | -l | -h" @@ -296,6 +312,9 @@ case "$COMMAND" in shuffle) COMMAND='{"type":"ShuffleCommand","shuffle":"true"}' ;; + repeat) + COMMAND='{"type":"RepeatCommand","repeat":true}' + ;; vol:*) VOL=${COMMAND##*:} # volume as integer! diff --git a/alexa_remote_control_plain.sh b/alexa_remote_control_plain.sh index 1ccfffc..f715aa4 100644 --- a/alexa_remote_control_plain.sh +++ b/alexa_remote_control_plain.sh @@ -3,7 +3,7 @@ # Amazon Alexa Remote Control (PLAIN shell) # alex(at)loetzimmer.de # -# 2018-06-18: v0.10b (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html) +# 2019-01-22: v0.11 (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html) # ### # @@ -13,35 +13,51 @@ # ########################################## -EMAIL='amazon_account@email.address' -PASSWORD='Very_Secret_Amazon_Account_Password' -LANGUAGE="de-DE" -#LANGUAGE="en-US" +SET_EMAIL='amazon_account@email.address' +SET_PASSWORD='Very_Secret_Amazon_Account_Password' -AMAZON='amazon.de' -#AMAZON='amazon.com' +SET_LANGUAGE="de-DE" +#SET_LANGUAGE="en-US" -ALEXA='layla.amazon.de' -#ALEXA='pitangui.amazon.com' +SET_AMAZON='amazon.de' +#SET_AMAZON='amazon.com' + +SET_ALEXA='alexa.amazon.de' +#SET_ALEXA='pitangui.amazon.com' # cURL binary -CURL='/usr/bin/curl' +SET_CURL='/usr/bin/curl' # cURL options # -k : if your cURL cannot verify CA certificates, you'll have to trust any # --compressed : if your cURL was compiled with libz you may use compression # --http1.1 : cURL defaults to HTTP/2 on HTTPS connections if available -OPTS='--compressed --http1.1' -#OPTS='-k --compressed --http1.1' +SET_OPTS='--compressed --http1.1' +#SET_OPTS='-k --compressed --http1.1' # browser identity -BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0' +SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:1.0) bash-script/1.0' +#SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0' + +# tmp path +SET_TMP="/tmp" ########################################### # nothing to configure below here # -TMP="/tmp" + +# retrieving environment variables if any are set +EMAIL=${EMAIL:-$SET_EMAIL} +PASSWORD=${PASSWORD:-$SET_PASSWORD} +AMAZON=${AMAZON:-$SET_AMAZON} +ALEXA=${ALEXA:-$SET_ALEXA} +LANGUAGE=${LANGUAGE:-$SET_LANGUAGE} +BROWSER=${BROWSER:-$SET_BROWSER} +CURL=${CURL:-$SET_CURL} +OPTS=${OPTS:-$SET_OPTS} +TMP=${TMP:-$SET_TMP} + COOKIE="${TMP}/.alexa.cookie" DEVLIST="${TMP}/.alexa.devicelist.json" DEVTXT="${TMP}/.alexa.devicelist.txt" @@ -69,7 +85,7 @@ LASTALEXA="" usage() { - echo "$0 [-d |ALL] -e > |" + echo "$0 [-d |ALL] -e > |" echo " -b [list|<\"AA:BB:CC:DD:EE:FF\">] | -q | -r <\"station name\"|stationid> |" echo " -s | -t | -u | -v | -w |" echo " -a | -m [device_1 .. device_X] | -lastalexa | -l | -h" @@ -247,6 +263,9 @@ case "$COMMAND" in shuffle) COMMAND='{"type":"ShuffleCommand","shuffle":"true"}' ;; + repeat) + COMMAND='{"type":"RepeatCommand","repeat":true}' + ;; vol:*) VOL=${COMMAND##*:} # volume as integer!