Skip to content

Commit

Permalink
Merge pull request #8 from mamantoha/binary-response
Browse files Browse the repository at this point in the history
fetch binary
  • Loading branch information
mamantoha authored May 8, 2022
2 parents c5482cf + 3c2fe63 commit 0d74f75
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: ruby

rvm:
- 3.0.0
- 2.7.2
- 2.6.6
- 3.1.2
- 3.0.4
- 2.7.6

script:
- rspec
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# MPD::Client CHANGELOG

## 0.2.0

* Tested with Ruby 3.1
* Add `albumart` command
* Add `readpicture` command
* Remove `playlist` command. Use `playlistinfo` instead

## 0.1.0

* Rename `MPDClient` to `MPD::Client`
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gemspec
group :development, :test do
gem 'pry'
gem 'rubocop'
gem 'solargraph'
end

group :test do
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Anton Maminov
Copyright (c) 2012-2022 Anton Maminov

MIT License

Expand All @@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion MPD_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ If the optional `SUBSYSTEMS` argument is used, MPD will only send notifications
---
`mixrampdb {deciBels} => fetch_nothing`

> 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://sourceforge.net/projects/mixramp/)
> 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)
---
`mixrampdelay {SECONDS} => fetch_nothing`
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ gem install mpd_client
All functionality is contained in the `MPD::Client` class. Creating an instance of this class is as simple as:

```ruby
require 'mpd_client'

client = MPD::Client.new
```

Expand Down Expand Up @@ -64,6 +66,26 @@ client.status # insert the status command into the list
client.command_list_end # result will be a Array with the results
```

### Binary responses

Some commands can return binary data.

```ruby
require 'mpd_client'

client = MPD::Client.new
client.connect('localhost', 6600)

if (current_song = client.currentsong)
data, io = client.readpicture(current_song['file'])
io # StringIO
data # => {"size"=>"322860", "type"=>"image/jpeg", "binary"=>"3372"}
File.write('cover.jpg', io.string)
end
```

The above will locate album art for the current song and save image to `cover.jpg` file.

### Ranges

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:
Expand Down Expand Up @@ -103,7 +125,7 @@ client = MPD::Client.new
client.log = Logger.new($stderr)
```

For more information about logging configuration, see [Logger](https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html)
For more information about logging configuration, see [Logger](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)

## Development

Expand All @@ -121,6 +143,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## License and Author

Copyright (c) 2013-2018 by Anton Maminov
Copyright (c) 2012-2022 by Anton Maminov

This library is distributed under the MIT license. Please see the LICENSE file.
18 changes: 18 additions & 0 deletions examples/albumart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'bundler'
Bundler.setup :default

require 'logger'
require 'mpd_client'

# MPD::Client.log = Logger.new($stderr)

client = MPD::Client.new
client.connect('localhost', 6600)

if (current_song = client.currentsong)
data, io = client.readpicture(current_song['file'])
puts data
File.write('cover.jpg', io.string)
end
17 changes: 17 additions & 0 deletions examples/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'bundler'
Bundler.setup :default

require 'logger'
require 'mpd_client'

MPD::Client.log = Logger.new($stderr)

client = MPD::Client.new
client.connect('localhost', 6600)

puts client.stats
puts client.status
puts client.currentsong
puts client.playlistinfo
2 changes: 1 addition & 1 deletion examples/stickers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MPD::Client.log = Logger.new($stderr)

# Stickers
# http://www.musicpd.org/doc/protocol/ch03s07.html
# https://mpd.readthedocs.io/en/latest/protocol.html#stickers

client = MPD::Client.new

Expand Down
Loading

0 comments on commit 0d74f75

Please sign in to comment.