-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpd.rb
executable file
·62 lines (55 loc) · 1.07 KB
/
mpd.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'ruby-mpd'
class MPD
def idle(*subsystems)
self.send_command('idle',*subsystems)
end
def async_idle
raise ConnectionError, "Not connected to the server!" if !@socket
@mutex.synchronize do
begin
@socket.puts convert_command('idle', 'mixer')
rescue Errno::EPIPE
reconnect
retry
end
end
end
def noidle
@idle_lock ||= Mutex.new
EM.defer do
@idle_lock.synchronize do
self.send_command 'noidle'
begin
yield self
rescue MPD::ServerArgumentError => e
p e
rescue MPD::NotPlaying => e
p e
end
self.async_idle
end
end
end
def noidle_sync
@idle_lock ||= Mutex.new
@idle_lock.synchronize do
self.send_command 'noidle'
begin
yield self
rescue MPD::ServerArgumentError => e
p e
rescue MPD::NotPlaying => e
p e
end
self.async_idle
end
end
class Song
def as_json
{title: title, artist: artist, album: album}
end
def to_json(*a)
as_json.to_json(*a)
end
end
end