X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fclient.py;h=641fa22166f106ff2adfa32611223e783b091c71;hb=5fe20b6caffe162afe5be18e77fe40004d00c95e;hp=e19a5aafdabbdce12ad18e747eb5d8c16e5f83ea;hpb=1cc879f39941fc302f9a841a532c9f749797cca4;p=mpd-sima.git diff --git a/sima/client.py b/sima/client.py index e19a5aa..641fa22 100644 --- a/sima/client.py +++ b/sima/client.py @@ -26,6 +26,7 @@ class PlayerError(Exception): class PlayerCommandError(PlayerError): """Command error""" +PlayerUnHandledError = MPDError class PlayerClient(Player): """MPC Client @@ -91,6 +92,13 @@ class PlayerClient(Player): return Track(**ans) return ans + def __skipped_track(self, old_curr): + if (self.state == 'stop' + or not hasattr(old_curr, 'id') + or not hasattr(self.current, 'id')): + return False + return (self.current.id != old_curr.id) # pylint: disable=no-member + def find_track(self, artist, title=None): #return getattr(self, 'find')('artist', artist, 'title', title) if title: @@ -108,18 +116,14 @@ class PlayerClient(Player): return self.find('artist', artist, 'album', album) def monitor(self): + curr = self.current try: self._client.send_idle('database', 'playlist', 'player', 'options') select([self._client], [], [], 60) - return self._client.fetch_idle() - except (MPDError, IOError) as err: - raise PlayerError("Couldn't init idle: %s" % err) - - def idle(self): - try: - self._client.send_idle('database', 'playlist', 'player', 'options') - select([self._client], [], [], 60) - return self._client.fetch_idle() + ret = self._client.fetch_idle() + if self.__skipped_track(curr): + ret.append('skipped') + return ret except (MPDError, IOError) as err: raise PlayerError("Couldn't init idle: %s" % err) @@ -134,6 +138,7 @@ class PlayerClient(Player): def current(self): return self.currentsong() + @property def playlist(self): """ Override deprecated MPD playlist command @@ -192,7 +197,6 @@ class PlayerClient(Player): # If that fails, don't worry, just ignore it and disconnect except (MPDError, IOError): pass - try: self._client.disconnect() # Disconnecting failed, so use a new client object instead