]> kaliko git repositories - python-musicpd.git/commitdiff
Add albumart command
authorKaliko Jack <kaliko@azylum.org>
Sun, 3 Feb 2019 13:05:17 +0000 (14:05 +0100)
committerKaliko Jack <kaliko@azylum.org>
Sun, 3 Feb 2019 13:05:17 +0000 (14:05 +0100)
CHANGES.txt
musicpd.py
test.py

index 8838c6296fcbf139f8d771105709196a4c31ee78..e8f3380d49dd8959ed07bb4cbddb373b99031b89 100644 (file)
@@ -7,6 +7,7 @@ Changes in 0.4.4 UNRELEASED
 * Add partition commands (Thanks Naglis Jonaitis)
 * Add listfiles command
 * Add tagtypes (disable|enable|clear|all) commands
 * Add partition commands (Thanks Naglis Jonaitis)
 * Add listfiles command
 * Add tagtypes (disable|enable|clear|all) commands
+* Add albumart command
 
 Changes in 0.4.3
 ----------------
 
 Changes in 0.4.3
 ----------------
index ae12e1da501235b81f03846927054617795de51f..aae85a5f5348e897760cfe4248668a8b58047c68 100644 (file)
@@ -204,7 +204,7 @@ class MPDClient:
             "rm":                 self._fetch_nothing,
             "save":               self._fetch_nothing,
             # Database Commands
             "rm":                 self._fetch_nothing,
             "save":               self._fetch_nothing,
             # Database Commands
-            #"albumart":           self._fetch_object,
+            "albumart":           self._fetch_composite,
             "count":              self._fetch_object,
             "find":               self._fetch_songs,
             "findadd":            self._fetch_nothing,
             "count":              self._fetch_object,
             "find":               self._fetch_songs,
             "findadd":            self._fetch_nothing,
@@ -502,6 +502,17 @@ class MPDClient:
     def _fetch_neighbors(self):
         return self._fetch_objects(["neighbor"])
 
     def _fetch_neighbors(self):
         return self._fetch_objects(["neighbor"])
 
+    def _fetch_composite(self):
+        obj = {}
+        for key, value in self._read_pairs():
+            key = key.lower()
+            obj[key] = value
+            if key == 'binary':
+                break
+        by = self._read_line()
+        obj['data'] = by.encode(errors='surrogateescape')
+        return obj
+
     @iterator_wrapper
     def _fetch_command_list(self):
         return self._read_command_list()
     @iterator_wrapper
     def _fetch_command_list(self):
         return self._read_command_list()
@@ -594,7 +605,7 @@ class MPDClient:
             self._sock = self._connect_unix(host)
         else:
             self._sock = self._connect_tcp(host, port)
             self._sock = self._connect_unix(host)
         else:
             self._sock = self._connect_tcp(host, port)
-        self._rfile = self._sock.makefile("r", encoding='utf-8')
+        self._rfile = self._sock.makefile("r", encoding='utf-8', errors='surrogateescape')
         self._wfile = self._sock.makefile("w", encoding='utf-8')
         try:
             self._hello()
         self._wfile = self._sock.makefile("w", encoding='utf-8')
         try:
             self._hello()
diff --git a/test.py b/test.py
index f1976705e1f4525b8792859ef64bca7a7f7584ba..fdd6efa699beb76f1899d423b5e647a96a824da7 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -418,6 +418,15 @@ class TestMPDClient(unittest.TestCase):
         res = self.client.sticker_list('song', 'baz')
         self.assertEqual(['foo=bar'], res)
 
         res = self.client.sticker_list('song', 'baz')
         self.assertEqual(['foo=bar'], res)
 
+    def test_albumart(self):
+        data = bytes('\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01'
+                     '\x00\x01\x00\x00\xff\xdb\x00C\x00\x05\x03\x04',
+                     encoding='utf8')
+        data_str = data.decode(encoding='utf-8', errors='surrogateescape')
+        self.MPDWillReturn('size: 36474\n', 'binary: 8192\n',
+                           data_str+'\n', 'OK\n')
+        res = self.client.albumart('muse/Raised Fist/2002-Dedication/', 0)
+        self.assertEqual(res.get('data'), data)
 
 if __name__ == '__main__':
     unittest.main()
 
 if __name__ == '__main__':
     unittest.main()