-
Notifications
You must be signed in to change notification settings - Fork 0
/
lolmpd.sh
executable file
·80 lines (72 loc) · 1.67 KB
/
lolmpd.sh
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
#!/bin/bash
#lolmpd.sh - simple lold MPD track notification
#Copyright (C) 2013 Anton Pirogov
#Licensed under the MIT License
#
#requires mpc and standard unix tools to work
#help text
usage() {
cat << EOF
usage: $0 [OPTIONS]
This script regularily sends the running MPD track to lold
OPTIONS:
-h: Show this message
-l: lold host
-p: lold port
-m: MPD host
-P: MPD port
EOF
}
#read settings
LOLD_HOST=localhost
LOLD_PORT=10101
MPD_HOST=localhost
MPD_PORT=6600
while getopts "hl:p:m:P:" OPTION; do
case $OPTION in
h)
usage
exit 1
;;
l)
LOLD_HOST=$OPTARG
;;
p)
LOLD_PORT=$OPTARG
;;
m)
MPD_HOST=$OPTARG
;;
P)
MPD_PORT=$OPTARG
;;
esac
done
#main loop
MPC="mpc -h $MPD_HOST -p $MPD_PORT"
OLDTRACK=
DURATION=0
SLEEPCOUNT=0
while true; do
TRACK=`$MPC | grep -v volume | head -n 1` #read track
TRACK=`echo "$TRACK" | sed 's/[^[:print:]]//'` #strip non-printable
TRACK=`echo "$TRACK" | sed 's/^.*\///'` #strip path
TRACK=`echo "$TRACK" | sed 's/.mp3$//'` #strip ext. on filenames
if [ "$TRACK" == "$OLDTRACK" ] && [ "$SLEEPCOUNT" -lt "$DURATION" ]; then
#old animation probably still playing -> sleep
sleep 5
SLEEPCOUNT=$(($SLEEPCOUNT+5))
else
#time to resend track / show new track
OLDTRACK=$TRACK
SLEEPCOUNT=0
#calculate approximate duration
frmnum=`./lolplay -m "$TRACK" -o | wc -l`
delay=40
DURATION=$(($frmnum*$delay/1000 + 2))
#output track
./lolplay -h $LOLD_HOST -p $LOLD_PORT -C 1 -m " " #interrupt running
sleep 2
./lolplay -h $LOLD_HOST -p $LOLD_PORT -D $delay -m "$TRACK" #current track
fi
done