-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger
More file actions
54 lines (46 loc) · 1.59 KB
/
logger
File metadata and controls
54 lines (46 loc) · 1.59 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
#!/bin/sh
mpg123_info() {
[ "${str:0:1}" == "@" ] || return
case "$str" in
*StreamTitle*)
#...StreamTitle='song title here';..... -we want only the title,
#remove up to song title via empty substitute
str="${str/*StreamTitle=\'/}"
#remove after title (will be left with just the title)
str="${str/\';*/}"
#empty string, just return
[ "$str" ] || return
#duplicates of last title
[ "$last_str" == "$str" ] && unset str && return
#title contains 'YourClassical.org'
[ -z "${str##*YourClassical.org*}" ] && unset str && return
#save for next time (check duplicates)
last_str="$str"
#add '@ ' so we know log source is mpg123
str="@ $str"
;;
"@P 0") str="@ stopped" ;;
"@P 1") str="@ paused" ;;
"@P 2") str="@ play" ;;
*)
unset str
;;
esac
}
#if passed a logfile name, use it, else set ourselves
[ "$1" ] && logfile="$1" || logfile=log.txt
#try to append to log, if fails use our own log file
>>"$logfile" || logfile=log.txt
#stay in logging loop until QUITQUIT received (by mp3 script)
#input is from logfifo (mpg123 and mp3 script will send all messages to this script
#via the fifo)
while [ 1 -eq 1 ]; do
read str <logfifo
[ "$str" == "QUITQUIT" ] && break
dat="$(date +%Y-%m-%d)"
tim="$(date +%H:%M:%S)"
mpg123_info
[ "$str" ] && echo "[ $dat $tim ] $str" >> "$logfile"
done
#>$logfile
#just let mp3 delete logfile if needed