mpd_client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/MPD_COMMANDS.md ADDED
@@ -0,0 +1,578 @@
1
+ ### Status Commands
2
+
3
+ ---
4
+ `clearerror => fetch_nothing`
5
+
6
+ > Clears the current error message in status (this is also accomplished by any command that starts playback).
7
+
8
+ ---
9
+ `currentsong => fetch_object`
10
+
11
+ > Displays the song info of the current song (same song that is identified in status).
12
+
13
+ ---
14
+ `idle [SUBSYSTEMS...] => fetch_list`
15
+
16
+ > Waits until there is a noteworthy change in one or more of MPD's subsystems. As soon as there is one, it lists all changed systems in a line in the format changed: `SUBSYSTEM`, where `SUBSYSTEM` is one of the following:
17
+
18
+ > * `database`: the song database has been modified after update.
19
+ * `update`: a database update has started or finished. If the database was modified during the update, the database event is also emitted.
20
+ * `stored_playlist`: a stored playlist has been modified, renamed, created or deleted
21
+ * `playlist`: the current playlist has been modified
22
+ * `player`: the player has been started, stopped or seeked
23
+ * `mixer`: the volume has been changed
24
+ * `output`: an audio output has been enabled or disabled
25
+ * `options`: options like repeat, random, crossfade, replay gain
26
+ * `sticker`: the sticker database has been modified
27
+ * `subscription`: a client has subscribed or unsubscribed to a channel
28
+ * `message`: a message was received on a channel this client is subscribed to; this event is only emitted when the queue is empty
29
+
30
+ > While a client is waiting for `idle` results, the server disables timeouts, allowing a client to wait for events as long as mpd runs. The `idle` command can be canceled by sending the command `noidle` (no other commands are allowed). MPD will then leave `idle` mode and print results immediately; might be empty at this time.
31
+
32
+ > If the optional `SUBSYSTEMS` argument is used, MPD will only send notifications when something changed in one of the specified subsytems.
33
+
34
+ ---
35
+ `noidle`
36
+
37
+ >
38
+
39
+ ---
40
+ `status => "fetch_object`
41
+
42
+ > Reports the current status of the player and the volume level.
43
+
44
+ > * `volume`: 0-100
45
+ * `repeat`: 0 or 1
46
+ * `random`: 0 or 1
47
+ * `single`: 0 or 1
48
+ * `consume`: 0 or 1
49
+ * `playlist`: 31-bit unsigned integer, the playlist version number
50
+ * `playlistlength`: integer, the length of the playlist
51
+ * `state`: play, stop, or pause
52
+ * `song`: playlist song number of the current song stopped on or playing
53
+ * `songid`: playlist songid of the current song stopped on or playing
54
+ * `nextsong`: playlist song number of the next song to be played
55
+ * `nextsongid`: playlist songid of the next song to be played
56
+ * `time`: total time elapsed (of current playing/paused song)
57
+ * `elapsed`: Total time elapsed within the current song, but with higher resolution.
58
+ * `bitrate`: instantaneous bitrate in kbps
59
+ * `xfade`: crossfade in seconds
60
+ * `mixrampdb`: mixramp threshold in dB
61
+ * `mixrampdelay`: mixrampdelay in seconds
62
+ * `audio`: sampleRate:bits:channels
63
+ * `updating_db`: job id
64
+ * `error`: if there is an error, returns message here
65
+
66
+ ---
67
+ `stats => "fetch_object`
68
+
69
+ > Displays statistics.
70
+
71
+ > * `artists`: number of artists
72
+ * `songs`: number of albums
73
+ * `uptime`: daemon uptime in seconds
74
+ * `db_playtime`: sum of all song times in the db
75
+ * `db_update`: last db update in UNIX time
76
+ * `playtime`: time length of music played
77
+
78
+ ### Playback Option Commands
79
+
80
+ ---
81
+ `consume {STATE} => fetch_nothing`
82
+
83
+ > Sets consume state to `STATE`, `STATE` should be 0 or 1. When consume is activated, each song played is removed from playlist.
84
+
85
+ ---
86
+ `crossfade {SECONDS} => fetch_nothing`
87
+
88
+ > Sets crossfading between songs.
89
+
90
+ ---
91
+ `mixrampdb {deciBels} => fetch_nothing`
92
+
93
+ > Sets the threshold at which songs will be overlapped. Like crossfading but doesn't fade the track volume, just overlaps. The songs need to have MixRamp tags added by an external tool. 0dB is the normalized maximum volume so use negative values, I prefer -17dB. In the absence of mixramp tags crossfading will be used. See http://sourceforge.net/projects/mixramp
94
+
95
+ ---
96
+ `mixrampdelay {SECONDS} => fetch_nothing`
97
+
98
+ > Additional time subtracted from the overlap calculated by `mixrampdb`. A value of "nan" disables MixRamp overlapping and falls back to crossfading.
99
+
100
+ ---
101
+ `random {STATE} => fetch_nothing`
102
+
103
+ > Sets random state to `STATE`, `STATE` should be 0 or 1.
104
+
105
+ ---
106
+ `repeat {STATE} => fetch_nothing`
107
+
108
+ > Sets repeat state to `STATE`, `STATE` should be 0 or 1.
109
+
110
+ ---
111
+ `setvol {VOL} => fetch_nothing`
112
+
113
+ > Sets volume to `VOL`, the range of volume is 0-100.
114
+
115
+ ---
116
+ `single {STATE} => fetch_nothing`
117
+
118
+ > Sets single state to `STATE`, `STATE` should be 0 or 1. When single is activated, playback is stopped after current song, or song is repeated if the 'repeat' mode is enabled.
119
+
120
+ ---
121
+ `replay_gain_mode {MODE} => fetch_nothing`
122
+
123
+ > Sets the replay gain mode. One of `off`, `track`, `album`, `auto`.
124
+
125
+ > Changing the mode during playback may take several seconds, because the new settings does not affect the buffered data.
126
+
127
+ > This command triggers the options idle event.
128
+
129
+ ---
130
+ `replay_gain_status => fetch_item`
131
+
132
+ > Prints replay gain options. Currently, only the variable `replay_gain_mode` is returned.
133
+
134
+
135
+ ### Playback Control Commands
136
+
137
+ ---
138
+ `next => fetch_nothing`
139
+
140
+ > Plays next song in the playlist.
141
+
142
+ ---
143
+ `pause {PAUSE} => fetch_nothing`
144
+
145
+ > Toggles pause/resumes playing, `PAUSE` is 0 or 1.
146
+ > > **Note**. The use of pause command w/o the `PAUSE` argument is deprecated.
147
+
148
+ ---
149
+ `play [SONGPOS] => fetch_nothing`
150
+
151
+ > Begins playing the playlist at song number `SONGPOS`.
152
+
153
+ ---
154
+ `playid [SONGID] => fetch_nothing`
155
+
156
+ > Begins playing the playlist at song `SONGID`.
157
+
158
+ ---
159
+ `previous => fetch_nothing`
160
+
161
+ > Plays previous song in the playlist.
162
+
163
+ ---
164
+ `seek {SONGPOS} {TIME} => fetch_nothing`
165
+
166
+ > Seeks to the position `TIME` (in seconds) of entry `SONGPOS` in the playlist.
167
+
168
+ ---
169
+ `seekid {SONGID} {TIME} => fetch_nothing`
170
+
171
+ > Seeks to the position `TIME` (in seconds) of song `SONGID`.
172
+
173
+ ---
174
+ `seekcur {TIME} => fetch_nothing`
175
+
176
+ > Seeks to the position `TIME` within the current song. If prefixed by '+' or '-', then the time is relative to the current playing position.
177
+
178
+ ---
179
+ `stop => fetch_nothing`
180
+
181
+ > Stops playing.
182
+
183
+
184
+ ### Playlist Commands
185
+
186
+ ---
187
+ `add {URI} => fetch_nothing`
188
+
189
+ > Adds the file `URI` to the playlist (directories add recursively). `URI` can also be a single file.
190
+
191
+ ---
192
+ `addid {URI} [POSITION] => fetch_item`
193
+
194
+ > Adds a song to the playlist (non-recursive) and returns the song id.
195
+
196
+ > `URI` is always a single file or URL.
197
+
198
+ ---
199
+ `clear => fetch_nothing`
200
+
201
+ > Clears the current playlist.
202
+
203
+ ---
204
+ `delete [{POS} | {START:END}] => fetch_nothing`
205
+
206
+ > Deletes a song from the playlist.
207
+
208
+ ---
209
+ `deleteid {SONGID} => fetch_nothing`
210
+
211
+ > Deletes the song `SONGID` from the playlist
212
+
213
+ ---
214
+ `move [{FROM} | {START:END}] {TO} => fetch_nothing`
215
+
216
+ > Moves the song at `FROM` or range of songs at `START:END` to `TO` in the playlist.
217
+
218
+ ---
219
+ `moveid {FROM} {TO} => fetch_nothing`
220
+
221
+ > Moves the song with `FROM` (songid) to `TO` (playlist index) in the playlist. If `TO` is negative, it is relative to the current song in the playlist (if there is one).
222
+
223
+ ---
224
+ `playlist => fetch_playlist`
225
+
226
+ > Displays the current playlist.
227
+
228
+ > > **Note**: Do not use this, instead use `playlistinfo`.
229
+
230
+ ---
231
+ `playlistfind {TAG} {NEEDLE} => fetch_songs`
232
+
233
+ > Finds songs in the current playlist with strict matching.
234
+
235
+ ---
236
+ `playlistid {SONGID} => fetch_songs`
237
+
238
+ > Displays a list of songs in the playlist. `SONGID` is optional and specifies a single song to display info for.
239
+
240
+ ---
241
+ `playlistinfo [[SONGPOS] | [START:END]] => fetch_songs`
242
+
243
+ > Displays a list of all songs in the playlist, or if the optional argument is given, displays information only for the song `SONGPOS` or the range of songs `START:END`
244
+
245
+ ---
246
+ `playlistsearch {TAG} {NEEDLE} => fetch_songs`
247
+
248
+ > Searches case-sensitively for partial matches in the current playlist.
249
+
250
+ ---
251
+ `plchanges {VERSION} => fetch_songs`
252
+
253
+ > Displays changed songs currently in the playlist since `VERSION`.
254
+
255
+ > To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
256
+
257
+ ---
258
+ `plchangesposid {VERSION} => fetch_changes`
259
+
260
+ > Displays changed songs currently in the playlist since `VERSION`. This function only returns the position and the id of the changed song, not the complete metadata. This is more bandwidth efficient.
261
+
262
+ > To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
263
+
264
+ ---
265
+ `prio {PRIORITY} {START:END...} => fetch_nothing`
266
+
267
+ > Set the priority of the specified songs. A higher priority means that it will be played first when "random" mode is enabled.
268
+
269
+ > A priority is an integer between 0 and 255. The default priority of new songs is 0.
270
+
271
+ ---
272
+ `prioid {PRIORITY} {ID...} => fetch_nothing`
273
+
274
+ > Same as `prio`, but address the songs with their id.
275
+
276
+ ---
277
+ `shuffle [START:END] => fetch_nothing`
278
+
279
+ > Shuffles the current playlist. `START:END` is optional and specifies a range of songs.
280
+
281
+ ---
282
+ `swap {SONG1} {SONG2} => fetch_nothing`
283
+
284
+ > Swaps the positions of `SONG1` and `SONG2`.
285
+
286
+ ---
287
+ `swapid {SONG1} {SONG2} => fetch_nothing`
288
+
289
+ Swaps the positions of `SONG1` and `SONG2` (both song ids).
290
+
291
+ ### Stored Playlist Commands
292
+
293
+ Playlists are stored inside the configured playlist directory. They are addressed with their file name (without the directory and without the .m3u suffix).
294
+
295
+ Some of the commands described in this section can be used to run playlist plugins instead of the hard-coded simple m3u parser. They can access playlists in the music directory (relative path including the suffix) or remote playlists (absolute URI with a supported scheme).
296
+
297
+ ---
298
+ `listplaylist {NAME} => fetch_list`
299
+
300
+ > Lists the songs in the playlist. Playlist plugins are supported.
301
+
302
+ ---
303
+ `listplaylistinfo {NAME} => fetch_songs`
304
+
305
+ > Lists the songs with metadata in the playlist. Playlist plugins are supported.
306
+
307
+ ---
308
+ `listplaylists => fetch_playlists`
309
+
310
+ > Prints a list of the playlist directory.
311
+
312
+ > After each playlist name the server sends its last modification time as attribute "Last-Modified" in ISO 8601 format. To avoid problems due to clock differences between clients and the server, clients should not compare this value with their local clock.
313
+
314
+ ---
315
+ `load {NAME} [START:END] => fetch_nothing`
316
+
317
+ > Loads the playlist into the current queue. Playlist plugins are supported. A range may be specified to load only a part of the playlist.
318
+
319
+ ---
320
+ `playlistadd {NAME} {URI} => fetch_nothing`
321
+
322
+ > Adds `URI` to the playlist `NAME.m3u`.
323
+
324
+ > `NAME.m3u` will be created if it does not exist.
325
+
326
+ ---
327
+ `playlistclear {NAME} => fetch_nothing`
328
+
329
+ > Clears the playlist `NAME.m3u`.
330
+
331
+ ---
332
+ `playlistdelete {NAME} {SONGPOS} => fetch_nothing`
333
+
334
+ > Deletes `SONGPOS` from the playlist `NAME.m3u`.
335
+
336
+ ---
337
+ `playlistmove {NAME} {SONGID} {SONGPOS} => fetch_nothing`
338
+
339
+ > Moves `SONGID` in the playlist `NAME.m3u` to the position `SONGPOS`.
340
+
341
+ ---
342
+ `rename {NAME} {NEW_NAME} => fetch_nothing`
343
+
344
+ > Renames the playlist `NAME.m3u` to `NEW_NAME.m3u`.
345
+
346
+ ---
347
+ `rm {NAME} => fetch_nothing`
348
+
349
+ > Removes the playlist `NAME.m3u` from the playlist directory.
350
+
351
+ ---
352
+ `save {NAME} => fetch_nothing`
353
+
354
+ > Saves the current playlist to `NAME.m3u` in the playlist directory.
355
+
356
+ ### Database Commands
357
+
358
+ ---
359
+ `count {TAG} {NEEDLE} => fetch_object`
360
+
361
+ > Counts the number of songs and their total playtime in the db matching `TAG` exactly.
362
+
363
+ ---
364
+ `find {TYPE} {WHAT} [...] => fetch_songs`
365
+
366
+ > Finds songs in the db that are exactly `WHAT`. `TYPE` can be any tag supported by MPD, or one of the two special parameters — file to search by full path (relative to database root), and any to match against all available tags. `WHAT` is what to find.
367
+
368
+ ---
369
+ `findadd {TYPE} {WHAT} [...] => fetch_nothing`
370
+
371
+ > Finds songs in the db that are exactly `WHAT` and adds them to current playlist. Parameters have the same meaning as for find.
372
+
373
+ ---
374
+ `list {TYPE} [ARTIST] => fetch_list`
375
+
376
+ > Lists all tags of the specified type. `TYPE` can be any tag supported by MPD or file.
377
+
378
+ > `ARTIST` is an optional parameter when type is album, this specifies to list albums by an artist.
379
+
380
+ ---
381
+ `listall [URI] => fetch_database`
382
+
383
+ > Lists all songs and directories in `URI`.
384
+
385
+ ---
386
+ `listallinfo [URI] => fetch_database`
387
+
388
+ > Same as `listall`, except it also returns metadata info in the same format as `lsinfo`.
389
+
390
+ ---
391
+ `lsinfo [URI] => fetch_database`
392
+
393
+ > Lists the contents of the directory `URI`.
394
+
395
+ > When listing the root directory, this currently returns the list of stored playlists. This behavior is deprecated; use `listplaylists` instead.
396
+
397
+ > Clients that are connected via UNIX domain socket may use this command to read the tags of an arbitrary local file (`URI` beginning with "file:///").
398
+
399
+ ---
400
+ `search {TYPE} {WHAT} [...] => fetch_songs`
401
+
402
+ > Searches for any song that contains `WHAT`. Parameters have the same meaning as for find, except that search is not case sensitive.
403
+
404
+ ---
405
+ `searchadd {TYPE} {WHAT} [...] => fetch_nothing`
406
+
407
+ > Searches for any song that contains `WHAT` in tag `TYPE` and adds them to current playlist.
408
+
409
+ > Parameters have the same meaning as for `find`, except that search is not case sensitive.
410
+
411
+ ---
412
+ `searchaddpl {NAME} {TYPE} {WHAT} [...] => fetch_nothing`
413
+
414
+ > Searches for any song that contains `WHAT` in tag `TYPE` and adds them to the playlist named `NAME`.
415
+
416
+ > If a playlist by that name doesn't exist it is created.
417
+
418
+ > Parameters have the same meaning as for find, except that search is not case sensitive.
419
+
420
+ ---
421
+ `update [URI] => fetch_item`
422
+
423
+ > Updates the music database: find new files, remove deleted files, update modified files.
424
+
425
+ > `URI` is a particular directory or song/file to update. If you do not specify it, everything is updated.
426
+
427
+ > Prints "updating_db: JOBID" where JOBID is a positive number identifying the update job. You can read the current job id in the status response.
428
+
429
+ ---
430
+ `rescan [URI] => fetch_item`
431
+
432
+ > Same as `update`, but also rescans unmodified files.
433
+
434
+ ### Sticker Commands
435
+
436
+ "Stickers" are pieces of information attached to existing MPD objects (e.g. song files, directories, albums). Clients can create arbitrary name/value pairs. MPD itself does not assume any special meaning in them.
437
+
438
+ The goal is to allow clients to share additional (possibly dynamic) information about songs, which is neither stored on the client (not available to other clients), nor stored in the song files (MPD has no write access).
439
+
440
+ Client developers should create a standard for common sticker names, to ensure interoperability.
441
+
442
+ Objects which may have stickers are addressed by their object type ("song" for song objects) and their URI (the path within the database for songs).
443
+
444
+ ---
445
+ `sticker get {TYPE} {URI} {NAME} => fetch_sticker`
446
+
447
+ > Reads a sticker value for the specified object.
448
+
449
+ ---
450
+ `sticker set {TYPE} {URI} {NAME} {VALUE} => fetch_nothing`
451
+
452
+ > Adds a sticker value to the specified object. If a sticker item with that name already exists, it is replaced.
453
+
454
+ ---
455
+ `sticker delete {TYPE} {URI} [NAME] => fetch_nothing`
456
+
457
+ > Deletes a sticker value from the specified object. If you do not specify a sticker name, all sticker values are deleted.
458
+
459
+ ---
460
+ `sticker list {TYPE} {URI} => fetch_stickers`
461
+
462
+ > Lists the stickers for the specified object.
463
+
464
+ ---
465
+ `sticker find {TYPE} {URI} {NAME} => fetch_songs`
466
+
467
+ > Searches the sticker database for stickers with the specified name, below the specified directory (`URI`). For each matching song, it prints the URI and that one sticker's value.
468
+
469
+ ### Connection Commands
470
+
471
+ ---
472
+ `close`
473
+
474
+ > Closes the connection to MPD.
475
+
476
+ ---
477
+ `kill`
478
+
479
+ > Kills MPD.
480
+
481
+ ---
482
+ `password {PASSWORD} => fetch_nothing`
483
+
484
+ > This is used for authentication with the server. `PASSWORD` is simply the plaintext password.
485
+
486
+ ---
487
+ `ping => fetch_nothing`
488
+
489
+ > Does nothing but return "OK".
490
+
491
+ ## Audio Output Commands
492
+
493
+ ---
494
+ `disableoutput {ID} => fetch_nothing`
495
+
496
+ > Turns an output off.
497
+
498
+ ---
499
+ `enableoutput {ID} => fetch_nothing`
500
+
501
+ > Turns an output on.
502
+
503
+ ---
504
+ `outputs => fetch_outputs`
505
+
506
+ > Shows information about all outputs.
507
+
508
+ ### Reflection Commands
509
+
510
+ ---
511
+ `config => fetch_item`
512
+
513
+ > Dumps configuration values that may be interesting for the client. This command is only permitted to "local" clients (connected via UNIX domain socket).
514
+
515
+ > The following response attributes are available:
516
+
517
+ >
518
+ | Name | Description |
519
+ | ------------------ | ---------------------------------------- |
520
+ | music_directory | The absolute path of the music directory |
521
+
522
+ ---
523
+ `commands => fetch_list`
524
+
525
+ > Shows which commands the current user has access to.
526
+
527
+ ---
528
+ `notcommands => fetch_list`
529
+
530
+ > Shows which commands the current user does not have access to.
531
+
532
+ ---
533
+ `tagtypes => fetch_list`
534
+
535
+ > Shows a list of available song metadata.
536
+
537
+ ---
538
+ `urlhandlers => fetch_list`
539
+
540
+ > Gets a list of available URL handlers.
541
+
542
+ ---
543
+ `decoders => fetch_plugins`
544
+
545
+ > Print a list of decoder plugins, followed by their supported suffixes and MIME types.
546
+
547
+ ### Client to client
548
+
549
+ Clients can communicate with each others over "channels". A channel is created by a client subscribing to it. More than one client can be subscribed to a channel at a time; all of them will receive the messages which get sent to it.
550
+
551
+ Each time a client subscribes or unsubscribes, the global idle event subscription is generated. In conjunction with the channels command, this may be used to auto-detect clients providing additional services.
552
+
553
+ New messages are indicated by the message idle event.
554
+
555
+ ---
556
+ `subscribe {NAME} => fetch_nothing`
557
+
558
+ > Subscribe to a channel. The channel is created if it does not exist already. The name may consist of alphanumeric ASCII characters plus underscore, dash, dot and colon.
559
+
560
+ ---
561
+ `unsubscribe {NAME} => fetch_nothing`
562
+
563
+ > Unsubscribe from a channel.
564
+
565
+ ---
566
+ `channels => fetch_list`
567
+
568
+ > Obtain a list of all channels. The response is a list of "channel:" lines.
569
+
570
+ ---
571
+ `readmessages => fetch_messages`
572
+
573
+ > Reads messages for this client. The response is a list of "channel:" and "message:" lines.
574
+
575
+ ---
576
+ `sendmessage {CHANNEL} {TEXT} => fetch_nothing`
577
+
578
+ > Send a message to the specified channel.
data/README.md CHANGED
@@ -36,6 +36,12 @@ Once you have an instance of the `MPDClient` class, start by connecting to the s
36
36
  client.connect('localhost', 6600)
