lib/mpd_client.rb in mpd_client-0.0.1 vs lib/mpd_client.rb in mpd_client-0.0.2
- old
+ new
@@ -6,11 +6,14 @@
HELLO_PREFIX = "OK MPD "
ERROR_PREFIX = "ACK "
SUCCESS = "OK"
NEXT = "list_OK"
+# MPD changelog: http://git.musicpd.org/cgit/master/mpd.git/plain/NEWS
# http://mpd.wikia.com/wiki/MusicPlayerDaemonCommands
+# http://git.musicpd.org/cgit/cirrus/mpd.git/plain/doc/protocol.xml
+#
COMMANDS = {
# Status Commands
"clearerror" => "fetch_nothing",
"currentsong" => "fetch_object",
"idle" => "fetch_list",
@@ -77,10 +80,12 @@
"list" => "fetch_list",
"listall" => "fetch_database",
"listallinfo" => "fetch_database",
"lsinfo" => "fetch_database",
"search" => "fetch_songs",
+ "searchadd" => "fetch_nothing",
+ "searchaddp1" => "fetch_nothing",
"update" => "fetch_item",
"rescan" => "fetch_item",
# Sticker Commands
"sticker get" => "fetch_item",
"sticker set" => "fetch_nothing",
@@ -117,12 +122,17 @@
def initialize
reset
end
def connect(host = 'localhost', port = 6600)
- @socket = TCPSocket.new(host, port)
- hello
+ if host.start_with?('/')
+ @socket = UNIXSocket.new(host)
+ hello
+ else
+ @socket = TCPSocket.new(host, port)
+ hello
+ end
end
def disconnect
@socket.close
reset
@@ -198,11 +208,11 @@
end
def read_pair(separator)
line = read_line
return if line.nil?
- pair = line.split(separator)
+ pair = line.split(separator, 2)
raise "Could now parse pair: '#{line}'" if pair.size < 2
return pair #Array
end
@@ -238,10 +248,12 @@
end
seen = key
end
result << value
end
+
+ return result
end
def fetch_objects(delimeters = [])
result = []
obj = {}
@@ -316,10 +328,10 @@
@command_list = nil
@socket = nil
end
def escape(text)
- text.gsub("\\", "\\\\").gsub('"', '\\"')
+ text.to_s.gsub("\\", "\\\\").gsub('"', '\\"')
end
end
COMMANDS.each_pair do |name, callback|