-def blocklist(album=False, track=False):
- # pylint: disable=C0111,W0212
- field = (album, track)
-
- def decorated(func):
- def wrapper(*args, **kwargs):
- if not args[0].database:
- return func(*args, **kwargs)
- cls = args[0]
- boolgen = (bl for bl in field)
- bl_fun = (cls.database.get_bl_album,
- cls.database.get_bl_track,)
- #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 = list()
- for elem in func(*args, **kwargs):
- if bl_getter(elem, add=False):
- #cls.log.debug('Blacklisted "{0}"'.format(elem))
- continue
- if track and cls.database.get_bl_album(elem, add=False):
- # filter album as well in track mode
- # (artist have already been)
- cls.log.debug('Album "%s" in blocklist', elem)
- continue
- results.append(elem)
- return results
- return wrapper
- return decorated
-
-