-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpd_idle.rb
47 lines (44 loc) · 996 Bytes
/
mpd_idle.rb
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
class MPDIdle < EM::Connection
def initialize(common)
@common = common
end
def post_init
@common.mpd.noidle do |mpd|
song = mpd.current_song
status = mpd.status
end
end
def send_idle
send_data "idle player options mixer\n"
end
def receive_data(data)
if data =~ /changed: (.*)\n/
case $1
when 'options'
@common.mpd.noidle do |mpd|
status = mpd.status
@common.events.mpd_status.push status
end
when 'mixer'
puts "MIXER"
@common.mpd.noidle do |mpd|
volume = mpd.volume
@common.events.mpd_volume.push volume
end
when 'player'
@common.mpd.noidle do |mpd|
status = mpd.status
if status.is_a? Hash
@common.events.mpd_status.push status
else
puts "bad status"
p status
end
end
else
puts "unknown #{$1}"
end
end
send_idle
end
end