mackstann / bin

personal scripts

This URL has Read+Write access

bin / rempd
100755 64 lines (53 sloc) 0.986 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
#!/bin/sh
 
# Written by Nick Welch <nick@incise.org>. Author disclaims copyright.
 
# for controlling mpd (musicpd.org) and associated utilities
 
kill_with_prejudice()
{
    name="$1"
    for i in 1 2 3
    do
sudo killall "$name" 2>/dev/null
        if ! pidof "$name" >/dev/null
        then
return 0
        fi
sleep 0.1
    done
sudo killall -9 "$name" 2>/dev/null
    while pidof "$name" >/dev/null
    do
sleep 0.05
    done
}
 
launch()
{
    mpdscribble &
    mpd $HOME/.mpdconf
    mpc random 1 >/dev/null
    mpc repeat 1 >/dev/null
    python $HOME/dev/mpd-weighted-playlist/mpd_weighted_playlist.py < $HOME/.mpd-weights >/dev/null
}
 
update()
{
    mpc update >/dev/null
    while mpc | grep -q 'Updating DB'
    do sleep 0.1
    done
}
 
stop()
{
    kill_with_prejudice mpd
    kill_with_prejudice mpdscribble
}
 
start()
{
    launch
    mpc play
}
 
restart() { update; stop; start; }
 
if [ -n "$1" ]
then
    $1
else
restart
fi