summaryrefslogtreecommitdiff
path: root/nephilim/mpclient.py
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-04-30 10:05:39 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-04-30 14:31:18 +0200
commitde61cf6798d542e9433e6cef6837cdff2501a5f7 (patch)
tree1de33efed081274bb09f3cc5eb032d1f50d8e50a /nephilim/mpclient.py
parent20f70fe5bbea4b84d55376cde69ae295321ac72e (diff)
mpclient: add tagtypes, single and consume commands.
also regroup functions.
Diffstat (limited to 'nephilim/mpclient.py')
-rw-r--r--nephilim/mpclient.py88
1 files changed, 55 insertions, 33 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 620bb6a..641d03d 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -33,7 +33,8 @@ class MPClient(QtCore.QObject):
_status = {'volume' : 0, 'repeat' : 0, 'random' : 0,
'songid' : 0, 'playlist' : 0, 'playlistlength' : 0,
'time' : 0, 'length' : 0, 'xfade' : 0,
- 'updatings_db' : 0,'state' : 'stop'}
+ 'updatings_db' : 0,'state' : 'stop', 'single' : 0,
+ 'consume' : 0}
_commands = None
_timer_id = None
@@ -82,7 +83,6 @@ class MPClient(QtCore.QObject):
self._timer_id = self.startTimer(500)
self._logger.info('Successfully connected to MPD.')
return True
-
def disconnect_mpd(self):
"""Disconnect from MPD."""
self._logger.info('Disconnecting from MPD...')
@@ -103,7 +103,6 @@ class MPClient(QtCore.QObject):
self._cur_playlist = []
self._commands = []
self.emit(QtCore.SIGNAL('disconnected'))
-
def password(self, password):
"""Use the password to authenticate with MPD."""
if not self._check_command_ok('password'):
@@ -114,30 +113,25 @@ class MPClient(QtCore.QObject):
self._commands = self._retrieve(self._client.commands)
except mpd.CommandError:
logging.error('Incorrect MPD password.')
-
- def commands(self):
- """List all currently available MPD commands."""
- return self._commands
-
def is_connected(self):
"""Returns True if connected to MPD, False otherwise."""
return self._client != None
+ def status(self):
+ """Get current MPD status."""
+ return self._status
def playlist(self):
"""Returns the current playlist."""
return self._cur_playlist
-
def library(self):
"""Returns current library."""
return self._cur_lib
-
def current_song(self):
"""Returns the current playing song."""
return self._cur_song
-
- def status(self):
- """Get current MPD status."""
- return self._status
+ def is_playing(self):
+ """Returns True if MPD is playing, False otherwise."""
+ return self._status['state'] == 'play'
def update_db(self, paths = None):
"""Starts MPD database update."""
@@ -165,12 +159,35 @@ class MPClient(QtCore.QObject):
else:
self._client.disableoutput(output_id)
+ def volume(self):
+ """Get current volume."""
+ return int(self._status['volume'])
+ def set_volume(self, volume):
+ """Set volume to volume."""
+ if not self._client:
+ return self._logger.error('Not connected.')
+ try:
+ volume = min(100, max(0, volume))
+ self._client.setvol(volume)
+ except mpd.CommandError, e:
+ self._logger.error('Can\'t set volume: %s.' %('don\'t have control permissions' if 'permission' in str(e)
+ else 'unknown error'))
+
def urlhandlers(self):
"""Returns an array of available url handlers."""
if not self._client:
return []
else:
return self._client.urlhandlers()
+ def tagtypes(self):
+ """Returns a list of supported tags."""
+ if not self._check_command_ok('tagtypes'):
+ return []
+
+ return self._retrieve(self._client.tagtypes)
+ def commands(self):
+ """List all currently available MPD commands."""
+ return self._commands
def repeat(self, val):
"""Set repeat playlist to val (True/False)."""
@@ -191,9 +208,20 @@ class MPClient(QtCore.QObject):
if not self._check_command_ok('crossfade'):
return
self._client.crossfade(time)
- def is_playing(self):
- """Returns True if MPD is playing, False otherwise."""
- return self._status['state'] == 'play'
+ def single(self, val):
+ """Set single playback to val (True, False)"""
+ if not self._check_command_ok('single'):
+ return
+ if isinstance(val, bool):
+ val = 1 if val else 0
+ self._client.single(val)
+ def consume(self, val):
+ """Set consume mode to val (True, False)"""
+ if not self._check_command_ok('consume'):
+ return
+ if isinstance(val, bool):
+ val = 1 if val else 0
+ self._client.consume(val)
def play(self, id = None):
"""Play song with ID id or next song if id is None."""
@@ -270,20 +298,6 @@ class MPClient(QtCore.QObject):
i += 1
self._client.command_list_end()
- def volume(self):
- """Get current volume."""
- return int(self._status['volume'])
- def set_volume(self, volume):
- """Set volume to volume."""
- if not self._client:
- return self._logger.error('Not connected.')
- try:
- volume = min(100, max(0, volume))
- self._client.setvol(volume)
- except mpd.CommandError, e:
- self._logger.error('Can\'t set volume: %s.' %('don\'t have control permissions' if 'permission' in str(e)
- else 'unknown error'))
-
def _retrieve(self, method):
"""Makes sure only one call is made at a time to MPD."""
self._retr_mutex.lock()
@@ -326,8 +340,10 @@ class MPClient(QtCore.QObject):
if not ret:
return None
- ret['repeat'] = int(ret['repeat'])
- ret['random'] = int(ret['random'])
+ ret['repeat'] = int(ret['repeat'])
+ ret['random'] = int(ret['random'])
+ ret['single'] = int(ret['single'])
+ ret['consume'] = int(ret['consume'])
if 'time' in ret:
cur, len = ret['time'].split(':')
ret['length'] = int(len)
@@ -377,6 +393,12 @@ class MPClient(QtCore.QObject):
if self._status['random'] != old_status['random']:
self.emit(QtCore.SIGNAL('random_changed'), bool(self._status['random']))
+ if self._status['single'] != old_status['single']:
+ self.emit(QtCore.SIGNAL('single_changed'), bool(self._status['single']))
+
+ if self._status['consume'] != old_status['consume']:
+ self.emit(QtCore.SIGNAL('consume_changed'), bool(self._status['consume']))
+
if self._status['playlist'] != old_status['playlist']:
self._update_playlist()
self.emit(QtCore.SIGNAL('playlist_changed'))