"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,
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()
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()
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()