Commit b90d88a37fe0c4bff1915d320af59a5fb530c865

Anton Maminov 2022-05-06T16:00:57

add readpicture

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2f47c9..cae0d04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
 
 * Tested with Ruby 3.1
 * Add `albumart` command
+* Add `readpicture` command
+
 ## 0.1.0
 
 * Rename `MPDClient` to `MPD::Client`
diff --git a/README.md b/README.md
index 2ff751e..497a285 100644
--- a/README.md
+++ b/README.md
@@ -77,9 +77,9 @@ client = MPD::Client.new
 client.connect('localhost', 6600)
 
 if (current_song = client.currentsong)
-  data, io = client.albumart(current_song['file'])
+  data, io = client.readpicture(current_song['file'])
   io # StringIO
-  data # => {"size"=>"322860", "binary"=>"3372"}
+  data # => {"size"=>"322860", "type"=>"image/jpeg", "binary"=>"3372"}
   File.write('cover.jpg', io.string)
 end
 ```
diff --git a/examples/albumart.rb b/examples/albumart.rb
index 5090ca5..6e81635 100644
--- a/examples/albumart.rb
+++ b/examples/albumart.rb
@@ -12,7 +12,7 @@ client = MPD::Client.new
 client.connect('localhost', 6600)
 
 if (current_song = client.currentsong)
-  data, io = client.albumart(current_song['file'])
+  data, io = client.readpicture(current_song['file'])
   puts data
   File.write('cover.jpg', io.string)
 end
diff --git a/lib/mpd_client.rb b/lib/mpd_client.rb
index c57b9dc..b38076e 100644
--- a/lib/mpd_client.rb
+++ b/lib/mpd_client.rb
@@ -249,6 +249,10 @@ module MPD
       fetch_binary(StringIO.new, 0, 'albumart', uri)
     end
 
+    def readpicture(uri)
+      fetch_binary(StringIO.new, 0, 'readpicture', uri)
+    end
+
     private
 
     def ensure_connected