Files
bash/sonos.sh
Bruno 21 84a4aef5f1 sonos.sh
rewrite from scratch
2020-12-18 17:46:41 +01:00

561 lines
15 KiB
Bash
Executable File

#!/bin/bash
#set -e
set -u
#set -o pipefail
#\033[background;style;color]
# background: 40-49,100-107
# color: 30-39,90-97
# style: 1 (bold) 2 (light) 4 (underline) 5 (blink) 7 (reverse) 8 (hidden)
list="local"
if [ "$list" = "discovery" ]; then loc="";
else loc=" -l"; fi
echo "$loc"
#sleep 3
underline="\033[4m"
bgd="\033[1;4;31m"
red="\033[1;31m"
bold="\033[1m"
reset="\033[0m"
# Main Menu
main() {
clear
set device
device="$1"
while :
do
clear
echo -e ""
echo -e "\033[1m 🔈 SoCo-Cli GUI\033[0m"
echo -e ""
echo -e " "
echo -e "---------------------------------"
echo -e " Main Menu "
echo -e "---------------------------------"
echo -e " 1) ${bgd}A${reset}bout "
echo -e " 2) ${bgd}H${reset}elp "
echo -e " 3) ➔ ${bgd}C${reset}hambre "
echo -e " 4) ➔ ${bgd}S${reset}alon "
echo -e " 5) ${bgd}Q${reset}uit "
echo -e "================================="
echo -e "Enter your menu choice [1-5]: \c "
read main_menu
case "$main_menu" in
1|a|A) about
read -p ""
;;
2|h|H) help
read -p ""
;;
3|c|C) soco "Chambre";;
4|s|S) soco "Salon";;
5|q|Q) exit 0;;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
echo -e "Press ${bold}ENTER${reset} To Continue..." ; read ;;
esac
done
}
about() {
clear
echo ""
echo -e "\033[1mAbout:\033[0m"
echo ""
echo " ##### ##### #### #### ## ";
echo " ## ## ## ## ## ## ";
echo " ##### ## ## #### ## ## #### ## ## ### ## ## ## ### ";
echo " ## ## ## ## ## ## ## ###### ## ## ## ## ## ## ## ## ## ";
echo " ##### ## ## ## ## ## ## ## # ## ## ## ## ## ## ";
echo " ## ## ## ## ## ## ## ## ## ## ## ## ##### ## ## ## ";
echo " ###### ##### #### ##### #### ####### #### ## ###### #### ";
echo " ##### ";
echo ""
echo "Just a GUI for the wonderful tool SoCo-Cli"
echo ""
echo "https://github.com/avantrec/soco-cli"
echo ""
echo "<Press Enter to quit>"
}
help() {
echo ""
echo -e "\033[1mHelp:\033[0m"
echo ""
echo "<Press Enter to quit>"
}
inform() {
device="$1"
info=$(sonos $loc $device info)
model_name=$(echo "$info" | grep "model_name" | awk -F"=" '{print $2}')
model_number=$(echo "$info" | grep "model_number" | awk -F"=" '{print $2}')
player_name=$(echo "$info" | grep "player_name" | awk -F"=" '{print $2}')
zone_name=$(echo "$info" | grep "zone_name" | awk -F"=" '{print $2}')
mac_address=$(echo "$info" | grep "mac_address" | awk -F"=" '{print $2}')
ip_address=$(echo "$info" | grep "ip_address" | awk -F"=" '{print $2}')
display_version=$(echo "$info" | grep "display_version" | awk -F"=" '{print $2}')
hardware_version=$(echo "$info" | grep "hardware_version" | awk -F"=" '{print $2}')
software_version=$(echo "$info" | grep "software_version" | awk -F"=" '{print $2}')
echo ""
printf "\e[1m| %-20s | %-20s |\e[0m\n" "$model_name" "$player_name"
printf "| %-20s | %-20s |\n" "Model name" "$model_name"
printf "| %-20s | %-20s |\n" "Model number" "$model_number"
printf "| %-20s | %-20s |\n" "Player name" "$player_name"
printf "| %-20s | %-20s |\n" "Zone name" "$zone_name"
printf "| %-20s | %-20s |\n" "mac adress" "$mac_address"
printf "| %-20s | %-20s |\n" "IP address" "$ip_address"
printf "| %-20s | %-20s |\n" "Display version" "$display_version"
printf "| %-20s | %-20s |\n" "Hardware version" "$hardware_version"
printf "| %-20s | %-20s |\n" "Software version" "$software_version"
echo ""
}
# Soco device Menu
soco() {
clear
#set device
playing=""
device="$1"
while :
do
clear
echo -e ""
echo -e "\033[1m 🔊 Sonos $device \033[0m"
echo -e ""
echo -e " "
echo -e "------------------------|-------------------------|--------------------"
echo -e " Sonos $device Menu : $playing "
echo -e "------------------------|-------------------------|--------------------"
echo -e " 1) France In${bgd}f${reset}o " " | " "11) volume ${bgd}11${reset} " " | " "21) ➔ ${bgd}I${reset}nfos "
echo -e " 2) France Int${bgd}e${reset}r " " | " "12) ${bgd}m${reset}ute ON " " | " "22) ➔ ${bgd}L${reset}ists "
echo -e " 3) ${bgd}K${reset}6 FM " " | " "13) volume ${bgd}13${reset} " " | " "23) Play al${bgd}b${reset}ums "
echo -e " 4) Rires et ${bgd}C${reset}hansons " " | " "14) m${bgd}u${reset}te OFF " " | " "24) Play artists (${bgd}x${reset}) "
echo -e " 5) ${bgd}R${reset}TL " " | " "15) volume ${bgd}15${reset} " " | " "25) Play tracks (${bgd}y${reset}) "
echo -e " 6) ${bgd}D${reset}eezer Flow " " | " "16) ${bgd}s${reset}tart $device " " | " "26) "
echo -e " 7) " " | " "17) s${bgd}t${reset}op $device " " | " "27) "
echo -e " 8) " " | " "18) ${bgd}p${reset}rev on $device " " | " "28) "
echo -e " 9) " " | " "19) ${bgd}n${reset}ext on $device " " | " "29) ${bgd}H${reset}elp "
echo -e "10) " " | " "20) Sha${bgd}z${reset}aaaam " " | " "30) ➔ ${bgd}A${reset}ccueil "
echo -e "========================================================================"
echo -e "Enter your menu choice [1-30]: \c "
read soco_menu
case "$soco_menu" in
1|f|F) option_1;;
2|e|E) option_2;;
3|k|K) option_3;;
4|c|C) option_4;;
5|r|R) option_5;;
6|d|D) option_6;;
11) option_11;;
12|m|M) option_12;;
13) option_13;;
14|u|U) option_14;;
15) option_15;;
16|s|S) option_16;;
17|t|T) option_17;;
18|p|P) option_18;;
19|n|N) option_19;;
20|z|Z) option_20;;
21|i|I) soco_infos $device;;
22|l|L) soco_lists $device;;
23|b|B) play_album_from_library;;
24|x|X) play_artist_from_library;;
25|y|Y) play_track_from_library;;
29|h|H) help;;
30|a|A) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
echo -e "Press ${bold}ENTER${reset} To Continue..." ; read ;;
esac
done
}
# Playing France Info
option_1() {
#echo "$loc"
playing="Playing France Info..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'franceinfo' && sleep 2
}
# Playing France Inter
option_2() {
playing="Playing France Inter..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'france inter' && sleep 2
}
# Playing K6 FM
option_3() {
playing="Playing K6 FM..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'K6 FM' && sleep 2
}
# Playing Rires et Chansons
option_4() {
playing="Playing Rires et Chansons..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'Rire et Chansons' && sleep 2
}
# Playing RTL
option_5() {
playing="Playing RTL..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'RTL' && sleep 2
}
# Playing Deezer Flow
option_6() {
playing="Playing Deezer Flow..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device play_fav 'Flow'
}
# Set volume to level 11
option_11() {
#playing="Playing Deezer Flow..."
echo -e "\n\033[1m Set volume to level 11... \033[0m"
sonos $loc $device volume 11 && sleep 2
}
# Mute ON
option_12() {
playing="Mute ON..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device mute on && sleep 2
}
# Set volume to level 13
option_13() {
#playing="Start $device..."
echo -e "\n\033[1m Set volume to level 13... \033[0m"
sonos $loc $device volume 13 && sleep 2
}
# Mute OFF
option_14() {
#playing="Playing Deezer Flow..." <= Shazaaam
echo -e "\n\033[1m Mute OFF... \033[0m"
sonos $loc $device mute off && sleep 2
}
# Set volume to level 15
option_15() {
#playing="Stop $device..."
echo -e "\n\033[1m Set volume to level 15... \033[0m"
sonos $loc $device volume 15 && sleep 2
}
# Start $device
option_16() {
playing="Start $device..." # <= Shazaaam
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device start && sleep 2
}
# Stop $device
option_17() {
playing="Stop $device..."
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device stop && sleep 2
}
# Previous tracks
option_18() {
#playing="Start $device..." # <= Shazaaam
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device previous && sleep 2
}
# Next tracks
option_19() {
#playing="Stop $device..." # <= Shazaaam
echo -e "\n\033[1m $playing \033[0m"
sonos $loc $device next && sleep 2
}
# Shazaaaam
option_20() {
echo -e "\n\033[1m Shazaaaam... \033[0m"
shazam
}
shazam() {
sz=$(sonos $loc $device track)
if [[ "$sz" =~ "Artist" ]]; then artist=$(echo "$sz" | grep "Artist" | awk -F"[=:]" '{print $2}');
else artist=""; fi
if [[ "$sz" =~ "Title" ]]; then title=$(echo "$sz" | grep "Title" | awk -F"[=:]" '{print $2}');
else title=""; fi
if [[ "$sz" =~ "Album" ]]; then album=$(echo "$sz" | grep "Album" | awk -F"[=:]" '{print $2}');
else album=""; fi
result=$( grep -i "uRi" <<< $sz)
if [ -n "$result" ]; then
uri=$(echo ${sz} | grep "URI" | grep -Eo '(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]');
if [[ "$uri" =~ "?" ]]; then
radio=$(echo "$uri" | awk -F"?" '{print $1}')
else
radio="$uri"
fi
else radio=""; fi
if [ -n "$radio" ]; then
shazam="\033[1mOn air\033[0m: \033[3m$radio\033[0m"
else
shazam="\033[1mOn air\033[0m: \033[1m$title\033[0m \033[3mfrom\033[0m $album \033[3mof\033[0m $artist"
fi
echo -e "\n $shazam \n"
sleep 2.5
#read -p "< Press Enter>"
}
# Search artist in library -> add album to queue -> play it
play_artist_from_library() {
read -p "Search artist in library: " search
sonos $loc $device search_artists "$search"
read -p "Album to play: " number
sonos $loc $device queue_search_result_number $number first : $device play_from_queue
}
# Search album in library -> add to queue -> play it
play_album_from_library() {
read -p "Search album in library: " search
sonos $loc $device search_albums "$search"
read -p "Album to play: " number
sonos $loc $device queue_search_result_number $number first : $device play_from_queue
}
# Search track in library -> add to queue -> play it
play_track_from_library() {
read -p "Search track in library: " search
sonos $loc $device search_tracks "$search"
read -p "Track to play: " number
sonos $loc $device queue_search_result_number $number first : $device play_from_queue
}
# Help
help() {
echo -e "\n\033[1m Help... \033[0m\n"
echo -e "Play albums:"
echo -e "Play artists:"
echo -e "Play tracks:"
echo -e "\n"
read -p "< Press Enter>"
}
# Soco device Lists Menu
soco_lists() {
clear
device="$1"
while :
do
clear
echo -e ""
echo -e "\033[1m 🔊 Sonos lists $device \033[0m"
echo -e ""
echo -e " "
echo -e "--------------------------------"
echo -e " Sonos $device lists Menu "
echo -e "--------------------------------"
echo -e " 1) Favourite radio ${bgd}s${reset}tations " " | "
echo -e " 2) ${bgd}F${reset}avourites " " | "
echo -e " 3) ${bgd}Q${reset}ueue " " | "
echo -e " 4) List ${bgd}a${reset}rtists " " | "
echo -e " 5) List al${bgd}b${reset}ums " " | "
echo -e " 6) " " | "
echo -e " 7) " " | "
echo -e " 8) " " | "
echo -e " 9) ${bgd}C${reset}lear queue " " | "
echo -e "10) ${bgd}R${reset}eturn " " | "
echo -e "================================"
echo -e "Enter your menu choice [1-10]: \c "
read lists
case "$lists" in
1|s|S) list_1;;
2|f|F) list_2;;
3|q|Q) list_3;;
4|a|A) list_4;;
5|b|B) list_5;;
9|c|C) list_9;;
10|r|R) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
echo -e "Press ${bold}ENTER${reset} To Continue..." ; read ;;
esac
done
}
# Favourite radio stations
list_1() {
echo -e "\n\033[1m Favourite radio stations... \033[0m"
s=$(sonos $loc $device favourite_radio_stations)
echo -e "\n $s \n"
read -p "< Press Enter>"
}
# Favourites
list_2() {
echo -e "\n\033[1m Favourites... \033[0m"
f=$(sonos $loc $device list_favs)
echo -e "\n $f \n"
read -p "< Press Enter>"
}
# Queue
list_3() {
echo -e "\n\033[1m Queue... \033[0m"
q=$(sonos $loc $device list_queue)
echo -e "\n $q \n"
read -p "< Press Enter>"
}
# List Artists
list_4() {
echo -e "\n\033[1m List artists... \033[0m"
a=$(sonos $loc $device list_artists | more)
echo -e "\n $a \n"
read -p "< Press Enter>"
}
# Lists Albums
list_5() {
echo -e "\n\033[1m List albums... \033[0m"
b=$(sonos $loc $device list_albums | more)
echo -e "\n $b \n"
read -p "< Press Enter>"
}
# Clear queue
list_9() {
echo -e "\n\033[1m Clear queue... \033[0m"
sonos $loc $device clear_queue
q=$(sonos $loc $device queue_length)
if [ $q -eq 0 ]; then echo "Queue is empty"; else echo "Queue is not empty"; fi
sleep 1.5
}
# Soco device Infos Menu
soco_infos() {
clear
device="$1"
while :
do
clear
echo -e ""
echo -e "\033[1m 🔊 Sonos $device infos \033[0m"
echo -e ""
echo -e " "
echo -e "--------------------------------"
echo -e " Sonos $device infos Menu "
echo -e "--------------------------------"
echo -e " 1) ${bgd}A${reset}larms " " | "
echo -e " 2) ${bgd}G${reset}roups " " | "
echo -e " 3) ${bgd}I${reset}nfo " " | "
echo -e " 4) ${bgd}S${reset}hares " " | "
echo -e " 5) S${bgd}y${reset}sinfo " " | "
echo -e " 6) " " | "
echo -e " 7) " " | "
echo -e " 8) " " | "
echo -e " 9) " " | "
echo -e "10) ${bgd}R${reset}eturn " " | "
echo -e "================================"
echo -e "Enter your menu choice [1-10]: \c "
read infos
case "$infos" in
1|a|A) info_1;;
2|g|G) info_2;;
3|i|I) info_3;;
4|s|S) info_4;;
5|y|Y) info_5;;
10|r|R) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
echo -e "Press ${bold}ENTER${reset} To Continue..." ; read ;;
esac
done
}
# Alarms
info_1() {
echo -e "\n\033[1m Alarms... \033[0m"
a=$(sonos $loc $device alarms)
echo -e "\n $a \n"
read -p "< Press Enter>"
}
# Groups
info_2() {
echo -e "\n\033[1m Groups... \033[0m"
g=$(sonos $loc $device groups)
echo -e "\n $g \n"
read -p "< Press Enter>"
}
# Infos
info_3() {
inform $device
read -p "< Press Enter>"
}
# Shares
info_4() {
echo -e "\n\033[1m Shares... \033[0m"
s=$(sonos $loc $device shares)
echo -e "\n $s \n"
read -p "< Press Enter>"
}
# Sysinfo
info_5() {
echo -e "\n\033[1m Sysinfo... \033[0m"
y=$(sonos $loc $device sysinfo)
echo -e "\n $y \n"
read -p "< Press Enter>"
}
main