ruby-mpd 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/lib/ruby-mpd/parser.rb +7 -13
- data/lib/ruby-mpd/version.rb +1 -1
- data/lib/ruby-mpd.rb +17 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65799fe0826f542ebb67a82b3041bdaf8b17aacd
|
4
|
+
data.tar.gz: 0416d81eaf92f7f559c9bfd969c11b5f519f9e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9bc49c2e0f69bdd15be62cd0676597ae0730b5e263c1f8ed6dbb7d27d9cbd2e60502c62ee981addc6b5386e32ab182845fe3173be00517ab9b721b34dde04db
|
7
|
+
data.tar.gz: f75b7368594cb02b8cfa225c57e8a27e16737562e984262059bffd8cce8740a31bcf9b33866343b89f68594790b71e5945d3972a1005eaf246e6f75bcd82a0fd
|
data/README.rdoc
CHANGED
@@ -220,7 +220,7 @@ in order to recieve those values:
|
|
220
220
|
Finally, the easiest step. In order for callbacks to work, connect to the server
|
221
221
|
with callbacks enabled:
|
222
222
|
|
223
|
-
mpd.connect true
|
223
|
+
mpd.connect(callbacks: true)
|
224
224
|
|
225
225
|
Easy as pie. The above will connect to the server like normal, but this time it will
|
226
226
|
create a new thread that loops until you issue a `disconnect`. This loop checks the
|
data/lib/ruby-mpd/parser.rb
CHANGED
@@ -107,7 +107,6 @@ class MPD
|
|
107
107
|
# Converts the response to MPD::Song objects.
|
108
108
|
# @return [Array<MPD::Song>] An array of songs.
|
109
109
|
def build_songs_list(array)
|
110
|
-
return [] if !array.is_a?(Array)
|
111
110
|
return array.map {|hash| Song.new(hash) }
|
112
111
|
end
|
113
112
|
|
@@ -132,27 +131,22 @@ class MPD
|
|
132
131
|
#
|
133
132
|
# @return [Array<Hash>, Array<String>, String, Integer] Parsed response.
|
134
133
|
def parse_response(command, string)
|
135
|
-
# return explicit array if
|
136
|
-
return RETURN_ARRAY.include?(command) ? [] : true if string
|
134
|
+
# return explicit array or true if the message is empty
|
135
|
+
return RETURN_ARRAY.include?(command) ? [] : true if string.empty?
|
137
136
|
if command == :listall
|
138
|
-
build_hash(string)
|
137
|
+
return build_hash(string)
|
139
138
|
elsif command == :listallinfo
|
140
|
-
|
141
|
-
else
|
142
|
-
build_response(command, string)
|
139
|
+
string = filter_lines(string, [:directory, :playlist])
|
143
140
|
end
|
141
|
+
|
142
|
+
build_response(command, string)
|
144
143
|
end
|
145
144
|
|
146
145
|
# Parses the response into appropriate objects (either a single object,
|
147
146
|
# or an array of objects or an array of hashes).
|
148
147
|
#
|
149
148
|
# @return [Array<Hash>, Array<String>, String, Integer] Parsed response.
|
150
|
-
def build_response(command, string
|
151
|
-
return [] if string.nil? || !string.is_a?(String)
|
152
|
-
|
153
|
-
# filter lines if filter specified
|
154
|
-
string = filter_lines(string,filter) if filter
|
155
|
-
|
149
|
+
def build_response(command, string)
|
156
150
|
chunks = make_chunks(string)
|
157
151
|
# if there are any new lines (more than one data piece), it's a hash, else an object.
|
158
152
|
is_hash = chunks.any? {|chunk| chunk.include? "\n"}
|
data/lib/ruby-mpd/version.rb
CHANGED
data/lib/ruby-mpd.rb
CHANGED
@@ -136,19 +136,32 @@ class MPD
|
|
136
136
|
# When called without any arguments, this will just connect to the server
|
137
137
|
# and wait for your commands.
|
138
138
|
#
|
139
|
-
# When called with true as an argument, this will enable callbacks by starting
|
139
|
+
# When called with +callbacks: true+ as an argument, this will enable callbacks by starting
|
140
140
|
# a seperate polling thread, which will also automatically reconnect if disconnected
|
141
141
|
# for whatever reason.
|
142
142
|
#
|
143
143
|
# @return [true] Successfully connected.
|
144
144
|
# @raise [MPDError] If connect is called on an already connected instance.
|
145
|
-
def connect(
|
145
|
+
def connect(opts = {callbacks: false})
|
146
146
|
raise ConnectionError, 'Already connected!' if self.connected?
|
147
147
|
|
148
148
|
@socket = File.exists?(@hostname) ? UNIXSocket.new(@hostname) : TCPSocket.new(@hostname, @port)
|
149
|
-
@version = @socket.gets.chomp.gsub('OK MPD ', '') # Read the version
|
150
149
|
|
151
|
-
|
150
|
+
# by protocol, we need to get a 'OK MPD <version>' reply
|
151
|
+
# should we fail to do so, the connection was unsuccessful
|
152
|
+
if response = @socket.gets
|
153
|
+
@version = response.chomp.gsub('OK MPD ', '') # Read the version
|
154
|
+
else
|
155
|
+
reset_vars
|
156
|
+
raise ConnectionError, 'Unable to connect (possibly too many connections open)'
|
157
|
+
end
|
158
|
+
|
159
|
+
if opts == true || opts == false
|
160
|
+
warn "Using 'true' or 'false' as an argument to #connect has been deprecated, and will be removed in the future!"
|
161
|
+
opts = {callbacks: opts}
|
162
|
+
end
|
163
|
+
|
164
|
+
callback_thread if opts[:callbacks]
|
152
165
|
return true
|
153
166
|
end
|
154
167
|
|
@@ -243,7 +256,6 @@ class MPD
|
|
243
256
|
end
|
244
257
|
|
245
258
|
if !error
|
246
|
-
return true if msg.empty?
|
247
259
|
return msg
|
248
260
|
else
|
249
261
|
err = error.match(/^ACK \[(?<code>\d+)\@(?<pos>\d+)\] \{(?<command>.*)\} (?<message>.+)$/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blaž Hrastnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A powerful, modern and feature complete library for the Music Player
|
14
14
|
Daemon.
|