X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fclient.py;h=9eae523bd574e209d5e0c7ff8459e532b90d9370;hb=d62b8c3db5a87accb40a49d0347255bfe467911b;hp=3d10c483d326edf36b4c391f5a9010d74e52cf9e;hpb=e8bcefbcb4a56e111af402bdb705436f42cc93e0;p=mpd-sima.git diff --git a/sima/client.py b/sima/client.py index 3d10c48..9eae523 100644 --- a/sima/client.py +++ b/sima/client.py @@ -66,16 +66,17 @@ def blacklist(artist=False, album=False, track=False): #bl_getter = next(fn for fn, bl in zip(bl_fun, boolgen) if bl is True) bl_getter = next(dropwhile(lambda _: not next(boolgen), bl_fun)) #cls.log.debug('using {0} as bl filter'.format(bl_getter.__name__)) - results = func(*args, **kwargs) - for elem in results: + results = list() + for elem in func(*args, **kwargs): if bl_getter(elem, add_not=True): - cls.log.info('Blacklisted: {0}'.format(elem)) - results.remove(elem) + cls.log.debug('Blacklisted "{0}"'.format(elem)) + continue if track and cls.database.get_bl_album(elem, add_not=True): # filter album as well in track mode # (artist have already been) - cls.log.info('Blacklisted: {0}'.format(elem)) - results.remove(elem) + cls.log.debug('Blacklisted alb. "{0.album}"'.format(elem)) + continue + results.append(elem) return results return wrapper return decorated @@ -95,7 +96,7 @@ class PlayerClient(Player): TODO: handle exception in command not going through _client_wrapper() (ie. remove…) """ - database = None # sima database (history, blaclist) + database = None # sima database (history, blacklist) def __init__(self, host="localhost", port="6600", password=None): super().__init__() @@ -169,6 +170,7 @@ class PlayerClient(Player): } self._cache['artists'] = frozenset(self._client.list('artist')) + @blacklist(track=True) def find_track(self, artist, title=None): #return getattr(self, 'find')('artist', artist, 'title', title) if title: @@ -286,9 +288,9 @@ class PlayerClient(Player): def monitor(self): curr = self.current try: - self._client.send_idle('database', 'playlist', 'player', 'options') + self.send_idle('database', 'playlist', 'player', 'options') select([self._client], [], [], 60) - ret = self._client.fetch_idle() + ret = self.fetch_idle() if self.__skipped_track(curr): ret.append('skipped') if 'database' in ret: @@ -297,8 +299,16 @@ class PlayerClient(Player): except (MPDError, IOError) as err: raise PlayerError("Couldn't init idle: %s" % err) + def clean(self): + """Clean blocking event (idle) and pending commands + """ + if 'idle' in self._client._pending: + self._client.noidle() + elif self._client._pending: + self.log.warning('pending commands: {}'.format(self._client._pending)) + def remove(self, position=0): - self._client.delete(position) + self.delete(position) def add(self, track): """Overriding MPD's add method to accept add signature with a Track @@ -311,7 +321,7 @@ class PlayerClient(Player): @property def state(self): - return str(self._client.status().get('state')) + return str(self.status().get('state')) @property def current(self):