From 7ec60e720d2bf825eb57f9920cc9144b95226473 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Jan 2019 00:07:58 +0100 Subject: [PATCH 1/3] 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! From 17697ab561d45ec94f5c6bbf8aff2a6550e0dd9b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Jan 2019 00:08:29 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 671f21b..7101a43 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ control Amazon Alexa from command Line ``` -alexa-remote-control [-d |ALL] -e > | +alexa-remote-control [-d |ALL] -e > | -b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -r <"station name"|stationid> | -s | -t | -u | -v | -w | -i | -p | -P | -S | -a | -l | -h | From 236bc722d1a2896cea2578737327f01231d409ad Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Jan 2019 00:09:03 +0100 Subject: [PATCH 3/3] Delete alexa-pandora.sh --- alexa-pandora.sh | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 alexa-pandora.sh diff --git a/alexa-pandora.sh b/alexa-pandora.sh deleted file mode 100644 index ec4d5b2..0000000 --- a/alexa-pandora.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -DEVICENUMBER='G090LF0961234582' -DEVICETYPE='A3S5BH212345YF' -CUSTOMERID='A2C7IGO12345PS' -COOKIE='Cookie: x-amzn-dat-gui-client-v=1.24.111.0; aws-target-static-id=14712345678-839972; aws-session-id=168-0412369-4130549; aws-session-id-time=2106123471l; aws-x-main=PgpqvER9Wibauhf4zfSDri12lBILfMnk; aws-at-main=Atza|IwEBIAFsntUWFc_PZvFde5drDzPNXXXXXXXXXHPqI53aQNl-Fu83eAMUsFJmMtamv_4mL123h6N82lqq8OHA8SKgh44X2MZwTguXNcUvd0-RVQyayT2lQ86JjoXvJrlMlrZIs7kJLWBryCGJEXXXXXXXXXXFJQpHhnGeC72ljNT_nVObL_wZoYhMFHVMXGiYjFyrb-QcjYY-I3ar-Q-kLAmzZYQIKU-mZ8GChNefKuG_x4ZZ2A06XXXXXXXXXOhX9w94vgmn2y3Qr9Q0rEi8K--UoFuTQ54GArubNsofNLh4U2dov8D7Gs3GoW6Hp2zEwt7cyumpRR_vceAz3aUjskoNKXsgDfpPZrebl-0R4bC6BfIasyoDOX9XXXXXXXXjRihKSxf4gs79p1ExYBmaBOX6glBrsKRqOXfk6Vh87_96uQ; aws-userInfo=%7B%22arn%22%3A%22arn%3Aaws%3Aiam%3A%3A314911114493%3Aroot%22%2C%22alias%22%3A%22%22%2C%22username%22%3A%22MeinUser%2520Name%22%2C%22keybase%22%3A%22dhVv%2Fmb%2BJyCH%2BJA6zwfighlgs5jc0W0mVYXkLBkb77M%5Cu003d%22%2C%22issuer%22%3A%22https%3A%2F%2Fwww.amazon.com%2Fap%2Fsignin%22%7D; __utmv=191231197.PgpqvER9Wibauhf4zfSDXXXXXXXXk; s_dslv=1475471239073; regStatus=registered; aws-target-visitor-id=1475445653051-715340.26_4; aws-target-data=%7B%22support%22%3A%221%22%7D; s_pers=%20s_ev15%3D%255B%255B%2527Typed%252FBookmarked%2527%252C%25212375474893114%2527%255D%255D%7C1632141293114%3B%20s_fid%3D0523A63XXXXXXXXX3C9679E640DA3570%7C1538547024210%3B%20s_dl%3D1%7C1475481765932%3B%20gpv_page%3Dno%2520value%7C1475481765939%3B; session-id=151-3512347-8293901; session-id-time=2106212731l; s_fid=71689F1234D6D238-299FD69294EFC3C1; s_nr=1475492764173-Repeat; aws-ubid-main=151-3388123-1263140; aws-session-token="lprp9YroXXXXXXXXXz5EFfSaPt96R0oSBWL2dR/AGFdlmk4QwRcVPXXXXXXXrmZ5kfHBdNwvSWWMKTnYU0pB5CE2XXXXXXUk6SIuaQYti17ZQ8B3NGwyCKNs7Lil+kz9qonZS5/cwtmrWHCe7SGx/QmPXXXXXXX89WbiV2xwTRkhVw6hTjO+8WUOXXXXXXXXi8MaR196v+Ewflx7dd3ouTVtY+hbJE4XSs="; __utma=194891197.1975555581.1444474071.1475495555.1475555580.5; __utmz=194555597.1475555680.5.2.utmccn=(referral)|utmcsr=console.aws.amazon.com|utmcct=/cloudwatch/home|utmcmd=referral; ubid-main=152-8362434-2710144; session-token="Y2Eoqs81+wIbanI7mPonK9t7gFvH7ZdTG2OxCZB3orqTILNY5ev4cFBWiSPTl2u8nFNXNmwtFP6RxnPBTunkdbHfpos8WYYOX7gEF52wnn5J3SknsvO99+MAT5GeyMR4JRa+ZOX+DcnIt8xtgYY2sSaEZ3JspjrQF+M9PUkuT9D4aYbZGRNa1BkFvoOt8Kettr9xxS/ODPfXEaE6xJr7qyPv0IQ3K6e+FbfGk3AWypY="; x-main=4r7ZrJJV4BT1R2sWn2W4NpiXZm9RSJLD; at-main=Atza|IwEEEEE4EikDns-CTHnGRqXXXcnnaij75AfcF1-XOBvphYTp_ATJHu6f0vDgMI7B1ApWn51cP6bqvG-XXXXeTPD8t7jl5El_FdhlYn3mmtn476FfnI5E7anoZNSKLyE-jauNJssBeGUjsSd0z8746mujYcJbKQsMMVVUlxcu4jXXxXXYcC4GasQyvOIp92wY-TPKAOys8NV0-yXH4xTGBzgJ0zzJa5JvyRz2v0x3fijvyXXXXXXSDhZtaDOZ6GOQlYrsUmudsorYUcUT52x0EYavXXXXX92cmgkMUzuTxppV1SpLk2Wk63LQQkCCZLs6_HWlnX2Saf0zgc13BdUehhSBiYHzJJeg1Ys7g68GLG5IuSGvyGe8ebmcN9KUDdD2CwphaeW34iy6dVKGbUpJ3GKVlz; sess-at-main="eSHstcxm5Krki5T1EAcQyk9XXXXXXqMbqcJqDBaA="; csrf=-2012345694' -CSRF='csrf: -2081123454' - -SENDER=$1 -#Check if parameter is empty -if [ -z "$SENDER" ]; -then - echo "Station Empty - use ./alexa-pandora.sh 3409818391113140449" - exit -fi - -STATION='{"stationToken":"'$SENDER'","createStation":false}' -echo "${STATION}" - -#pandora -URL='https://pitangui.amazon.com/api/amber/queue-and-play?deviceSerialNumber='$DEVICENUMBER'&deviceType='$DEVICETYPE'&mediaOwnerCustomerId='$CUSTOMERID -curl $URL \ --H "$COOKIE" \ --H "$CSRF" \ ---data "${STATION}" \ ---compressed -