37
37
  ```
38
38
 
39
+ or Unix domain socket
40
+
41
+ ```ruby
42
+ client.connect('/var/run/mpd/socket')
43
+ ```
44
+
39
45
  The client library can be used as follows:
40
46
 
41
47
  ```ruby
@@ -54,6 +60,48 @@ client.status # insert the status command into the list
54
60
  client.command_list_end # result will be a Array with the results
55
61
  ```
56
62
 
63
+ ### Ranges
64
+
65
+ Some commands(e.g. `move`, `delete`, `load`, `shuffle`, `playlistinfo`) support integer ranges(`[START:END]`) as argument. This is done in `mpd_client` by using two element array:
66
+
67
+ ```ruby
68
+ # move the first three songs after the fifth number in the playlist
69
+ client.move([0, 3], 5)
70
+ ```
71
+
72
+ Second element can be omitted. MPD will assumes the biggest possible number then:
73
+
74
+ ```ruby
75
+ # delete all songs from the current playlist, except for the firts ten
76
+ client.delete([10,])
77
+ ```
78
+
79
+ ### Logging
80
+
81
+ Default logger for all MPDClient instances:
82
+
83
+ ```ruby
84
+ require 'logger'
85
+ require 'mpd_client'
86
+
87
+ MPDClient.log = Logger.new($stderr)
88
+
89
+ client = MPDClient.new
90
+ ```
91
+
92
+ Sets the logger used by this instance of MPDClient:
93
+
94
+ ```ruby
95
+ require 'logger'
96
+ require 'mpd_client'
97
+
98
+ client = MPDClient.new
99
+ client.log = Logger.new($stderr)
100
+ ```
101
+
102
+
103
+ For more information about logging configuration, see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html
104
+
57
105
  ## Contributing
58
106
 
59
107
  1. Fork it
@@ -64,4 +112,4 @@ client.command_list_end # result will be a Array with the results
64
112
 
65
113
  ## License
66
114
 
67
- This library is distributed under the MIT license. Please see the LICENSE file.
115
+ This library is distributed under the MIT license. Please see the LICENSE file.
data/examples/range.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ Bundler.setup :default
3
+
4
+ require 'pp'
5
+ require 'logger'
6
+ require 'mpd_client'
7
+
8
+ MPDClient.log = Logger.new($stderr)
9
+
10
+ client = MPDClient.new
11
+ client.connect('localhost', 6600)
12
+
13
+ # delete all songs from the current playlist, except for the firts ten
14
+ client.delete([10,])
15
+
16
+ # move the first three songs after the fifth number in the playlist
17
+ client.move([0, 3], 69)
18
+
19
+ pp client.playlistinfo([69, 71])
@@ -3,12 +3,18 @@
3
3
  require 'bundler'
4
4
  Bundler.setup :default
5
5
 
6
+ require 'logger'
6
7
  require 'mpd_client'
7
8
 
9
+ #MPDClient.log = Logger.new($stderr)
10
+
11
+ client = MPDClient.new
12
+
8
13
  type = ARGV[0]
9
14
  what = ARGV[1]
10
15
 
11
16
  client = MPDClient.new
17
+ client.log = Logger.new($stderr)
12
18
 
13
19
  # Connecting to the server
14
20
  client.connect('localhost', 6600)
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ MPDClient.log = Logger.new($stderr)
10
+
11
+ # Stickers
12
+ # http://www.musicpd.org/doc/protocol/ch03s07.html
13
+
14
+ client = MPDClient.new
15
+
16
+ # Connecting to the server
17
+ client.connect('/var/run/mpd/socket')
18
+
19
+ puts "MPD version: #{client.mpd_version}"
20
+ puts "mpd_client version: #{MPDClient::VERSION}"
21
+
22
+ uri = "world/j/Jane Air/2012.Иллюзия полёта/12. Любить любовь.ogg"
23
+
24
+ # sticker set {TYPE} {URI} {NAME} {VALUE}
25
+ # Adds a sticker value to the specified object. If a sticker item with that name already exists, it is replaced.
26
+ #
27
+ client.sticker_set('song', uri, 'rating', '1')
28
+
29
+ # sticker get {TYPE} {URI} {NAME}
30
+ # Reads a sticker value for the specified object.
31
+ #
32
+ puts client.sticker_get('song', uri, 'rating')
33
+
34
+ # sticker list {TYPE} {URI}
35
+ # Lists the stickers for the specified object.
36
+ #
37
+ puts client.sticker_list('song', uri)
38
+
39
+ # sticker find {TYPE} {URI} {NAME}
40
+ # Searches the sticker database for stickers with the specified name, below the specified directory (URI).
41
+ # For each matching song, it prints the URI and that one sticker's value.
42
+ #
43
+ puts client.sticker_find('song', '/', 'rating')
44
+
45
+ # sticker delete {TYPE} {URI} [NAME]
46
+ # Deletes a sticker value from the specified object. If you do not specify a sticker name, all sticker values are deleted.
47
+ #
48
+ client.sticker_delete('song', uri, 'rating')
49
+
50
+ client.close
51
+ client.disconnect
@@ -1,5 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  class MPDClient
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
data/lib/mpd_client.rb CHANGED
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'socket'
4
4
  require "mpd_client/version"
@@ -82,15 +82,15 @@ COMMANDS = {
82
82
  "listallinfo" => "fetch_database",
83
83
  "lsinfo" => "fetch_database",
84
84
  "search" => "fetch_songs",
85
- "searchadd" => "fetch_nothing",
86
- "searchaddp1" => "fetch_nothing",
85
+ "searchadd" => "fetch_nothing",
86
+ "searchaddp1" => "fetch_nothing",
87
87
  "update" => "fetch_item",
88
88
  "rescan" => "fetch_item",
89
89
  # Sticker Commands
90
- "sticker get" => "fetch_item",
90
+ "sticker get" => "fetch_sticker",
91
91
  "sticker set" => "fetch_nothing",
92
92
  "sticker delete" => "fetch_nothing",
93
- "sticker list" => "fetch_list",
93
+ "sticker list" => "fetch_stickers",
94
94
  "sticker find" => "fetch_songs",
95
95
  # Connection Commands
96
96
  "close" => "",
@@ -116,14 +116,46 @@ COMMANDS = {
116
116
  "sendmessage" => "fetch_nothing"
117
117
  }
118
118
 
119
+ # The MPDClient library is used for interactions with a MPD.
120
+ #
121
+ # == Example
122
+ #
123
+ # require 'mpd_client'
124
+ # require 'logger'
125
+ #
126
+ # client = MPDClient.new
127
+ # client.log = Logger.new($stderr)
128
+ # client.connect('/var/run/mpd/socket')
129
+ #
119
130
  class MPDClient
120
131
  attr_reader :mpd_version
121
132
 
133
+ class << self
134
+ # Default logger for all MPDClient instances
135
+ #
136
+ # MPDClient.log = Logger.new($stderr)
137
+ #
138
+ attr_accessor :log
139
+
140
+ def add_command(name, retval)
141
+ escaped_name = name.gsub(' ', '_')
142
+ define_method escaped_name.to_sym do |*args|
143
+ execute(name, *args, retval)
144
+ end
145
+ end
146
+
147
+ def remove_command(name)
148
+ raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym
149
+ remove_method name.to_sym
150
+ end
151
+ end
152
+
122
153
  def initialize
123
154
  reset
124
155
  end
125
156
 
126
157
  def connect(host = 'localhost', port = 6600)
158
+ log.info("MPD connect #{host}, #{port}") if log
127
159
  if host.start_with?('/')
128
160
  @socket = UNIXSocket.new(host)
129
161
  hello
@@ -134,6 +166,7 @@ class MPDClient
134
166
  end
135
167
 
136
168
  def disconnect
169
+ log.info("MPD disconnect")
137
170
  @socket.close
138
171
  reset
139
172
  end
@@ -152,17 +185,16 @@ class MPDClient
152
185
  return fetch_command_list
153
186
  end
154
187
 
155
- class << self
156
- def add_command(name, retval)
157
- define_method name.to_sym do |*args|
158
- execute(name, *args, retval)
159
- end
160
- end
188
+ # The current logger. If no logger has been set MPDClient.log is used
189
+ #
190
+ def log
191
+ @log || MPDClient.log
192
+ end
161
193
 
162
- def remove_command(name)
163
- raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym
164
- remove_method name.to_sym
165
- end
194
+ # Sets the +logger+ used by this instance of MPDClient
195
+ #
196
+ def log= logger
197
+ @log = logger
166
198
  end
167
199
 
168
200
  private
@@ -184,7 +216,15 @@ class MPDClient
184
216
 
185
217
  def write_command(command, *args)
186
218
  parts = [command]
187
- args.each{|arg| parts << "\"#{escape(arg)}\""}
219
+ args.each do |arg|
220
+ if arg.kind_of?(Array)
221
+ parts << (arg.size == 1 ? "\"#{arg[0].to_i}:\"" : "\"#{arg[0].to_i}:#{arg[1].to_i}\"")
222
+ else
223
+ parts << "\"#{escape(arg)}\""
224
+ end
225
+ end
226
+ #log.debug("Calling MPD: #{command}#{args}") if log
227
+ log.debug("Calling MPD: #{parts.join(' ')}") if log
188
228
  write_line(parts.join(' '))
189
229
  end
190
230
 
@@ -301,6 +341,19 @@ class MPDClient
301
341
  return result
302
342
  end
303
343
 
344
+ def fetch_stickers
345
+ result = []
346
+ read_pairs.each do |key, sticker|
347
+ value = sticker.split('=', 2)
348
+ raise "Could now parse sticker: #{sticker}" if value.size < 2
349
+ result << Hash[*value]
350
+ end
351
+
352
+ return result
353
+ end
354
+
355
+ def fetch_sticker; fetch_stickers[0]; end
356
+
304
357
  def fetch_command_list
305
358
  result = []
306
359
  begin
@@ -327,6 +380,7 @@ class MPDClient
327
380
  @mpd_version = nil
328
381
  @command_list = nil
329
382
  @socket = nil
383
+ @log = nil
330
384
  end
331
385
 
332
386
  def escape(text)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpd_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Yet another Ruby MPD client library
15
15
  email:
@@ -21,10 +21,13 @@ files:
21
21
  - .gitignore
22
22
  - Gemfile
23
23
  - LICENSE
24
+ - MPD_COMMANDS.md
24
25
  - README.md
25
26
  - Rakefile
26
27
  - examples/Gemfile
28
+ - examples/range.rb
27
29
  - examples/search_and_replace_playlist.rb
30
+ - examples/stickers.rb
28
31
  - lib/mpd_client.rb
29
32
  - lib/mpd_client/version.rb
30
33
  - mpd_client.gemspec
@@ -48,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
51
  version: '0'
49
52
  requirements: []
50
53
  rubyforge_project:
51
- rubygems_version: 1.8.21
54
+ rubygems_version: 1.8.25
52
55
  signing_key:
53
56
  specification_version: 3
54
57
  summary: Simple Music Player Daemon library written entirely in Ruby