-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalplc.sh
executable file
·96 lines (85 loc) · 1.93 KB
/
alplc.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
get_players() {
pacmd list-sink-inputs | grep -E "client: [0-9]+ <([Ss]potify|Music Player Daemon)>" | cut -d' ' -f2
}
get_player_state() {
pacmd list-sink-inputs | grep "client: $1 " -B12 | grep "state: " | cut -d' ' -f2
}
get_player_name() {
pacmd list-sink-inputs | grep "client: $1 " | cut -d' ' -f3-
}
spotify_cmd() {
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$1
}
mpd_cmd() {
mpc -h ~/.config/mpd/mpd.sock $1
}
toggle_player() {
case "$1" in
"<Spotify>"|"<spotify>")
spotify_cmd PlayPause
;;
"<Music Player Daemon>")
mpd_cmd toggle
;;
**)
;;
esac
}
next_player() {
case "$1" in
"<Spotify>"|"<spotify>")
spotify_cmd Next
;;
"<Music Plaer Daemon>")
mpd_cmd next
;;
**)
;;
esac
}
prev_player() {
case "$1" in
"<Spotify>"|"<spotify>")
spotify_cmd Previous
;;
"<Music Plaer Daemon>")
mpd_cmd prev
;;
**)
;;
esac
}
toggle_active() {
if [ -n "$1" ]; then
name=`get_player_name $1`
toggle_player "$name"
echo "$name" >~/.last-active-player
elif [ -f ~/.last-active-player ]; then
name=`cat ~/.last-active-player`
toggle_player "$name"
fi
}
action="$1"
active_client=
for player in `get_players`; do
if [ `get_player_state $player` != "CORKED" ]; then
active_client=$player
break
fi
done
if [ "$action" = "toggle" ]; then
toggle_active "$active_client"
elif [ -n "$active_client" ]; then
name=`get_player_name $active_client`
case "$action" in
next)
next_player "$name"
;;
prev)
prev_player "$name"
;;
**)
;;
esac
fi