mpd_client 0.0.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.hound.yml +2 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +21 -6
- data/Gemfile +12 -0
- data/LICENSE +2 -2
- data/MPD_COMMANDS.md +41 -45
- data/README.md +46 -15
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/examples/Gemfile +3 -1
- data/examples/albumart.rb +18 -0
- data/examples/client.rb +17 -0
- data/examples/idle.rb +27 -0
- data/examples/range.rb +6 -4
- data/examples/rangeid.rb +5 -3
- data/examples/search_and_replace_playlist.rb +6 -6
- data/examples/stickers.rb +10 -8
- data/lib/mpd_client/version.rb +5 -3
- data/lib/mpd_client.rb +449 -347
- data/mpd_client.gemspec +20 -12
- data/spec/mpd_client/mpd_client_spec.rb +17 -0
- data/spec/spec_helper.rb +8 -0
- metadata +42 -14
- data/Rakefile +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f6e3b14a951fdfbd9467155757083aff2fa275945363cf137e813dfce3e80ab
|
4
|
+
data.tar.gz: ce2ae51be7986266b0ad1978e76e5714ca6a4937d29bbeec905c295fedaa8960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0b9ab125796173047fe37d4ddcd1885f1381bb3b9723da38c6999e385a457d72f064d3ec400ac62c5a58c2674386a872da392b997688402a662ddbad4cf638a
|
7
|
+
data.tar.gz: 7d690dfbb506809875c63b534431bbb5658acf3b48855357087350d1856ddd21f0e21475697790917998d7b0e99d24fc588144172fa605a9d53829896f4d9f6e
|
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Max: 120
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ModuleLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# TODO FIXME
|
20
|
+
Metrics/CyclomaticComplexity:
|
21
|
+
Max: 7
|
22
|
+
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 8
|
25
|
+
|
26
|
+
Security/Eval:
|
27
|
+
Exclude:
|
28
|
+
- 'lib/mpd_client.rb'
|
29
|
+
|
30
|
+
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,29 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# MPD::Client CHANGELOG
|
2
2
|
|
3
|
-
|
3
|
+
## 0.2.0
|
4
|
+
|
5
|
+
* Tested with Ruby 3.1
|
6
|
+
* Add `albumart` command
|
7
|
+
* Add `readpicture` command
|
8
|
+
* Remove `playlist` command. Use `playlistinfo` instead
|
9
|
+
|
10
|
+
## 0.1.0
|
11
|
+
|
12
|
+
* Rename `MPDClient` to `MPD::Client`
|
13
|
+
|
14
|
+
## 0.0.6
|
15
|
+
|
16
|
+
* Fixed readcomments command
|
17
|
+
|
18
|
+
## 0.0.5
|
4
19
|
|
5
20
|
* Support for mount, umount, listmounts, listneighbors
|
6
21
|
* Support for listfiles
|
7
22
|
* Support for rangeid, addtagid, cleartagid
|
8
23
|
|
9
|
-
|
24
|
+
## 0.0.4
|
10
25
|
|
11
26
|
* Added support for readcomments, toggleoutput, volume
|
12
27
|
* Added a mutex protecting execution of MPD commands
|
13
28
|
* Automatic reconnect after the server dropped the connection
|
14
29
|
|
15
|
-
|
30
|
+
## 0.0.3
|
16
31
|
|
17
32
|
* Support for logging
|
18
33
|
* Better support for fetching stickers from MPD
|
19
34
|
* Fixed sticker commands
|
20
35
|
* Add support for ranges
|
21
36
|
|
22
|
-
|
37
|
+
## 0.0.2
|
23
38
|
|
24
39
|
* Support for connecting to unix domain sockets
|
25
40
|
* Fixed some bugs
|
26
41
|
|
27
|
-
|
42
|
+
## 0.0.1
|
28
43
|
|
29
44
|
* Porting code from mpd-python2
|
data/Gemfile
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in mpd_client.gemspec
|
4
6
|
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'pry'
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'solargraph'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rspec'
|
16
|
+
end
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Anton Maminov
|
1
|
+
Copyright (c) 2012-2022 Anton Maminov
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MPD_COMMANDS.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# MPD Commands
|
2
|
+
|
1
3
|
* [Status Commands](#status-commands)
|
2
4
|
* [Playback Option Commands](#playback-option-commands)
|
3
5
|
* [Playback Control Commands](#playback-control-commands)
|
@@ -10,7 +12,7 @@
|
|
10
12
|
* [Reflection Commands](#reflection-commands)
|
11
13
|
* [Client to client](#client-to-client)
|
12
14
|
|
13
|
-
|
15
|
+
## Status Commands
|
14
16
|
|
15
17
|
---
|
16
18
|
`clearerror => fetch_nothing`
|
@@ -27,7 +29,7 @@
|
|
27
29
|
|
28
30
|
> 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:
|
29
31
|
|
30
|
-
|
32
|
+
* `database`: the song database has been modified after update.
|
31
33
|
* `update`: a database update has started or finished. If the database was modified during the update, the database event is also emitted.
|
32
34
|
* `stored_playlist`: a stored playlist has been modified, renamed, created or deleted
|
33
35
|
* `playlist`: the current playlist has been modified
|
@@ -39,21 +41,19 @@
|
|
39
41
|
* `subscription`: a client has subscribed or unsubscribed to a channel
|
40
42
|
* `message`: a message was received on a channel this client is subscribed to; this event is only emitted when the queue is empty
|
41
43
|
|
42
|
-
|
44
|
+
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.
|
43
45
|
|
44
|
-
|
46
|
+
If the optional `SUBSYSTEMS` argument is used, MPD will only send notifications when something changed in one of the specified subsytems.
|
45
47
|
|
46
48
|
---
|
47
49
|
`noidle`
|
48
50
|
|
49
|
-
>
|
50
|
-
|
51
51
|
---
|
52
52
|
`status => "fetch_object`
|
53
53
|
|
54
54
|
> Reports the current status of the player and the volume level.
|
55
55
|
|
56
|
-
|
56
|
+
* `volume`: 0-100
|
57
57
|
* `repeat`: 0 or 1
|
58
58
|
* `random`: 0 or 1
|
59
59
|
* `single`: 0 or 1
|
@@ -80,14 +80,14 @@
|
|
80
80
|
|
81
81
|
> Displays statistics.
|
82
82
|
|
83
|
-
|
83
|
+
* `artists`: number of artists
|
84
84
|
* `songs`: number of albums
|
85
85
|
* `uptime`: daemon uptime in seconds
|
86
86
|
* `db_playtime`: sum of all song times in the db
|
87
87
|
* `db_update`: last db update in UNIX time
|
88
88
|
* `playtime`: time length of music played
|
89
89
|
|
90
|
-
|
90
|
+
## Playback Option Commands
|
91
91
|
|
92
92
|
---
|
93
93
|
`consume {STATE} => fetch_nothing`
|
@@ -102,7 +102,7 @@
|
|
102
102
|
---
|
103
103
|
`mixrampdb {deciBels} => fetch_nothing`
|
104
104
|
|
105
|
-
> 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
|
105
|
+
> 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 [mixramp](https://mpd.readthedocs.io/en/latest/user.html?highlight=mixramp#mixramp)
|
106
106
|
|
107
107
|
---
|
108
108
|
`mixrampdelay {SECONDS} => fetch_nothing`
|
@@ -134,9 +134,9 @@
|
|
134
134
|
|
135
135
|
> Sets the replay gain mode. One of `off`, `track`, `album`, `auto`.
|
136
136
|
|
137
|
-
|
137
|
+
Changing the mode during playback may take several seconds, because the new settings does not affect the buffered data.
|
138
138
|
|
139
|
-
|
139
|
+
This command triggers the options idle event.
|
140
140
|
|
141
141
|
---
|
142
142
|
`replay_gain_status => fetch_item`
|
@@ -148,7 +148,7 @@
|
|
148
148
|
|
149
149
|
> Changes volume by amount `CHANGE`.
|
150
150
|
|
151
|
-
|
151
|
+
## Playback Control Commands
|
152
152
|
|
153
153
|
---
|
154
154
|
`next => fetch_nothing`
|
@@ -196,8 +196,7 @@
|
|
196
196
|
|
197
197
|
> Stops playing.
|
198
198
|
|
199
|
-
|
200
|
-
### Playlist Commands ###
|
199
|
+
## Playlist Commands
|
201
200
|
|
202
201
|
---
|
203
202
|
`add {URI} => fetch_nothing`
|
@@ -209,7 +208,7 @@
|
|
209
208
|
|
210
209
|
> Adds a song to the playlist (non-recursive) and returns the song id.
|
211
210
|
|
212
|
-
|
211
|
+
`URI` is always a single file or URL.
|
213
212
|
|
214
213
|
---
|
215
214
|
`clear => fetch_nothing`
|
@@ -240,7 +239,6 @@
|
|
240
239
|
`playlist => fetch_playlist`
|
241
240
|
|
242
241
|
> Displays the current playlist.
|
243
|
-
|
244
242
|
> > **Note**: Do not use this, instead use `playlistinfo`.
|
245
243
|
|
246
244
|
---
|
@@ -268,21 +266,21 @@
|
|
268
266
|
|
269
267
|
> Displays changed songs currently in the playlist since `VERSION`.
|
270
268
|
|
271
|
-
|
269
|
+
To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
|
272
270
|
|
273
271
|
---
|
274
272
|
`plchangesposid {VERSION} => fetch_changes`
|
275
273
|
|
276
274
|
> 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.
|
277
275
|
|
278
|
-
|
276
|
+
To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
|
279
277
|
|
280
278
|
---
|
281
279
|
`prio {PRIORITY} {START:END...} => fetch_nothing`
|
282
280
|
|
283
281
|
> Set the priority of the specified songs. A higher priority means that it will be played first when "random" mode is enabled.
|
284
282
|
|
285
|
-
|
283
|
+
A priority is an integer between 0 and 255. The default priority of new songs is 0.
|
286
284
|
|
287
285
|
---
|
288
286
|
`prioid {PRIORITY} {ID...} => fetch_nothing`
|
@@ -319,7 +317,7 @@
|
|
319
317
|
|
320
318
|
> Removes `TAG` from the specified `SONGID`. If `TAG` is not specified, then all tag values will be removed. Editing song tags is only possible for remote songs.
|
321
319
|
|
322
|
-
|
320
|
+
## Stored Playlist Commands
|
323
321
|
|
324
322
|
Playlists are stored inside the configured playlist directory. They are addressed with their file name (without the directory and without the .m3u suffix).
|
325
323
|
|
@@ -340,7 +338,7 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
340
338
|
|
341
339
|
> Prints a list of the playlist directory.
|
342
340
|
|
343
|
-
|
341
|
+
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.
|
344
342
|
|
345
343
|
---
|
346
344
|
`load {NAME} [START:END] => fetch_nothing`
|
@@ -352,7 +350,7 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
352
350
|
|
353
351
|
> Adds `URI` to the playlist `NAME.m3u`.
|
354
352
|
|
355
|
-
|
353
|
+
`NAME.m3u` will be created if it does not exist.
|
356
354
|
|
357
355
|
---
|
358
356
|
`playlistclear {NAME} => fetch_nothing`
|
@@ -384,7 +382,7 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
384
382
|
|
385
383
|
> Saves the current playlist to `NAME.m3u` in the playlist directory.
|
386
384
|
|
387
|
-
|
385
|
+
## Database Commands
|
388
386
|
|
389
387
|
---
|
390
388
|
`count {TAG} {NEEDLE} => fetch_object`
|
@@ -406,7 +404,7 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
406
404
|
|
407
405
|
> Lists all tags of the specified type. `TYPE` can be any tag supported by MPD or file.
|
408
406
|
|
409
|
-
|
407
|
+
`ARTIST` is an optional parameter when type is album, this specifies to list albums by an artist.
|
410
408
|
|
411
409
|
---
|
412
410
|
`listall [URI] => fetch_database`
|
@@ -423,14 +421,14 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
423
421
|
|
424
422
|
> Lists the contents of the directory `URI`, including files are not recognized by `MPD`. `URI` can be a path relative to the music directory or an `URI` understood by one of the storage plugins. The response contains at least one line for each directory entry with the prefix `"file: "` or `"directory: "`, and may be followed by file attributes such as `"Last-Modified"` and `"size"`.
|
425
423
|
|
426
|
-
|
424
|
+
For example, `smb://SERVER` returns a list of all shares on the given SMB/CIFS server; `nfs://servername/path` obtains a directory listing from the NFS server.
|
427
425
|
|
428
426
|
---
|
429
427
|
`lsinfo [URI] => fetch_database`
|
430
428
|
|
431
429
|
> Lists the contents of the directory `URI`.
|
432
430
|
|
433
|
-
|
431
|
+
When listing the root directory, this currently returns the list of stored playlists. This behavior is deprecated; use `listplaylists` instead.
|
434
432
|
|
435
433
|
> 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:///").
|
436
434
|
|
@@ -444,25 +442,25 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
444
442
|
|
445
443
|
> Searches for any song that contains `WHAT` in tag `TYPE` and adds them to current playlist.
|
446
444
|
|
447
|
-
|
445
|
+
Parameters have the same meaning as for `find`, except that search is not case sensitive.
|
448
446
|
|
449
447
|
---
|
450
448
|
`searchaddpl {NAME} {TYPE} {WHAT} [...] => fetch_nothing`
|
451
449
|
|
452
450
|
> Searches for any song that contains `WHAT` in tag `TYPE` and adds them to the playlist named `NAME`.
|
453
451
|
|
454
|
-
|
452
|
+
If a playlist by that name doesn't exist it is created.
|
455
453
|
|
456
|
-
|
454
|
+
Parameters have the same meaning as for find, except that search is not case sensitive.
|
457
455
|
|
458
456
|
---
|
459
457
|
`update [URI] => fetch_item`
|
460
458
|
|
461
459
|
> Updates the music database: find new files, remove deleted files, update modified files.
|
462
460
|
|
463
|
-
|
461
|
+
`URI` is a particular directory or song/file to update. If you do not specify it, everything is updated.
|
464
462
|
|
465
|
-
|
463
|
+
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.
|
466
464
|
|
467
465
|
---
|
468
466
|
`rescan [URI] => fetch_item`
|
@@ -474,11 +472,11 @@ Some of the commands described in this section can be used to run playlist plugi
|
|
474
472
|
|
475
473
|
> Read "comments" (i.e. key-value pairs) from the file specified by `URI`. This `URI` can be a path relative to the music directory or a URL in the form `file:///foo/bar.ogg`.
|
476
474
|
|
477
|
-
|
475
|
+
The response consists of lines in the form "KEY: VALUE". Comments with suspicious characters (e.g. newlines) are ignored silently.
|
478
476
|
|
479
|
-
|
477
|
+
The meaning of these depends on the codec, and not all decoder plugins support it. For example, on Ogg files, this lists the Vorbis comments.
|
480
478
|
|
481
|
-
|
479
|
+
## Mounts and neighbors
|
482
480
|
|
483
481
|
A "storage" provides access to files in the directory tree. The most basic storage plugin is a "local" storage plugin which accesses the local file system, and there are plugins to access NFS and SMB servers.
|
484
482
|
|
@@ -504,7 +502,7 @@ Multiple storages can be "mounted" together, similar to the `mount` command on m
|
|
504
502
|
|
505
503
|
> Queries a list of "neighbors" (e.g. accessible file servers on the local net). Items on that list may be used with the `mount` command.
|
506
504
|
|
507
|
-
|
505
|
+
## Sticker Commands
|
508
506
|
|
509
507
|
"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.
|
510
508
|
|
@@ -539,7 +537,7 @@ Objects which may have stickers are addressed by their object type ("song" for s
|
|
539
537
|
|
540
538
|
> 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.
|
541
539
|
|
542
|
-
|
540
|
+
## Connection Commands
|
543
541
|
|
544
542
|
---
|
545
543
|
`close`
|
@@ -583,20 +581,18 @@ Objects which may have stickers are addressed by their object type ("song" for s
|
|
583
581
|
|
584
582
|
> Turns an output on or off, depending on the current state.
|
585
583
|
|
586
|
-
|
587
|
-
### Reflection Commands ###
|
584
|
+
## Reflection Commands
|
588
585
|
|
589
586
|
---
|
590
587
|
`config => fetch_item`
|
591
588
|
|
592
589
|
> Dumps configuration values that may be interesting for the client. This command is only permitted to "local" clients (connected via UNIX domain socket).
|
593
590
|
|
594
|
-
|
591
|
+
The following response attributes are available:
|
595
592
|
|
596
|
-
|
597
|
-
|
|
598
|
-
|
|
599
|
-
| music_directory | The absolute path of the music directory |
|
593
|
+
| Name | Description |
|
594
|
+
| --- | --- |
|
595
|
+
| music_directory | The absolute path of the music directory |
|
600
596
|
|
601
597
|
---
|
602
598
|
`commands => fetch_list`
|
@@ -623,7 +619,7 @@ Objects which may have stickers are addressed by their object type ("song" for s
|
|
623
619
|
|
624
620
|
> Print a list of decoder plugins, followed by their supported suffixes and MIME types.
|
625
621
|
|
626
|
-
|
622
|
+
## Client to client
|
627
623
|
|
628
624
|
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.
|
629
625
|
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# MPD::Client
|
2
|
+
|
3
|
+
[![Build Status](https://badgen.net/travis/mamantoha/mpd_client)](https://travis-ci.org/mamantoha/mpd_client)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/mpd_client.svg)](https://badge.fury.io/rb/mpd_client)
|
2
5
|
|
3
6
|
Yet another Music Player Daemon (MPD) client library written entirely in Ruby.
|
4
7
|
`mpd_client` is a Ruby port of the [python-mpd](https://github.com/Mic92/python-mpd2) library.
|
@@ -13,24 +16,27 @@ gem 'mpd_client'
|
|
13
16
|
|
14
17
|
And then execute:
|
15
18
|
|
16
|
-
```
|
17
|
-
|
19
|
+
```console
|
20
|
+
bundle
|
18
21
|
```
|
19
22
|
|
20
23
|
Or install it yourself as:
|
21
24
|
|
22
|
-
```
|
23
|
-
|
25
|
+
```console
|
26
|
+
gem install mpd_client
|
24
27
|
```
|
25
28
|
|
26
29
|
## Usage
|
27
|
-
|
30
|
+
|
31
|
+
All functionality is contained in the `MPD::Client` class. Creating an instance of this class is as simple as:
|
28
32
|
|
29
33
|
```ruby
|
30
|
-
|
34
|
+
require 'mpd_client'
|
35
|
+
|
36
|
+
client = MPD::Client.new
|
31
37
|
```
|
32
38
|
|
33
|
-
Once you have an instance of the `
|
39
|
+
Once you have an instance of the `MPD::Client` class, start by connecting to the server:
|
34
40
|
|
35
41
|
```ruby
|
36
42
|
client.connect('localhost', 6600)
|
@@ -60,6 +66,26 @@ client.status # insert the status command into the list
|
|
60
66
|
client.command_list_end # result will be a Array with the results
|
61
67
|
```
|
62
68
|
|
69
|
+
### Binary responses
|
70
|
+
|
71
|
+
Some commands can return binary data.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
require 'mpd_client'
|
75
|
+
|
76
|
+
client = MPD::Client.new
|
77
|
+
client.connect('localhost', 6600)
|
78
|
+
|
79
|
+
if (current_song = client.currentsong)
|
80
|
+
data, io = client.readpicture(current_song['file'])
|
81
|
+
io # StringIO
|
82
|
+
data # => {"size"=>"322860", "type"=>"image/jpeg", "binary"=>"3372"}
|
83
|
+
File.write('cover.jpg', io.string)
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
The above will locate album art for the current song and save image to `cover.jpg` file.
|
88
|
+
|
63
89
|
### Ranges
|
64
90
|
|
65
91
|
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:
|
@@ -78,29 +104,34 @@ client.delete([10,])
|
|
78
104
|
|
79
105
|
### Logging
|
80
106
|
|
81
|
-
Default logger for all
|
107
|
+
Default logger for all MPD::Client instances:
|
82
108
|
|
83
109
|
```ruby
|
84
110
|
require 'logger'
|
85
111
|
require 'mpd_client'
|
86
112
|
|
87
|
-
|
113
|
+
MPD::Client.log = Logger.new($stderr)
|
88
114
|
|
89
|
-
client =
|
115
|
+
client = MPD::Client.new
|
90
116
|
```
|
91
117
|
|
92
|
-
Sets the logger used by this instance of
|
118
|
+
Sets the logger used by this instance of MPD::Client:
|
93
119
|
|
94
120
|
```ruby
|
95
121
|
require 'logger'
|
96
122
|
require 'mpd_client'
|
97
123
|
|
98
|
-
client =
|
124
|
+
client = MPD::Client.new
|
99
125
|
client.log = Logger.new($stderr)
|
100
126
|
```
|
101
127
|
|
128
|
+
For more information about logging configuration, see [Logger](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)
|
129
|
+
|
130
|
+
## Development
|
131
|
+
|
132
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
102
133
|
|
103
|
-
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
104
135
|
|
105
136
|
## Contributing
|
106
137
|
|
@@ -112,6 +143,6 @@ For more information about logging configuration, see http://www.ruby-doc.org/st
|
|
112
143
|
|
113
144
|
## License and Author
|
114
145
|
|
115
|
-
Copyright (c)
|
146
|
+
Copyright (c) 2012-2022 by Anton Maminov
|
116
147
|
|
117
148
|
This library is distributed under the MIT license. Please see the LICENSE file.
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mpd_client'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/examples/Gemfile
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup :default
|
5
|
+
|
6
|
+
require 'logger'
|
7
|
+
require 'mpd_client'
|
8
|
+
|
9
|
+
# MPD::Client.log = Logger.new($stderr)
|
10
|
+
|
11
|
+
client = MPD::Client.new
|
12
|
+
client.connect('localhost', 6600)
|
13
|
+
|
14
|
+
if (current_song = client.currentsong)
|
15
|
+
data, io = client.readpicture(current_song['file'])
|
16
|
+
puts data
|
17
|
+
File.write('cover.jpg', io.string)
|
18
|
+
end
|
data/examples/client.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup :default
|
5
|
+
|
6
|
+
require 'logger'
|
7
|
+
require 'mpd_client'
|
8
|
+
|
9
|
+
MPD::Client.log = Logger.new($stderr)
|
10
|
+
|
11
|
+
client = MPD::Client.new
|
12
|
+
client.connect('localhost', 6600)
|
13
|
+
|
14
|
+
puts client.stats
|
15
|
+
puts client.status
|
16
|
+
puts client.currentsong
|
17
|
+
puts client.playlistinfo
|
data/examples/idle.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup :default
|
5
|
+
|
6
|
+
require 'logger'
|
7
|
+
require 'mpd_client'
|
8
|
+
|
9
|
+
client = MPD::Client.new
|
10
|
+
|
11
|
+
client = MPD::Client.new
|
12
|
+
client.log = Logger.new($stderr)
|
13
|
+
|
14
|
+
client.connect('localhost', 6600)
|
15
|
+
|
16
|
+
# Lists all changed systems:
|
17
|
+
# database, update, stored_playlist, playlist, player, mixer, output, options, sticker, subscription, message
|
18
|
+
#
|
19
|
+
subsystems = %w[player playlist]
|
20
|
+
|
21
|
+
loop do
|
22
|
+
resp = client.idle(*subsystems)
|
23
|
+
puts resp
|
24
|
+
end
|
25
|
+
|
26
|
+
client.close
|
27
|
+
client.disconnect
|