summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2010-11-27 21:38:16 +0100
committerAnton Khirnov <anton@khirnov.net>2011-09-04 20:17:34 +0200
commit1be3cf6c6118eb39fe65f4e7848f2037f135ff33 (patch)
treed84192938a7c9a46897b8e2e0fc1feb113b75708
parent2c32e72bfdeee82b55d38ca79b38ab9c847b3bd3 (diff)
mpclient: add functions for manipulating stickers
-rw-r--r--nephilim/mpclient.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 6a98a96..104e62c 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -362,6 +362,26 @@ class MPClient(QtCore.QObject):
"""
self._command('seekid', self.status['songid'], time)
+ ## stickers ##
+ def sticker_list(self, song, callback):
+ """
+ Get a list of stickers for specified song. callback is called with an
+ iterator over (key, value) tuples as argument.
+ """
+ self._command('sticker', 'list', 'song', song, callback = lambda data: callback(self._parse_stickers(data)))
+ def sticker_set(self, song, key, value):
+ """
+ Set a sticker associated with song.
+ """
+ self._command('sticker', 'set', 'song', song, key, value)
+ def sticker_get(self, song, key, callback):
+ """
+ Get a sticker with the given key associated with song.
+ Callback is called with the sticker's value as argument.
+ """
+ self._command('sticker', 'get', 'song', song, key,
+ callback = lambda data: callback(self._parse_sticker(data)), report_errors = False)
+
#### PRIVATE ####
## connection functions ##
@@ -622,3 +642,25 @@ class MPClient(QtCore.QObject):
for song in self._parse_objects(data, ['file', 'directory']):
if 'file' in song:
yield Song(song)
+
+ def _parse_stickers(self, data):
+ """
+ Parse a list of stickers -- output of sticker list.
+ Yields (key, value) tuples.
+ """
+ for sticker in self._parse_list(data):
+ parts = sticker.partition('=')
+ if not parts[1]:
+ self._logger.error('Malformed sticker: %s.'%sticker)
+ continue
+ yield (parts[0], parts[2])
+ def _parse_sticker(self, data):
+ """
+ Parse a single sticker -- output of sticker get.
+ Returns the sticker's value.
+ """
+ sticker = list(self._parse_list(data))
+ try:
+ return sticker[0].partition('=')[2]
+ except IndexError:
+ return ""