From: Kaliko Jack Date: Sun, 3 Feb 2019 13:05:17 +0000 (+0100) Subject: Add albumart command X-Git-Tag: v0.4.4~4 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=a1d6fc6df18bca9a06232a77deecf241f48de92c;p=python-musicpd.git Add albumart command --- diff --git a/CHANGES.txt b/CHANGES.txt index 8838c62..e8f3380 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 albumart command Changes in 0.4.3 ---------------- diff --git a/musicpd.py b/musicpd.py index ae12e1d..aae85a5 100644 --- a/musicpd.py +++ b/musicpd.py @@ -204,7 +204,7 @@ class MPDClient: "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, @@ -502,6 +502,17 @@ class MPDClient: 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() @@ -594,7 +605,7 @@ class MPDClient: 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() diff --git a/test.py b/test.py index f197670..fdd6efa 100755 --- 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) + 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()