summaryrefslogtreecommitdiff
path: root/nephilim/mpclient.py
diff options
context:
space:
mode:
Diffstat (limited to 'nephilim/mpclient.py')
-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 ""