-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3
313 lines (303 loc) · 13.2 KB
/
mp3
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/sh
#
# cmdfifo -> mpg123 [1/2]-> logfifo
# mp3 -> cmdfifo
# mp3 -> logfifo
# logfifo -> logger.sh
#==============================================================================
# usage
#==============================================================================
script=$(basename $0) #script name only
usage() {
n=$script
echo " USAGE:"
echo " $n stop -stop stream playback"
echo " $n pause -pause stream playback"
echo " $n quit -quit the mpg123 process"
echo " $n cleanup -cleanup fifos, processes"
echo " $n vol 0-100 -set volume 0-100"
echo " $n vol -set volume to default ($vol_default)"
echo " $n seq B M H -set simple eq base mid high"
echo " $n seq -set simple eq to ($eq3_default)"
echo " $n logs -print the log files"
echo ""
echo " ---the following are live streams"
echo " $n holiday -play MPR Holiday stream"
echo " $n choral -play MPR Choral stream"
echo " $n classical -play MPR Classical stream"
echo " $n bott -play Bott Radio Network"
echo ""
echo " ----the following play today's stream"
echo " $n lwf -play Love Worth Finding"
echo " $n ttb -play Through the Bible"
echo " $n tp -play Turning Point"
# echo " $n itm -play In Touch Ministries"
echo " $n tfl -play Truth for Life"
echo ""
echo " ---the following streams default to today's stream"
echo " unless a date is also provided"
echo " $n anb [20YYMMDD] -play A New Beginning"
echo " $n rym [20YYMMDD] -play Renewing Your Mind"
echo " $n rtw [20YYMMDD] -play Running to Win"
echo " $n gty [20YYMMDD] -play Grace to You"
echo " $n fpm [20YYMMDD] -play Focal Point Ministries"
#echo " $n ltw [20YYMMDD] -play Leading The Way"
echo " $n btb [20YYMMDD] -play Back to the Bible"
echo ""
exit 1
}
#==============================================================================
# init variables
# script command arg arg ...
#==============================================================================
cmd=$1 #set cmd to first arg
this_dir=$(readlink -f $(dirname $0)) #this script full dir name
cmd_fifo=$this_dir/cmdfifo #cmd fifo name
wget_fifo=$this_dir/wgetfifo #wget fifo name
log_fifo=$this_dir/logfifo #wget fifo name
eq3_default="1.2 0.8 2.5" #default eq (base,mid,high)
[ $(pidof mpg123) ] && running=1 #mpg123 already running?
vol_default=70 #default amixer volume
mpg123_exe=mpg123 #mpg123 executable
logger_exe=$this_dir/logger
logfile=$this_dir/log.txt
[ $1 ] || usage #if no args,show usage and exit
#==============================================================================
# init date for streams that use date in url
# optional date can also be passed in
#==============================================================================
today=$(date +%Y)$(date +%m)$(date +%d)
[ ${#2} -eq 8 ] && [ ${2:0:2} -eq 20 ] && today=$2
#==============================================================================
# functions
#==============================================================================
#..............................................................................
# Omega expansion dock rgb connected to gpio 15,16,17
#..............................................................................
rgb() {
#all output (if not already), and off (high)
gpioctl dirout-high 17 &> /dev/null #red
gpioctl dirout-high 16 &> /dev/null #green
gpioctl dirout-high 15 &> /dev/null #blue
case "$1" in
"red")
gpioctl clear 17 &> /dev/null
;;
"green")
gpioctl clear 16 &> /dev/null
;;
"blue")
gpioctl clear 15 &> /dev/null
esac
}
#..............................................................................
# log messages to logger
# if one arg, just log it, if two args, assume first is a command
#..............................................................................
log() {
[ "$1" ] || return
[ "$2" ] && msg="$(printf "%7s : %s" "$1" "$2")" || msg="$1"
echo "$msg" > "$log_fifo"
}
#..............................................................................
logs() {
echo "================================================="
echo " $script log file - $logfile"
echo "================================================="
cat $logfile
}
#..............................................................................
command() {
[ $running ] && [ "$1" ] || exit 1 #if not running or no arg, exit
echo "$1" > "$cmd_fifo" #send command
log "command" "$1" #and log it
}
#..............................................................................
stop() {
command "STOP"
rgb "red" #lights red = stopped
}
#..............................................................................
pause() {
command "PAUSE"
}
#..............................................................................
seq() {
[ $3 ] && eq3_default="$1 $2 $3" #if 3 args, set simple eq
command "SEQ $eq3_default" #else use our default
}
#..............................................................................
vol() {
[ $1 ] && vol_default=$1 #if no arg, use vol_default
amixer -q sset PCM ${vol_default}% #alsa mixer volume
amixer -q sset PCM unmute #alsa mixer unmute
log "volume" $vol_default #log it
}
#..............................................................................
# remove or create fifo's (any arg- then just delete fifo's
#..............................................................................
fifos() {
rm -f $wget_fifo &>/dev/null
rm -f $log_fifo &>/dev/null
rm -f $cmd_fifo &>/dev/null
[ "$1" ] && return
mkfifo $wget_fifo
mkfifo $log_fifo
}
#..............................................................................
# shutdown mpg123, background process will end
#..............................................................................
quit() {
command "QUIT"
sleep 2 #give some time, then
log "QUITQUIT" #shutdown logger
sleep 2
fifos remove #delete fifos
sleep 2
>$logfile #clear logfile
rgb "OFF" #lights off
exit 0
}
#..............................................................................
# shutdown everything, clean up fifos
#..............................................................................
cleanup() {
kill -9 $(pidof logger) &>/dev/null
sleep 1
kill -9 $(pidof mpg123) &>/dev/null
sleep 1
fifos remove #delete fifos
sleep 2
>$logfile #clear logfile
rgb "OFF" #lights off
exit 0
}
#..............................................................................
# start mpg123 in background process
# mpg123 creates fifo (and removes when done), we create wget fifo
# send initial volume, eq
#..............................................................................
init() {
fifos
$logger_exe <$log_fifo & #start logger script
$mpg123_exe -R --float --fifo $cmd_fifo --remote-err 2>$log_fifo &
[ $? ] || exit 1 #if failed, exit
running=1 #set running flag
sleep 3 #give some time, then
vol #init volume
seq #set our default simple eq
rgb "blue" #lights blue = on
}
#..............................................................................
# for http streams, let mpg123 handle http so we get song titles
# use wget into fifo for https streams as mpg123 does not do https
# wget will quit when pipe is broken (by stop or quit command)
#..............................................................................
http() {
[ $running ] || init #init mpg123 if not running
[ $log_date ] && log "date" $today #date, (if log_date flag set)
log "title" "$title" #log title,
if [ ${url:4:1} == "s" ]; then #if https
log "url" $url #log url (mpg123 not logging it)
command "LOAD $wget_fifo" #tell mpg123 to load from fifo
wget -qO $wget_fifo $url & #wget into fifo, background
else #else is http
command "LOAD $url" #tell mpg123 to load url
fi
rgb "green" #lights green = running
}
#==============================================================================
# process script arguments
#==============================================================================
#assume http playback, change for other commands
func="http"
#allow uppercase arguments by converting all to lowercase
cmd=$(echo $cmd | awk '{ print tolower($0) }')
case $cmd in
"rgb") #can check rgb led operation- ./mp3 rgb blue|green|red|off
func="$@"
;;
"stop"|"pause"|"quit"|"logs"|"cleanup")
func=$cmd
;;
"seq"|"vol")
func="$@"
;;
"classical")
url="http://cms.stream.publicradio.org/cms.mp3"
title="MPR Classical Stream"
;;
"holiday")
url="http://holiday.stream.publicradio.org/holiday_cms.mp3"
title="MPR Holiday Stream"
;;
"choral")
url="http://choral.stream.publicradio.org/choral.mp3"
title="MPR Choral Stream"
;;
"rtw")
url="http://s3.amazonaws.com/themoodychurch/RadioPrograms/RTW25/RTWL${today}.mp3"
title="Running to Win - Dr. Erwin Lutzer"
log_date=1
;;
"rym")
url="http://s3.amazonaws.com/ligonier-broadcast-media/mp3/rym${today}.mp3"
title="Renewing Your Mind - R.C. Sproul"
log_date=1
;;
#"itm") #no longer works
# url=$(wget -qO - https://www.intouch.org/listen/podcast/today-on-radio | sed 's:":\n:g' | grep -m 1 mp3)
# title="In Touch Ministries - Dr. Charles Stanley"
# ;;
"lwf")
url=$(wget -qO - https://www.oneplace.com/ministries/love-worth-finding/custom-player | sed 's:\x27:\n:g' | grep -m 1 mp3)
title="Love Worth Finding - Adrian Rogers"
;;
"tp")
url=$(wget -qO - http://www.davidjeremiah.org/site/radio_player.aspx | sed 's:":\n:g' | grep -m 1 ".\mp3" | sed 's:?.*::')
title="Turning Point - Dr. David Jeremiah"
;;
"ttb")
url=$(wget -qO - https://www.oneplace.com/ministries/thru-the-bible-with-j-vernon-mcgee/custom-player/ | sed 's:\x27:\n:g' | grep -m 1 mp3)
title="Through the Bible - Dr. J. Vernon McGee"
;;
"bott")
url="http://sc1.christiannetcast.com:9058/"
title="Bott Radio Network"
;;
"anb")
url=https://anewbeginning.swncdn.com/anb/${today:0:4}/anb${today}pod.mp3
title="A New Beginning - Greg Laurie"
;;
"gty")
url=https://cdn.gty.org/podcast/${today}.mp3
title="Grace to You - John MacArthur"
;;
"fpm")
url=http://fpmedia.focalpointministries.org/sermonbroadcast/${today:0:4}/${today}.mp3
title="Focal Point Ministries - Mike Fabarez"
;;
#these crash mpg123 for some reason
#but can play via command line, https- wget -qO - $url | mpg123 -
#or http- mpg123 $url
#"ltw")
#url=$(https://web.audio.ltw.org/${today:0:4}/ltw${today}.mp3
#url=$(wget -qO - https://www.oneplace.com/ministries/leading-the-way/ | sed 's:\x27:\n:g' | grep -m 1 mp3)
#title="Leading The Way - Dr. Michael Youssef"
#;;
"tfl")
url=$(wget -qO - https://www.truthforlife.org | sed 's:\x27:\n:g' | grep -m 1 mp3)
title="Truth for Life - Alistair Begg"
;;
"btb")
url=https://s3.amazonaws.com/brn-archive/back-to-the-bible/${today:0:4}-${today:4:2}-${today:6:2}-back-to-the-bible.mp3
title="Back to the Bible - Bryan Clark"
;;
*)
usage
;;
esac
#==============================================================================
# do it
#==============================================================================
$func