X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fclient.py;h=9d6100535f93e880d1792ce4aa6c74847ecdfd69;hb=e09e76d41b2f041de935e9e884009e3187005ab9;hp=331c02c29bdef31e686a51ecf4a7c1a277b7d5a5;hpb=c73d03627448ae3015c2143e2c7629971ff5b326;p=mpd-sima.git diff --git a/sima/client.py b/sima/client.py index 331c02c..9d61005 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,16 +116,25 @@ 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() + 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) def remove(self, position=0): self._client.delete(position) + def add(self, track): + """Overriding MPD's add method to accept add signature with a Track + object""" + self._client.add(track.file) + @property def state(self): return str(self._client.status().get('state')) @@ -126,6 +143,12 @@ class PlayerClient(Player): def current(self): return self.currentsong() + @property + def queue(self): + plst = self.playlist + plst.reverse() + return [ trk for trk in plst if int(trk.pos) > int(self.current.pos)] + @property def playlist(self): """ @@ -166,7 +189,7 @@ class PlayerClient(Player): raise PlayerError("Could not connect to '%s': " "error with password command: %s" % (self._host, err)) - # Controls we have sufficient rights for MPD_sima + # Controls we have sufficient rights needed_cmds = ['status', 'stats', 'add', 'find', \ 'search', 'currentsong', 'ping']