-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradio
More file actions
executable file
·154 lines (142 loc) · 4.2 KB
/
radio
File metadata and controls
executable file
·154 lines (142 loc) · 4.2 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
147
148
149
150
151
152
153
154
#!/usr/local/bin/bash
# README: this script required bash 4+ (it uses associative arrays, which are supported since bash 4)
declare -A radios
radios['jungle']='http://stream5.jungletrain.net:8000/'
radios['soundart']='http://icecast.commedia.org.uk:8000/soundart.mp3'
radios['resonance']='http://stream.resonance.fm/resonance'
radios['reboot']='http://87.118.122.220:8002/stream?type=.mp3'
radios['corax']='https://streaming.fueralle.org/corax_192.mp3'
radios['panik']='https://streaming.domainepublic.net/radiopanik.ogg.m3u'
radios['ARA']='https://s1.voscast.com:11187/RadioARA.mp3'
# to add a radio, duplicate the line and change the name and URL, like radios['name']='URL'
declare -A players
players['VLC']='/Applications/VLC.app/Contents/MacOS/VLC -I curses'
players['mocp']='mocp'
players['mplayer']='mplayer'
# to add a player, duplicate the line and change the name and command line invocation, like players['name']='command'
# defaults
verbose="False"
list_radios()
{
echo "Available radios:"
iter=1
for key in "${!radios[@]}"; do
echo "$iter. $key at (${radios[$key]})"
((iter = iter+1))
done
}
list_players()
{
echo "Available command line players:"
iter=1
for key in "${!players[@]}"; do
echo "$iter. $key at (${players[$key]})"
((iter = iter+1))
done
}
help()
{
echo "radio is a bash/shell script for Unix (incl. Mac) that opens a web radiio and starts playing it with a particular command line music player. "
echo
echo "Usage:\n> radio [-h|p|l]"
echo "options:"
echo "-h --help Display this help."
echo "-r --radio <name> Play radio of <name> (see --list for list of available radios)."
echo "-R --ramdom Play a radio at RANDOM (see --list for list of available radios)."
echo "-p --player <name> Play radio using the <name> player (see --list-players for list of available players)."
echo "-pa --player-args <\"args\"> Pass additional arguments (use quotes around them) to your selected player."
echo "-l --list Display available radios (add more by editing the script)."
echo "-lr --list-radios Display available radios (add more by editing the script)."
echo "-lp --list-players Display available radios (add more by editing the script)."
echo
}
function parse_params() {
local param
while [[ $# -gt 0 ]]; do
param="$1"
shift
case $param in
-h | --help)
help;
exit 0
;;
-l | --list)
list_radios;
exit 0
;;
-lr | --list-radios)
list_radios;
exit 0
;;
-lp | --list-players)
list_players;
exit 0
;;
-p | --player) #player by name
player=$param
last_arg="player"
;;
-r | --radio) #radio by name
radio=$param
last_arg="radio"
;;
-R | --random) #radio chosen randomly
range=${#radios[@]}
((range=range-1))
random=`jot -r 1 0 $range}`
counter=0
for i in "${!radios[@]}"
do
if [ $counter -eq $random ]
then
radio=$i
fi
((counter=counter+1))
done
;;
-pa | --player-args) #additional args for player
player_args=$param
last_arg="player_args"
;;
-u | --url) #radio by url
url=$params
last_arg="url"
;;
-V | --verbose)
verbose="True"
;;
*)
case $last_arg in
player)
player=$param
;;
radio)
radio=$param
;;
player_args)
player_args=$param
;;
url)
url=$param
;;
*)
echo "Invalid parameter was provided: $param"
;;
esac
;;
esac
done
}
parse_params "$@"
if [ $verbose == "True" ]
then
echo "-------"
echo "player: $player (with args $player_args)"
echo "radio: $radio (or at forced url: $url)"
echo "-------"
fi
if [$url -ne ""]; then
${players[$player]} $player_args ${radios[$radio]}
else
${players[$player]} $player_args $url
fi