mirror of
https://github.com/thorsten-gehrig/alexa-remote-control.git
synced 2024-11-22 08:49:02 +01:00
added "-d ALL" to the plain version
This commit is contained in:
parent
308d38238d
commit
d63f23855a
@ -3,7 +3,7 @@
|
|||||||
# Amazon Alexa Remote Control (PLAIN shell)
|
# Amazon Alexa Remote Control (PLAIN shell)
|
||||||
# alex(at)loetzimmer.de
|
# alex(at)loetzimmer.de
|
||||||
#
|
#
|
||||||
# 2019-02-03: v0.11a (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html)
|
# 2019-02-10: v0.12 (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html)
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
@ -38,7 +38,7 @@ SET_OPTS='--compressed --http1.1'
|
|||||||
|
|
||||||
# browser identity
|
# browser identity
|
||||||
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:1.0) bash-script/1.0'
|
||||||
#SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0'
|
#SET_BROWSER='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'
|
||||||
|
|
||||||
# tmp path
|
# tmp path
|
||||||
SET_TMP="/tmp"
|
SET_TMP="/tmp"
|
||||||
@ -61,6 +61,7 @@ TMP=${TMP:-$SET_TMP}
|
|||||||
COOKIE="${TMP}/.alexa.cookie"
|
COOKIE="${TMP}/.alexa.cookie"
|
||||||
DEVLIST="${TMP}/.alexa.devicelist.json"
|
DEVLIST="${TMP}/.alexa.devicelist.json"
|
||||||
DEVTXT="${TMP}/.alexa.devicelist.txt"
|
DEVTXT="${TMP}/.alexa.devicelist.txt"
|
||||||
|
DEVALL="${TMP}/.alexa.devicelist.all"
|
||||||
|
|
||||||
GUIVERSION=0
|
GUIVERSION=0
|
||||||
|
|
||||||
@ -92,8 +93,8 @@ usage()
|
|||||||
echo
|
echo
|
||||||
echo " -e : run command, additional SEQUENCECMDs:"
|
echo " -e : run command, additional SEQUENCECMDs:"
|
||||||
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>'"
|
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>'"
|
||||||
echo " -q : query queue"
|
|
||||||
echo " -b : connect/disconnect/list bluetooth device"
|
echo " -b : connect/disconnect/list bluetooth device"
|
||||||
|
echo " -q : query queue"
|
||||||
echo " -r : play tunein radio"
|
echo " -r : play tunein radio"
|
||||||
echo " -s : play library track/library album"
|
echo " -s : play library track/library album"
|
||||||
echo " -t : play Prime playlist"
|
echo " -t : play Prime playlist"
|
||||||
@ -324,6 +325,7 @@ log_in()
|
|||||||
|
|
||||||
rm -f ${DEVLIST}
|
rm -f ${DEVLIST}
|
||||||
rm -f ${DEVTXT}
|
rm -f ${DEVTXT}
|
||||||
|
rm -f ${DEVALL}
|
||||||
rm -f ${COOKIE}
|
rm -f ${COOKIE}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -388,6 +390,28 @@ ${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep
|
|||||||
if [ ! -f ${DEVTXT} ] ; then
|
if [ ! -f ${DEVTXT} ] ; then
|
||||||
cat ${DEVLIST}| sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' > ${DEVTXT}
|
cat ${DEVLIST}| sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' > ${DEVTXT}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# create a file that contains valid device names for the "ALL" device
|
||||||
|
ATTR="accountName"
|
||||||
|
NAME=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
|
ATTR="deviceFamily"
|
||||||
|
FAMILY=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
|
IDX=0
|
||||||
|
for N in $NAME ; do
|
||||||
|
C=0
|
||||||
|
for F in $FAMILY ; do
|
||||||
|
if [ $C -eq $IDX ] ; then
|
||||||
|
if [ "$F" = "WHA" -o "$F" = "ECHO" -o "$F" = "KNIGHT" -o "$F" = "ROOK" ] ; then
|
||||||
|
echo ${N} >> ${DEVALL}
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
C=$((C+1))
|
||||||
|
done
|
||||||
|
IDX=$((IDX+1))
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
check_status()
|
check_status()
|
||||||
@ -413,35 +437,35 @@ check_status()
|
|||||||
set_var()
|
set_var()
|
||||||
{
|
{
|
||||||
ATTR="accountName"
|
ATTR="accountName"
|
||||||
NAME=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g'`
|
NAME=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
ATTR="deviceType"
|
ATTR="deviceType"
|
||||||
TYPE=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g'`
|
TYPE=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
ATTR="serialNumber"
|
ATTR="serialNumber"
|
||||||
SERIAL=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g'`
|
SERIAL=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
# ATTR="deviceOwnerCustomerId"
|
# ATTR="deviceOwnerCustomerId"
|
||||||
# MEDIAID=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g'`
|
# MEDIAID=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
ATTR="deviceFamily"
|
ATTR="deviceFamily"
|
||||||
FAMILY=`grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g'`
|
FAMILY=$(grep ${ATTR}\| ${DEVTXT} | sed "s/^.*${ATTR}|//" | sed 's/ /_/g')
|
||||||
|
|
||||||
|
|
||||||
if [ -z "${DEVICE}" ] ; then
|
if [ -z "${DEVICE}" ] ; then
|
||||||
# if no device was supplied, use the first Echo(dot) in device list
|
# if no device was supplied, use the first Echo(dot) in device list
|
||||||
IDX=0
|
IDX=0
|
||||||
for I in $FAMILY ; do
|
for F in $FAMILY ; do
|
||||||
if [ "$I" = "ECHO" -o "$I" = "KNIGHT" -o "$I" = "ROOK" ] ; then
|
if [ "$F" = "ECHO" -o "$F" = "KNIGHT" -o "$F" = "ROOK" ] ; then
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
IDX=$((IDX+1))
|
IDX=$((IDX+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
C=0
|
C=0
|
||||||
for I in $NAME ; do
|
for N in $NAME ; do
|
||||||
if [ $C -eq $IDX ] ; then
|
if [ $C -eq $IDX ] ; then
|
||||||
DEVICE=$I
|
DEVICE=$N
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
C=$((C+1))
|
C=$((C+1))
|
||||||
@ -451,8 +475,8 @@ set_var()
|
|||||||
else
|
else
|
||||||
DEVICE=`echo $DEVICE | sed 's/ /_/g'`
|
DEVICE=`echo $DEVICE | sed 's/ /_/g'`
|
||||||
IDX=0
|
IDX=0
|
||||||
for I in $NAME ; do
|
for N in $NAME ; do
|
||||||
if [ "$I" = "$DEVICE" ] ; then
|
if [ "$N" = "$DEVICE" ] ; then
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
IDX=$((IDX+1))
|
IDX=$((IDX+1))
|
||||||
@ -471,18 +495,18 @@ set_var()
|
|||||||
# done
|
# done
|
||||||
|
|
||||||
C=0
|
C=0
|
||||||
for I in $TYPE ; do
|
for T in $TYPE ; do
|
||||||
if [ $C -eq $IDX ] ; then
|
if [ $C -eq $IDX ] ; then
|
||||||
DEVICETYPE=$I
|
DEVICETYPE=$T
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
C=$((C+1))
|
C=$((C+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
C=0
|
C=0
|
||||||
for I in $SERIAL ; do
|
for S in $SERIAL ; do
|
||||||
if [ $C -eq $IDX ] ; then
|
if [ $C -eq $IDX ] ; then
|
||||||
DEVICESERIALNUMBER=$I
|
DEVICESERIALNUMBER=$S
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
C=$((C+1))
|
C=$((C+1))
|
||||||
@ -704,6 +728,7 @@ ${CURL} ${OPTS} -s -c ${COOKIE} -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Con
|
|||||||
|
|
||||||
rm -f ${DEVLIST}
|
rm -f ${DEVLIST}
|
||||||
rm -f ${DEVTXT}
|
rm -f ${DEVTXT}
|
||||||
|
rm -f ${DEVALL}
|
||||||
rm -f ${COOKIE}
|
rm -f ${COOKIE}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,7 +754,7 @@ if [ $? -eq 0 ] ; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f ${DEVTXT} ] ; then
|
if [ ! -f ${DEVTXT} -o ! -f ${DEVALL} ] ; then
|
||||||
echo "device list does not exist. downloading ..."
|
echo "device list does not exist. downloading ..."
|
||||||
get_devlist
|
get_devlist
|
||||||
if [ ! -f ${DEVTXT} ] ; then
|
if [ ! -f ${DEVTXT} ] ; then
|
||||||
@ -738,11 +763,25 @@ if [ ! -f ${DEVTXT} ] ; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$COMMAND" ] ; then
|
if [ -n "$COMMAND" -o -n "$QUEUE" ] ; then
|
||||||
set_var
|
if [ "${DEVICE}" = "ALL" ] ; then
|
||||||
if [ -n "$COMMAND" ] ; then
|
while IFS= read -r DEVICE ; do
|
||||||
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
|
set_var
|
||||||
run_cmd
|
if [ -n "$COMMAND" ] ; then
|
||||||
|
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
|
||||||
|
run_cmd
|
||||||
|
# in order to prevent a "Rate exceeded" we need to delay the command
|
||||||
|
sleep 1
|
||||||
|
else
|
||||||
|
echo "queue info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
|
||||||
|
show_queue
|
||||||
|
fi
|
||||||
|
done < ${DEVALL}
|
||||||
|
else
|
||||||
|
if [ -n "$COMMAND" ] ; then
|
||||||
|
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
|
||||||
|
run_cmd
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ -n "$LEMUR" ] ; then
|
elif [ -n "$LEMUR" ] ; then
|
||||||
DEVICE="${LEMUR}"
|
DEVICE="${LEMUR}"
|
||||||
@ -757,17 +796,28 @@ elif [ -n "$LEMUR" ] ; then
|
|||||||
create_multiroom
|
create_multiroom
|
||||||
fi
|
fi
|
||||||
rm -f ${DEVLIST}
|
rm -f ${DEVLIST}
|
||||||
|
rm -f ${DEVALL}
|
||||||
rm -f ${DEVTXT}
|
rm -f ${DEVTXT}
|
||||||
get_devlist
|
get_devlist
|
||||||
elif [ -n "$BLUETOOTH" ] ; then
|
elif [ -n "$BLUETOOTH" ] ; then
|
||||||
set_var
|
if [ "$BLUETOOTH" = "list" -o "$BLUETOOTH" = "List" -o "$BLUETOOTH" = "LIST" ] ; then
|
||||||
if [ "$BLUETOOTH" = "null" ] ; then
|
if [ "${DEVICE}" = "ALL" ] ; then
|
||||||
|
while IFS= read -r DEVICE ; do
|
||||||
|
set_var
|
||||||
|
echo "bluetooth api list:"
|
||||||
|
list_bluetooth
|
||||||
|
done < ${DEVALL}
|
||||||
|
else
|
||||||
|
set_var
|
||||||
|
echo "bluetooth api list:"
|
||||||
|
list_bluetooth
|
||||||
|
fi
|
||||||
|
elif [ "$BLUETOOTH" = "null" ] ; then
|
||||||
|
set_var
|
||||||
echo "disconnecting dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} from bluetooth"
|
echo "disconnecting dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} from bluetooth"
|
||||||
disconnect_bluetooth
|
disconnect_bluetooth
|
||||||
elif [ "$BLUETOOTH" = "list" -o "$BLUETOOTH" = "List" -o "$BLUETOOTH" = "LIST" ] ; then
|
|
||||||
echo "bluetooth api list:"
|
|
||||||
list_bluetooth
|
|
||||||
else
|
else
|
||||||
|
set_var
|
||||||
echo "connecting dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} to bluetooth device:${BLUETOOTH}"
|
echo "connecting dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} to bluetooth device:${BLUETOOTH}"
|
||||||
connect_bluetooth
|
connect_bluetooth
|
||||||
fi
|
fi
|
||||||
@ -795,10 +845,6 @@ elif [ -n "$HIST" ] ; then
|
|||||||
set_var
|
set_var
|
||||||
echo "playing PRIME historical queue ${HIST}"
|
echo "playing PRIME historical queue ${HIST}"
|
||||||
play_prime_hist_queue
|
play_prime_hist_queue
|
||||||
elif [ -n "$QUEUE" ]; then
|
|
||||||
set_var
|
|
||||||
echo "queue info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
|
|
||||||
show_queue
|
|
||||||
elif [ -n "$LIST" ] ; then
|
elif [ -n "$LIST" ] ; then
|
||||||
ATTR="accountName"
|
ATTR="accountName"
|
||||||
echo "the following devices exist in your account:"
|
echo "the following devices exist in your account:"
|
||||||
|
Loading…
Reference in New Issue
Block a user