-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathradioshell.sh
More file actions
executable file
·146 lines (127 loc) · 4.35 KB
/
radioshell.sh
File metadata and controls
executable file
·146 lines (127 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
#title :radioshell.sh
#description :This script allows to manage and listen online radios in the terminal.
#author :Tom Celestin
#date :20190123
#version :1.0
#usage :bash radioshell.sh
cmd_list() {
echo "\n====================[\e[0;32mRADIOS LIST\e[0m]====================="
echo ""
while read r;
do
echo "* $r"
done < $RADIOS_LIST | sed 's/ :.*$//' | sed '/#.*$/d' | sort
echo ""
echo "======================================================"
}
get_radio_url_from_name() {
url=$(grep "$1" "$RADIOS_LIST" | sed 's/^.*: //')
echo "$url"
}
get_radio_name() {
line=$1
echo "$line" | sed 's/ :.*$//'
}
test_grep_result() {
if [ "$(echo "$1" | wc -l)" -gt 1 ] || [ -z "$1" ]; then
return 0
fi
echo "ok"
}
cmd_clear() {
clear && echo "$(display_home)"
}
call_mpv() {
echo "\n===================[\e[0;32mSTOP WITH 'q'\e[0m]===================="
echo ""
mpv $1
echo ""
echo "======================================================"
cmd_clear
}
cmd_play() {
radiourl="$(get_radio_url_from_name "$1")"
if [ -z $(echo "$(test_grep_result "$radiourl")") ]; then
echo "\n\e[0;31mSorry, I had trouble finding one radio with the name you provided.\e[0m"
echo "If you can't decide, try the \e[0;34mrandom\e[0m command."
echo "Or list them with the \e[0;34mlist\e[0m command."
return 0
fi
call_mpv $radiourl
}
cmd_random() {
randomline="$(cat $RADIOS_LIST | sort | sed '/#.*$/d' | shuf -n 1)"
randomradioname=$(get_radio_name "$randomline")
call_mpv $(get_radio_url_from_name $randomradioname)
}
cmd_add() {
read -p "Enter radio name : " radioname
read -p "Enter radio URL : " radiourl
$(echo "$radioname : $radiourl" >> "$RADIOS_LIST")
}
cmd_delete() {
read -p "Do you need the list ? [yes/no] : " answer
if [ "$answer" = 'yes' ]
then
echo "$(cmd_list)"
fi
echo ""
read -p "Enter radio name to delete : " radioname
grep_result="$(grep "radioname" $RADIOS_LIST)"
if [ -z "$(test_grep_result "$grep_result")" ]; then
echo "\n\e[0;31mNo radio has been deleted. Please check the radio name you provided.\e[0m"
return 0
fi
grep -v "$radioname" $RADIOS_LIST > /tmp/radiolist.tmp; mv /tmp/radiolist.tmp $RADIOS_LIST
}
cmd_help() {
echo "======================[\e[0;32mCOMMANDS\e[0m]======================"
echo ""
echo " \e[0;34mlist\e[0m...............Show radio names"
echo " \e[0;34mplay <radio_name>\e[0m..Play specified radio"
echo " \e[0;34mrandom\e[0m.............Play random radio from list"
echo " \e[0;34madd\e[0m................Add a radio to the list"
echo " \e[0;34mdelete\e[0m.............Delete a radio from the list"
echo " \e[0;34mclear\e[0m..............Clear the screen"
echo " \e[0;34mquit\e[0m...............Quit program"
echo ""
echo "======================================================"
}
display_home() {
echo "======================================================"
echo "| |"
echo "| ____ ___ __ ____ |"
echo "| / __ \____ _____/ (_)___ _____/ /_ ___ / / / |"
echo "| / /_/ / __ \`/ __ / / __ \/ ___/ __ \/ _ \/ / / |"
echo "| / _, _/ /_/ / /_/ / / /_/ (__ ) / / / __/ / / |"
echo "| /_/ |_|\__,_/\__,_/_/\____/____/_/ /_/\___/_/_/ |"
echo "| |"
echo "| |"
echo "$(cmd_help)"
}
cmd_exit() {
exit 1
}
main() {
cmd_clear
while true;
do
echo ""
read -p "Enter command > " cmd args
case $cmd in
"") continue;; # skip empty input lines
h|help) cmd_name=help;;
q|exit|quit) cmd_name=exit;;
l|list) cmd_name=list;;
p|play) cmd_name=play;;
a|add) cmd_name=add;;
d|delete) cmd_name=delete;;
r|random) cmd_name=random;;
c|clear) cmd_name=clear;;
*) echo "\n\e[0;31mCommand doesn't exist. Try 'help'\e[0m" && continue;;
esac
cmd_$cmd_name $args
done
}
main