Features:
+playlist
+timer
This commit is contained in:
2020-12-20 09:26:48 +01:00
parent 84a4aef5f1
commit 96b1f9d772

174
sonos.sh
View File

@@ -152,7 +152,7 @@ soco() {
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 " 6) ${bgd}D${reset}eezer Flow " " | " "16) ${bgd}s${reset}tart $device " " | " "26) Sleeep (${bgd}w${reset}) "
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 "
@@ -184,6 +184,7 @@ soco() {
23|b|B) play_album_from_library;;
24|x|X) play_artist_from_library;;
25|y|Y) play_track_from_library;;
26|w|W) sleeep;;
29|h|H) help;;
30|a|A) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
@@ -378,6 +379,124 @@ help() {
read -p "< Press Enter>"
}
# Sleep timer
sleeep() {
playing="Set sleep timer..."
echo -e "\n\033[1m $playing \033[0m"
status=$(sonos $loc $device status)
if [[ "$status" != "STOPPED" ]]; then
while :
do
echo -e "\n1) -${bgd}d${reset}uration (10s, 30m, 1.5h)"
echo -e "2) -${bgd}t${reset}ime (16:00)"
echo -e "3) ${bgd}C${reset}ancel timer"
#echo -e "4) ${bgd}R${reset}eturn"
read -p "Choose an action [1-3]: " st
case $st in
1|d|D) sleeep_1
break;;
2|t|T) sleeep_2
break;;
3|c|C) sleeep_3
break;;
#4|r|R) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
break
esac
done
else
echo -e "\n${red}$device is not playing !${reset}";
sleep 1
fi
}
# Cancel timer
sleeep_3() {
clear
echo -e "\n\033[1m Cancel timer... \033[0m\n"
secs=$(sonos $loc $device sleep_timer)
if [ $secs -ne 0 ]; then
printf "Current timer: $device goes to sleep in %02dh:%02dm:%02ds\n" $(($secs/3600)) $(($secs%3600/60)) $(($secs%60))
echo -e "\n"
read -p "Do you want to cancel timer [y/n] ?: " rep
#if [[ "$rep" == "y" ]] || [[ "$rep" == "o" ]]; then
if [[ "$rep" == "y" || "$rep" == "Y" || "$rep" == "o" || "$rep" == "O" ]]; then
sonos $loc $device sleep_timer cancel
fi
else
echo -e "There is currently no timer !"
fi
sleep 1
}
# Sleep timer: timer
sleeep_2() {
clear
while :
do
read -p "Enter time [16:00]: " timer
if [[ $timer =~ ^([0-2][0-3]|[0-1][0-9]):[0-5][0-9]+$ ]];
then
sonos $loc $device sleep_at $timer
echo -e "\n$device goes to sleep at ${bold}$timer${reset}."
break
else echo -e "\n${red}Oops!!! Please enter correct hour.${reset}";
fi
done
sleep 2
}
# Sleep timer: duration
sleeep_1() {
clear
while :
do
read -p "Enter duration [10s, 30m, 1.5h]: " duration
if [[ $duration =~ ^[0-9](.?)[0-9]?(s|m|h)$ ]]; # 10s 2h
then
if [[ $duration =~ "s" ]];
then
a=${duration%?}
fi
if [[ $duration =~ "m" ]];
then
a=${duration%?}
a=$((a*60))
fi
if [[ $duration =~ "h" ]];
then
a=${duration%?}
b=$(echo "$a" | awk -F"." '{print $1}')
c=$(echo "$a" | awk -F"." '{print $2}')
b=$((b * 3600))
c=$((c * (3600 / 10)))
a=$((b + c))
fi
t=$(date +"%s")
t=$((t+a))
#date -d @$t # linux
h=$(date -r $t) # osx
sonos $loc $device sleep_timer $duration
echo -e "\n$device goes to sleep in ${bold}${duration//m/mn} ($h)${reset}."
break
else echo -e "\n${red}Oops!!! Please enter correct duration.${reset}";
fi
done
sleep 2
}
# Soco device Lists Menu
soco_lists() {
@@ -394,16 +513,16 @@ soco_lists() {
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 " 1) Favourite radio ${bgd}s${reset}tations " " | " " 11) Create Sonos ${bgd}p${reset}laylist " " | "
echo -e " 2) ${bgd}F${reset}avourites " " | " " 12) ${bgd}L${reset}ists tracks in all Sonos Playlists " " | "
echo -e " 3) ${bgd}Q${reset}ueue " " | " " 13) Ad${bgd}d${reset} a Sonos playlist to queue " " | "
echo -e " 4) List ${bgd}a${reset}rtists " " | " " 14) " " | "
echo -e " 5) List al${bgd}b${reset}ums " " | " " 15) " " | "
echo -e " 6) " " | " " 16) " " | "
echo -e " 7) " " | " " 17) " " | "
echo -e " 8) " " | " " 18) " " | "
echo -e " 9) ${bgd}C${reset}lear queue " " | " " 19) " " | "
echo -e "10) " " | " " 20) ${bgd}R${reset}eturn " " | "
echo -e "================================"
echo -e "Enter your menu choice [1-10]: \c "
read lists
@@ -416,7 +535,10 @@ soco_lists() {
4|a|A) list_4;;
5|b|B) list_5;;
9|c|C) list_9;;
10|r|R) exec "$0";;
11|p|P) list_11;;
12|l|L) list_12;;
13|d|D) list_13;;
20|r|R) exec "$0";;
*) echo -e "\n${red}Oops!!! Please Select Correct Choice${reset}";
echo -e "Press ${bold}ENTER${reset} To Continue..." ; read ;;
esac
@@ -473,6 +595,34 @@ list_9() {
sleep 1.5
}
# Create Sonos playlist
list_11() {
echo -e "\n\033[1m Create Sonos playlist... \033[0m"
echo -e "\n"
read -p "Input a name for playlist: " name
sonos $loc $device create_playlist "$name"
}
# Create Sonos playlist
list_12() {
echo -e "\n\033[1m List tracks in all Sonos Playlists... \033[0m"
c=$(sonos $loc $device list_all_playlist_tracks)
echo -e "\n $c \n"
read -p "< Press Enter>"
}
# Add a Sonos playlist to queue
list_13() {
playing="Add Sonos playlist to queue..."
echo -e "\n\033[1m $playing \033[0m"
echo -e "\nList of Sonos playlist:"
sonos $loc $device list_playlists
read -p "Choose a playlist: " lsp
sonos $loc $device add_playlist_to_queue "$lsp"
# Give an error if empty playlist
}
# Soco device Infos Menu