librmpd 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -2
- data/lib/librmpd.rb +32 -62
- metadata +2 -2
data/README
CHANGED
@@ -26,9 +26,10 @@ such as `artists` to get all artists and `songs` to get all songs.
|
|
26
26
|
All functionality is contained in the MPD class. Creating an instance of this
|
27
27
|
class is as simple as
|
28
28
|
|
29
|
-
require '
|
29
|
+
require 'rubygems'
|
30
|
+
require 'librmpd'
|
30
31
|
|
31
|
-
mpd = MPD.new
|
32
|
+
mpd = MPD.new 'localhost', 6600
|
32
33
|
|
33
34
|
Once you have an instance of the MPD class, start by connecting to the server:
|
34
35
|
|
data/lib/librmpd.rb
CHANGED
@@ -92,7 +92,8 @@ class MPD
|
|
92
92
|
# which may an empty string.
|
93
93
|
STATE_CALLBACK = 0
|
94
94
|
|
95
|
-
|
95
|
+
# CURRENT_SONG_CALLBACK: This is used to listen for changes in the current
|
96
|
+
#
|
96
97
|
# song being played by the server.
|
97
98
|
#
|
98
99
|
# The callback will always be called with a single argument, an MPD::Song
|
@@ -180,66 +181,23 @@ class MPD
|
|
180
181
|
#== Song
|
181
182
|
#
|
182
183
|
# This class is a glorified Hash used to represent a song
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
# You can access the various fields of a song (such as title) by
|
185
|
+
# either the normal hash method (song['title']) or by using
|
186
|
+
# the field as a method name (song.title).
|
187
|
+
#
|
188
|
+
# If the field doesn't exist or isn't set, nil will be returned
|
186
189
|
#
|
187
190
|
class Song < Hash
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
def album
|
201
|
-
self['album']
|
202
|
-
end
|
203
|
-
|
204
|
-
def title
|
205
|
-
self['title']
|
206
|
-
end
|
207
|
-
|
208
|
-
def track
|
209
|
-
self['track']
|
210
|
-
end
|
211
|
-
|
212
|
-
def name
|
213
|
-
self['name']
|
214
|
-
end
|
215
|
-
|
216
|
-
def genre
|
217
|
-
self['genre']
|
218
|
-
end
|
219
|
-
|
220
|
-
def date
|
221
|
-
self['date']
|
222
|
-
end
|
223
|
-
|
224
|
-
def composer
|
225
|
-
self['composer']
|
226
|
-
end
|
227
|
-
|
228
|
-
def performer
|
229
|
-
self['performer']
|
230
|
-
end
|
231
|
-
|
232
|
-
def comment
|
233
|
-
self['comment']
|
234
|
-
end
|
235
|
-
|
236
|
-
def disc
|
237
|
-
self['disc']
|
238
|
-
end
|
239
|
-
|
240
|
-
def file
|
241
|
-
self['file']
|
242
|
-
end
|
191
|
+
def method_missing(m, *a)
|
192
|
+
key = m.to_s
|
193
|
+
if key =~ /=$/
|
194
|
+
self[$`] = a[0]
|
195
|
+
elsif a.empty?
|
196
|
+
self[key]
|
197
|
+
else
|
198
|
+
raise NoMethodError, "#{m}"
|
199
|
+
end
|
200
|
+
end
|
243
201
|
end
|
244
202
|
|
245
203
|
# Initialize an MPD object with the specified hostname and port
|
@@ -267,6 +225,18 @@ class MPD
|
|
267
225
|
@callbacks[CONNECTION_CALLBACK] = []
|
268
226
|
end
|
269
227
|
|
228
|
+
# This will store the given method onto the given type's callback
|
229
|
+
# list. First you must get a reference to the method to call by
|
230
|
+
# the following:
|
231
|
+
#
|
232
|
+
# callback_method = my_object.method 'method name'
|
233
|
+
#
|
234
|
+
# Then you can call register_callback:
|
235
|
+
#
|
236
|
+
# mpd.register_callback( callback_method, MPD::STATE_CALLBACK )
|
237
|
+
#
|
238
|
+
# Now my_object's 'method name' method will be called whenever the
|
239
|
+
# state changes
|
270
240
|
def register_callback( method, type )
|
271
241
|
@callbacks[type].push method
|
272
242
|
end
|
@@ -496,8 +466,8 @@ class MPD
|
|
496
466
|
end
|
497
467
|
|
498
468
|
#
|
499
|
-
#
|
500
|
-
#
|
469
|
+
# Read the crossfade between songs in seconds,
|
470
|
+
# Raises a RuntimeError if the command failed
|
501
471
|
def crossfade
|
502
472
|
status = self.status
|
503
473
|
return if status.nil?
|
@@ -505,7 +475,7 @@ class MPD
|
|
505
475
|
end
|
506
476
|
|
507
477
|
#
|
508
|
-
# Read the
|
478
|
+
# Read the currently playing song
|
509
479
|
#
|
510
480
|
# Returns a Song object with the current song's data,
|
511
481
|
# Raises a RuntimeError if the command failed
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: librmpd
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2006-12-18 00:00:00 -05:00
|
8
8
|
summary: A library for the Music Player Daemon (MPD)
|
9
9
|
require_paths:
|
10
10
|
- lib
|