ruby-mpd 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +42 -11
- data/Rakefile +11 -1
- data/lib/ruby-mpd.rb +15 -27
- data/lib/ruby-mpd/parser.rb +23 -26
- data/lib/ruby-mpd/plugins/database.rb +34 -4
- data/lib/ruby-mpd/plugins/information.rb +10 -10
- data/lib/ruby-mpd/plugins/playlists.rb +1 -1
- data/lib/ruby-mpd/plugins/queue.rb +39 -4
- data/lib/ruby-mpd/song.rb +3 -6
- data/lib/ruby-mpd/version.rb +1 -1
- data/ruby-mpd.gemspec +2 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97d6dfaa6b5323b36dcd22fba6c4bcd43bf562c
|
4
|
+
data.tar.gz: 5b006f249e407ff97378887b8bf60ad94035c97c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7c25979f1d9af125916c1f3072d0f5678bbe8afdb4b7c7b2c7804062cd5e154658097958418fbca579801ec441ab86e08a2b5202403fd440b6bc73cc42cd3c0
|
7
|
+
data.tar.gz: dda3e10e3c3a74433a48832178c78a25188c947ee407fb7897e0944a49f5b0d8557691bf1fd8515a2d4ff4e1487e83ec2f2fb37c581de608cb722c4da4b2582b
|
data/README.rdoc
CHANGED
@@ -45,14 +45,14 @@ via a reconnect mechanism.
|
|
45
45
|
|
46
46
|
Once connected, you can issue commands to talk to the server.
|
47
47
|
|
48
|
-
|
48
|
+
mpd.connect
|
49
49
|
|
50
|
-
|
50
|
+
mpd.play if mpd.stopped?
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
song = mpd.current_song
|
53
|
+
puts "Current Song: #{song.artist} - #{song.title}"
|
54
54
|
|
55
|
-
|
55
|
+
Command documentation can be found {here}[http://www.rubydoc.info/github/archSeer/ruby-mpd/master/MPD].
|
56
56
|
|
57
57
|
== Commands
|
58
58
|
|
@@ -98,16 +98,45 @@ Commands that support ranges: +#delete+, +#move+, +#queue+, +#song_priority+, +#
|
|
98
98
|
|
99
99
|
== Searching
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
The MPD protocol supports two commands +find+ and +search+, where +find+ is strict
|
102
|
+
and will be case sensitive, as well as return only full matches, while +search+ is
|
103
|
+
"loose" -- case insensitive and allow partial matches.
|
104
|
+
|
105
|
+
For ease of use, ruby-mpd encapsulates both +find+ and +search+ in one method,
|
106
|
+
+MPD#where+.
|
107
|
+
|
108
|
+
Searching is case *loose* by default, meaning it is case insensitive, and will do
|
109
|
+
partial matching. To enable *strict* matching, enable the +strict+ option.
|
110
|
+
|
111
|
+
This does not work for Playlist#searchadd.
|
112
|
+
|
113
|
+
mpd.where({artist: 'MyArtiSt'}, {strict: true})
|
114
|
+
|
115
|
+
Multiple query parameters can also be used:
|
116
|
+
|
117
|
+
mpd.where(artist: 'Bonobo', album: 'Black Sands')
|
103
118
|
|
104
|
-
|
119
|
+
Query keys can be any of of the tags supported by MPD (a list can be fetched via
|
120
|
+
MPD#tags), or one of the two special parameters: +:file+ to search by full path
|
121
|
+
(relative to database root), and +:any+ to match against all available tags.
|
105
122
|
|
106
123
|
While searching, one can also enable the +add+ option, which will automatically add
|
107
124
|
the songs the query returned to the queue. In that case, the response will only return
|
108
125
|
+true+, stating that the operation was successful (instead of returning an array).
|
109
126
|
|
110
|
-
mpd.
|
127
|
+
mpd.where({artist: 'MyArtiSt'}, {strict: true, add: true})
|
128
|
+
|
129
|
+
=== Queue searching
|
130
|
+
|
131
|
+
Queue searching works the same way (except by using +MPD#queue_where+), and it also
|
132
|
+
accepts multiple search parameters (which seems to be undocumented in the MPD protocol
|
133
|
+
specification).
|
134
|
+
|
135
|
+
Same as +#where+, it is "loose" by default, and it supports a +:strict+ option.
|
136
|
+
|
137
|
+
mpd.queue_where(artist: 'James Brown', genre: 'Funk')
|
138
|
+
|
139
|
+
mpd.queue_where({artist: 'James Brown', genre: 'Funk'}, {strict: true})
|
111
140
|
|
112
141
|
== Playlists
|
113
142
|
|
@@ -129,7 +158,7 @@ get your results, you simply use the object in an object-oriented way:
|
|
129
158
|
playlist.add('awesome_track.mp3')
|
130
159
|
|
131
160
|
To create a new playlist, simply create a new object. The playlist will be created
|
132
|
-
in the daemon's library automatically as soon as you use +#add+ or +#
|
161
|
+
in the daemon's library automatically as soon as you use +#add+ or +#searchadd+. There
|
133
162
|
is also no save method, as playlists get 'saved' by the daemon any time you do an
|
134
163
|
action on them (add, delete, rename).
|
135
164
|
|
@@ -262,4 +291,6 @@ for a controlled environment needs to be written.
|
|
262
291
|
|
263
292
|
* MPD::Song, MPD::Directory.
|
264
293
|
* Make stickers a mixin for Playlist, Song, Directory...
|
265
|
-
* Namespace queue
|
294
|
+
* Namespace queue
|
295
|
+
|
296
|
+
* Merge +where+ and +queue_where+, by doing +where(..., {in_queue: true})+?
|
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
|
2
3
|
Rake::TestTask.new(:test) do |test|
|
3
4
|
test.verbose = true
|
4
5
|
end
|
5
6
|
|
6
|
-
|
7
|
+
desc "Open an irb session preloaded with this API"
|
8
|
+
task :console do
|
9
|
+
$:.unshift(File.expand_path('../lib', __FILE__))
|
10
|
+
require 'ruby-mpd'
|
11
|
+
require 'irb'
|
12
|
+
ARGV.clear
|
13
|
+
IRB.start
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :test
|
data/lib/ruby-mpd.rb
CHANGED
@@ -39,8 +39,7 @@ class MPD
|
|
39
39
|
include Plugins::Reflection
|
40
40
|
include Plugins::Channels
|
41
41
|
|
42
|
-
|
43
|
-
attr_reader :version
|
42
|
+
attr_reader :version, :hostname, :port
|
44
43
|
|
45
44
|
# Initialize an MPD object with the specified hostname and port.
|
46
45
|
# When called without arguments, 'localhost' and 6600 are used.
|
@@ -86,8 +85,7 @@ class MPD
|
|
86
85
|
# @param [Proc, Method] block The actual callback.
|
87
86
|
# @return [void]
|
88
87
|
def on(event, &block)
|
89
|
-
@callbacks[event] ||= []
|
90
|
-
@callbacks[event].push block
|
88
|
+
(@callbacks[event] ||= []).push block
|
91
89
|
end
|
92
90
|
|
93
91
|
# Triggers an event, running it's callbacks.
|
@@ -95,9 +93,7 @@ class MPD
|
|
95
93
|
# @return [void]
|
96
94
|
def emit(event, *args)
|
97
95
|
return unless @callbacks[event]
|
98
|
-
@callbacks[event].each
|
99
|
-
handle.call *args
|
100
|
-
end
|
96
|
+
@callbacks[event].each { |handle| handle.call *args }
|
101
97
|
end
|
102
98
|
|
103
99
|
# Constructs a callback loop thread and/or resumes it.
|
@@ -110,21 +106,19 @@ class MPD
|
|
110
106
|
|
111
107
|
status[:connection] = mpd.connected?
|
112
108
|
|
113
|
-
status[:time]
|
114
|
-
status[:audio]
|
115
|
-
|
109
|
+
status[:time] ||= [nil, nil] # elapsed, total
|
110
|
+
status[:audio] ||= [nil, nil, nil] # samp, bits, chans
|
116
111
|
status[:song] = mpd.current_song
|
117
112
|
|
118
113
|
status.each do |key, val|
|
119
114
|
next if val == old_status[key] # skip unchanged keys
|
120
|
-
|
121
|
-
val.is_a?(Array) ? emit(key, *val) : emit(key, val)
|
115
|
+
emit key, *val # splat arrays
|
122
116
|
end
|
123
117
|
|
124
118
|
old_status = status
|
125
119
|
sleep 0.1
|
126
120
|
|
127
|
-
|
121
|
+
unless status[:connection] || Thread.current[:stop]
|
128
122
|
sleep 2
|
129
123
|
mpd.connect rescue nil
|
130
124
|
end
|
@@ -151,12 +145,11 @@ class MPD
|
|
151
145
|
|
152
146
|
# by protocol, we need to get a 'OK MPD <version>' reply
|
153
147
|
# should we fail to do so, the connection was unsuccessful
|
154
|
-
|
155
|
-
@version = response.chomp.gsub('OK MPD ', '') # Read the version
|
156
|
-
else
|
148
|
+
unless response = @socket.gets
|
157
149
|
reset_vars
|
158
150
|
raise ConnectionError, 'Unable to connect (possibly too many connections open)'
|
159
151
|
end
|
152
|
+
@version = response.chomp.gsub('OK MPD ', '') # Read the version
|
160
153
|
|
161
154
|
if callbacks
|
162
155
|
warn "Using 'true' or 'false' as an argument to MPD#connect has been deprecated, and will be removed in the future!"
|
@@ -171,10 +164,8 @@ class MPD
|
|
171
164
|
#
|
172
165
|
# @return [Boolean] True only if the server responds otherwise false.
|
173
166
|
def connected?
|
174
|
-
return false
|
175
|
-
|
176
|
-
ret = send_command(:ping) rescue false
|
177
|
-
return ret
|
167
|
+
return false unless @socket
|
168
|
+
send_command(:ping) rescue false
|
178
169
|
end
|
179
170
|
|
180
171
|
# Disconnect from the MPD daemon. This has no effect if the client is not
|
@@ -184,7 +175,7 @@ class MPD
|
|
184
175
|
def disconnect
|
185
176
|
@cb_thread[:stop] = true if @cb_thread
|
186
177
|
|
187
|
-
return false
|
178
|
+
return false unless @socket
|
188
179
|
|
189
180
|
begin
|
190
181
|
@socket.puts 'close'
|
@@ -269,12 +260,9 @@ class MPD
|
|
269
260
|
end
|
270
261
|
end
|
271
262
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
err = error.match(/^ACK \[(?<code>\d+)\@(?<pos>\d+)\] \{(?<command>.*)\} (?<message>.+)$/)
|
276
|
-
raise SERVER_ERRORS[err[:code].to_i], "[#{err[:command]}] #{err[:message]}"
|
277
|
-
end
|
263
|
+
return msg unless error
|
264
|
+
err = error.match(/^ACK \[(?<code>\d+)\@(?<pos>\d+)\] \{(?<command>.*)\} (?<message>.+)$/)
|
265
|
+
raise SERVER_ERRORS[err[:code].to_i], "[#{err[:command]}] #{err[:message]}"
|
278
266
|
end
|
279
267
|
|
280
268
|
SERVER_ERRORS = {
|
data/lib/ruby-mpd/parser.rb
CHANGED
@@ -12,25 +12,30 @@ class MPD
|
|
12
12
|
private
|
13
13
|
|
14
14
|
# Parses the command into MPD format.
|
15
|
-
def convert_command(command, *
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def convert_command(command, *params)
|
16
|
+
params.map! do |param|
|
17
|
+
case param
|
18
|
+
when true, false
|
19
|
+
param ? '1' : '0' # convert bool to 1 or 0
|
20
|
+
when Range
|
21
|
+
if param.end == -1 # negative means to end of range
|
22
|
+
"#{param.begin}:"
|
22
23
|
else
|
23
|
-
"#{
|
24
|
+
"#{param.begin}:#{param.end + (param.exclude_end? ? 0 : 1)}"
|
24
25
|
end
|
25
|
-
|
26
|
-
%Q["#{
|
26
|
+
when MPD::Song
|
27
|
+
%Q["#{param.file}"] # escape filename
|
28
|
+
when Hash # normally a search query
|
29
|
+
param.each_with_object("") do |(type, what), query|
|
30
|
+
query << %Q[#{type} "#{what}" ]
|
31
|
+
end.strip
|
27
32
|
else
|
28
33
|
# escape any strings with space (wrap in double quotes)
|
29
|
-
|
30
|
-
|
34
|
+
param = param.to_s
|
35
|
+
param.match(/\s|'/) ? %Q["#{param}"] : param
|
31
36
|
end
|
32
37
|
end
|
33
|
-
return [command,
|
38
|
+
return [command, params].join(' ').strip
|
34
39
|
end
|
35
40
|
|
36
41
|
INT_KEYS = [
|
@@ -77,7 +82,6 @@ class MPD
|
|
77
82
|
|
78
83
|
# Parses a single response line into a key-object (value) pair.
|
79
84
|
def parse_line(line)
|
80
|
-
return nil if line.nil?
|
81
85
|
key, value = line.split(/:\s?/, 2)
|
82
86
|
key = key.downcase.to_sym
|
83
87
|
return key, parse_key(key, value.chomp)
|
@@ -95,8 +99,7 @@ class MPD
|
|
95
99
|
|
96
100
|
# if val appears more than once, make an array of vals.
|
97
101
|
if hash.include? key
|
98
|
-
hash[key] = Array(hash[key])
|
99
|
-
hash[key] << object # add new obj to array
|
102
|
+
hash[key] = Array(hash[key]) << object
|
100
103
|
else # val hasn't appeared yet, map it.
|
101
104
|
hash[key] = object # map obj to key
|
102
105
|
end
|
@@ -106,7 +109,7 @@ class MPD
|
|
106
109
|
# Converts the response to MPD::Song objects.
|
107
110
|
# @return [Array<MPD::Song>] An array of songs.
|
108
111
|
def build_songs_list(array)
|
109
|
-
return array.map {|hash| Song.new(hash) }
|
112
|
+
return array.map { |hash| Song.new(hash) }
|
110
113
|
end
|
111
114
|
|
112
115
|
# Remove lines which we don't want.
|
@@ -118,11 +121,7 @@ class MPD
|
|
118
121
|
# @return [Array<String>]
|
119
122
|
def make_chunks(string)
|
120
123
|
first_key = string.match(/\A(.+?):\s?/)[1]
|
121
|
-
|
122
|
-
chunks = string.split(/\n(?=#{first_key})/)
|
123
|
-
chunks.inject([]) do |result, chunk|
|
124
|
-
result << chunk.strip
|
125
|
-
end
|
124
|
+
chunks = string.split(/\n(?=#{first_key})/).map(&:strip)
|
126
125
|
end
|
127
126
|
|
128
127
|
# Parses the response, determining per-command on what parsing logic
|
@@ -149,16 +148,14 @@ class MPD
|
|
149
148
|
def build_response(command, string)
|
150
149
|
chunks = make_chunks(string)
|
151
150
|
# if there are any new lines (more than one data piece), it's a hash, else an object.
|
152
|
-
is_hash = chunks.any? {|chunk| chunk.include? "\n"}
|
151
|
+
is_hash = chunks.any? { |chunk| chunk.include? "\n" }
|
153
152
|
|
154
153
|
list = chunks.inject([]) do |result, chunk|
|
155
154
|
result << (is_hash ? build_hash(chunk) : parse_line(chunk)[1]) # parse_line(chunk)[1] is object
|
156
155
|
end
|
157
156
|
|
158
157
|
# if list has only one element and not set to explicit array, return it, else return array
|
159
|
-
|
160
|
-
return result
|
158
|
+
(list.length == 1 && !RETURN_ARRAY.include?(command)) ? list.first : list
|
161
159
|
end
|
162
|
-
|
163
160
|
end
|
164
161
|
end
|
@@ -45,6 +45,8 @@ class MPD
|
|
45
45
|
# Searches are case insensitive by default, however you can enable
|
46
46
|
# it using the third argument.
|
47
47
|
#
|
48
|
+
# @deprecated Use {#where} instead.
|
49
|
+
#
|
48
50
|
# Options:
|
49
51
|
# * *add*: Add the search results to the queue.
|
50
52
|
# * *case_sensitive*: Make the query case sensitive.
|
@@ -56,13 +58,41 @@ class MPD
|
|
56
58
|
# @return [Array<MPD::Song>] Songs that matched.
|
57
59
|
# @return [true] if +:add+ is enabled.
|
58
60
|
def search(type, what, options = {})
|
61
|
+
warn "MPD#search is deprecated! Use MPD#where instead."
|
62
|
+
options[:strict] = options[:case_sensitive] # transparently upgrade renamed option
|
63
|
+
where({type => what}, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Searches the database for any songs that match the specified parameters.
|
67
|
+
# Searching is *loose* (case insensitive and allow partial matching) by
|
68
|
+
# default.
|
69
|
+
#
|
70
|
+
# The search keys can be any of the tags supported by MPD, or one of the
|
71
|
+
# two special parameters: +:file+ to search by full path (relative to
|
72
|
+
# database root), and +:any+ to match against all available tags.
|
73
|
+
#
|
74
|
+
# mpd.where(artist: "DJ Shadow", album: "Endtroducing.....")
|
75
|
+
#
|
76
|
+
# A hash of options can be passed as a last parameter:
|
77
|
+
#
|
78
|
+
# mpd.where({artist: "Nujabes", album: "Modal Soul"}, {add: true})
|
79
|
+
#
|
80
|
+
# Options:
|
81
|
+
# * *add*: Add search results to the queue.
|
82
|
+
# * *strict*: Search will be *case sensitive* and allow only *full matches*.
|
83
|
+
#
|
84
|
+
# @param [Hash] params A hash of search parameters.
|
85
|
+
# @param [Hash] options A hash of options.
|
86
|
+
# @return [Array<MPD::Song>] Songs that matched.
|
87
|
+
# @return [true] if +:add+ is enabled.
|
88
|
+
def where(params, options = {})
|
59
89
|
if options[:add]
|
60
|
-
command = options[:
|
90
|
+
command = options[:strict] ? :findadd : :searchadd
|
61
91
|
else
|
62
|
-
command = options[:
|
92
|
+
command = options[:strict] ? :find : :search
|
63
93
|
end
|
64
94
|
|
65
|
-
build_songs_list send_command(command,
|
95
|
+
build_songs_list send_command(command, params)
|
66
96
|
end
|
67
97
|
|
68
98
|
# Tell the server to update the database. Optionally,
|
@@ -110,7 +140,7 @@ class MPD
|
|
110
140
|
#
|
111
141
|
# @return [Array<MPD::Song>]
|
112
142
|
def songs_by_artist(artist)
|
113
|
-
|
143
|
+
where(artist: artist)
|
114
144
|
end
|
115
145
|
|
116
146
|
end
|
@@ -95,54 +95,54 @@ class MPD
|
|
95
95
|
# Is MPD paused?
|
96
96
|
# @return [Boolean]
|
97
97
|
def paused?
|
98
|
-
|
98
|
+
status[:state] == :pause
|
99
99
|
end
|
100
100
|
|
101
101
|
# Is MPD playing?
|
102
102
|
# @return [Boolean]
|
103
103
|
def playing?
|
104
|
-
|
104
|
+
status[:state] == :play
|
105
105
|
end
|
106
106
|
|
107
107
|
# @return [Boolean] Is MPD stopped?
|
108
108
|
def stopped?
|
109
|
-
|
109
|
+
status[:state] == :stop
|
110
110
|
end
|
111
111
|
|
112
112
|
# Gets the volume level.
|
113
113
|
# @return [Integer]
|
114
114
|
def volume
|
115
|
-
|
115
|
+
status[:volume]
|
116
116
|
end
|
117
117
|
|
118
118
|
# @return [Integer] Crossfade in seconds.
|
119
119
|
def crossfade
|
120
|
-
|
120
|
+
status[:xfade]
|
121
121
|
end
|
122
122
|
|
123
123
|
# @return [Integer] Current playlist version number.
|
124
124
|
def playlist_version
|
125
|
-
|
125
|
+
status[:playlist]
|
126
126
|
end
|
127
127
|
|
128
128
|
# Returns true if consume is enabled.
|
129
129
|
def consume?
|
130
|
-
|
130
|
+
status[:consume]
|
131
131
|
end
|
132
132
|
|
133
133
|
# Returns true if single is enabled.
|
134
134
|
def single?
|
135
|
-
|
135
|
+
status[:single]
|
136
136
|
end
|
137
137
|
|
138
138
|
# Returns true if random playback is currently enabled,
|
139
139
|
def random?
|
140
|
-
|
140
|
+
status[:random]
|
141
141
|
end
|
142
142
|
|
143
143
|
# Returns true if repeat is enabled,
|
144
144
|
def repeat?
|
145
|
-
|
145
|
+
status[:repeat]
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
@@ -84,6 +84,8 @@ class MPD
|
|
84
84
|
# Searches for songs in the queue matched by the what
|
85
85
|
# argument. Case insensitive by default.
|
86
86
|
#
|
87
|
+
# @deprecated Use {#queue_where} instead.
|
88
|
+
#
|
87
89
|
# @param [Symbol] type Can be any tag supported by MPD, or one of the two special
|
88
90
|
# parameters: +:file+ to search by full path (relative to database root),
|
89
91
|
# and +:any+ to match against all available tags.
|
@@ -91,8 +93,34 @@ class MPD
|
|
91
93
|
# @param [Hash] options Use +:case_sensitive+ to make the query case sensitive.
|
92
94
|
# @return [Array<MPD::Song>] Songs that matched.
|
93
95
|
def queue_search(type, what, options = {})
|
94
|
-
|
95
|
-
|
96
|
+
warn "MPD#queue_search is deprecated! Use MPD#where instead."
|
97
|
+
options[:strict] = options[:case_sensitive] # transparently upgrade renamed option
|
98
|
+
queue_where({type => what}, options)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Searches the queue for any songs that match the specified parameters.
|
102
|
+
# Searching is *loose* (case insensitive and allow partial matching) by
|
103
|
+
# default.
|
104
|
+
#
|
105
|
+
# The search keys can be any of the tags supported by MPD, or one of the
|
106
|
+
# two special parameters: +:file+ to search by full path (relative to
|
107
|
+
# database root), and +:any+ to match against all available tags.
|
108
|
+
#
|
109
|
+
# mpd.queue_where(artist: "DJ Shadow", album: "Endtroducing.....")
|
110
|
+
#
|
111
|
+
# A hash of options can be passed as a last parameter:
|
112
|
+
#
|
113
|
+
# mpd.queue_where({artist: "Nujabes", album: "Modal Soul"}, {add: true})
|
114
|
+
#
|
115
|
+
# Options:
|
116
|
+
# * *strict*: Search will be *case sensitive* and allow only *full matches*.
|
117
|
+
#
|
118
|
+
# @param [Hash] params A hash of search parameters.
|
119
|
+
# @param [Hash] options A hash of options.
|
120
|
+
# @return [Array<MPD::Song>] Songs that matched.
|
121
|
+
def queue_where(params, options = {})
|
122
|
+
command = options[:strict] ? :playlistfind : :playlistsearch
|
123
|
+
build_songs_list send_command(command, params)
|
96
124
|
end
|
97
125
|
|
98
126
|
# List the changes since the specified version in the queue.
|
@@ -105,6 +133,13 @@ class MPD
|
|
105
133
|
|
106
134
|
# Set the priority of the specified songs. A higher priority means that it will be played
|
107
135
|
# first when "random" mode is enabled.
|
136
|
+
#
|
137
|
+
# Several ranges or ID's can be specified at once:
|
138
|
+
#
|
139
|
+
# mpd.song_priority(10, [5..7, 9..10]) # songs 5 to 10, excluding 8
|
140
|
+
#
|
141
|
+
# mpd.song_priority(10, {id: [5, 8, 12]}) # songs with ID's 5, 8 and 12
|
142
|
+
#
|
108
143
|
# @param [Integer] priority An integer between 0 and 255. The default priority of new songs is 0.
|
109
144
|
# @param [Integer] pos A specific position.
|
110
145
|
# @param [Range] pos A range of positions.
|
@@ -112,12 +147,12 @@ class MPD
|
|
112
147
|
def song_priority(priority, pos)
|
113
148
|
if pos.is_a?(Hash)
|
114
149
|
if pos[:id]
|
115
|
-
send_command :prioid, priority, pos[:id]
|
150
|
+
send_command :prioid, priority, *pos[:id]
|
116
151
|
else
|
117
152
|
raise ArgumentError, 'Only :id key is allowed!'
|
118
153
|
end
|
119
154
|
else
|
120
|
-
send_command :prio, priority, pos
|
155
|
+
send_command :prio, priority, *pos
|
121
156
|
end
|
122
157
|
end
|
123
158
|
|
data/lib/ruby-mpd/song.rb
CHANGED
@@ -9,7 +9,7 @@ class MPD::Song
|
|
9
9
|
|
10
10
|
def initialize(options)
|
11
11
|
@data = {} # allowed fields are @types + :file
|
12
|
-
@time = options.delete(:time) { [nil] }.first #HAXX for array return
|
12
|
+
@time = options.delete(:time) { [nil] }.first # HAXX for array return
|
13
13
|
@file = options.delete(:file)
|
14
14
|
@title = options.delete(:title)
|
15
15
|
@artist = options.delete(:artist)
|
@@ -25,11 +25,8 @@ class MPD::Song
|
|
25
25
|
|
26
26
|
# @return [String] A formatted representation of the song length ("1:02")
|
27
27
|
def length
|
28
|
-
if @time.nil?
|
29
|
-
|
30
|
-
else
|
31
|
-
"#{(@time / 60)}:#{"%02d" % (@time % 60)}"
|
32
|
-
end
|
28
|
+
return '--:--' if @time.nil?
|
29
|
+
"#{@time / 60}:#{"%02d" % (@time % 60)}"
|
33
30
|
end
|
34
31
|
|
35
32
|
# Pass any unknown calls over to the data hash.
|
data/lib/ruby-mpd/version.rb
CHANGED
data/ruby-mpd.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = 'ruby-mpd'
|
8
8
|
s.version = MPD::VERSION
|
9
9
|
s.homepage = 'https://github.com/archSeer/ruby-mpd'
|
10
|
+
s.license = 'GPL-2'
|
10
11
|
s.authors = ["Blaž Hrastnik"]
|
11
12
|
s.email = ['speed.the.bboy@gmail.com']
|
12
13
|
s.summary = "Modern client library for MPD"
|
@@ -16,4 +17,4 @@ Gem::Specification.new do |s|
|
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
19
|
s.require_paths = ["lib"]
|
19
|
-
end
|
20
|
+
end
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blaž Hrastnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-27 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.
|
@@ -18,7 +18,7 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
22
22
|
- COPYING
|
23
23
|
- README.rdoc
|
24
24
|
- Rakefile
|
@@ -41,7 +41,8 @@ files:
|
|
41
41
|
- ruby-mpd.gemspec
|
42
42
|
- test/test_parser.rb
|
43
43
|
homepage: https://github.com/archSeer/ruby-mpd
|
44
|
-
licenses:
|
44
|
+
licenses:
|
45
|
+
- GPL-2
|
45
46
|
metadata: {}
|
46
47
|
post_install_message:
|
47
48
|
rdoc_options: []
|
@@ -49,20 +50,19 @@ require_paths:
|
|
49
50
|
- lib
|
50
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- -
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
57
|
requirements:
|
57
|
-
- -
|
58
|
+
- - ">="
|
58
59
|
- !ruby/object:Gem::Version
|
59
60
|
version: '0'
|
60
61
|
requirements: []
|
61
62
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.0
|
63
|
+
rubygems_version: 2.2.0
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Modern client library for MPD
|
66
67
|
test_files:
|
67
68
|
- test/test_parser.rb
|
68
|
-
has_rdoc:
|