X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fplugins%2Finternal%2Flastfm.py;h=28bb3a42a075bef56ac740105443ef1e2465e353;hb=47ec78a3de8e2280849ec3ab70df3371514bf0ac;hp=1b9ae41798cd39c46efc940f16eb77d99340a2f6;hpb=8ce90ac30d1daa9bcf2ced0aa06c8c59302f71ca;p=mpd-sima.git diff --git a/sima/plugins/internal/lastfm.py b/sima/plugins/internal/lastfm.py index 1b9ae41..28bb3a4 100644 --- a/sima/plugins/internal/lastfm.py +++ b/sima/plugins/internal/lastfm.py @@ -7,7 +7,6 @@ Fetching similar artists from last.fm web services import random from collections import deque -from itertools import dropwhile from hashlib import md5 # third parties components @@ -37,36 +36,6 @@ def cache(func): return wrapper -def blacklist(artist=False, album=False, track=False): - #pylint: disable=C0111,W0212 - field = (artist, album, track) - def decorated(func): - def wrapper(*args, **kwargs): - cls = args[0] - boolgen = (bl for bl in field) - bl_fun = (cls._Plugin__daemon.sdb.get_bl_artist, - cls._Plugin__daemon.sdb.get_bl_album, - cls._Plugin__daemon.sdb.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__)) - if artist: - results = func(*args, **kwargs) - for elem in results: - if bl_getter(elem, add_not=True): - cls.log.info('Blacklisted: {0}'.format(elem)) - results.remove(elem) - return results - if track: - for elem in args[1]: - if bl_getter(elem, add_not=True): - cls.log.info('Blacklisted: {0}'.format(elem)) - args[1].remove(elem) - return func(*args, **kwargs) - return wrapper - return decorated - - class Lastfm(Plugin): """last.fm similar artists """ @@ -175,7 +144,6 @@ class Lastfm(Plugin): ' / '.join(art_not_in_hist))) return art_not_in_hist - @blacklist(artist=True) @cache def get_artists_from_player(self, similarities): """ @@ -267,13 +235,14 @@ class Lastfm(Plugin): ret = self.get_artists_from_player(similar) ret_extra = None if len(self.history) >= 2: - ret_extra = self.get_recursive_similar_artist() + if self.plugin_conf.getint('depth') > 1: + ret_extra = self.get_recursive_similar_artist() + if ret_extra: + ret = list(set(ret) | set(ret_extra)) if not ret: self.log.warning('Got nothing from music library.') self.log.warning('Try running in debug mode to guess why...') return [] - if ret_extra: - ret = list(set(ret) | set(ret_extra)) self.log.info('Got {} artists in library'.format(len(ret))) self.log.info(' / '.join(ret)) # Move around similars items to get in unplayed|not recently played @@ -297,7 +266,13 @@ class Lastfm(Plugin): for artist in artists: self.log.info('Looking for an album to add for "%s"...' % artist) albums = self.player.find_albums(artist) + # str conversion while Album type is not propagated + albums = [ str(album) for album in albums] + if albums: + self.log.debug('Albums candidate: {0:s}'.format(' / '.join(albums))) + else: continue # albums yet in history for this artist + albums = set(albums) albums_yet_in_hist = albums & self._get_album_history(artist=artist) albums_not_in_hist = list(albums - albums_yet_in_hist) # Get to next artist if there are no unplayed albums @@ -308,10 +283,6 @@ class Lastfm(Plugin): random.shuffle(albums_not_in_hist) for album in albums_not_in_hist: tracks = self.player.find_album(artist, album) - if tracks and self.sdb.get_bl_album(tracks[0], add_not=True): - self.log.info('Blacklisted album: "%s"' % album) - self.log.debug('using track: "%s"' % tracks[0]) - continue # Look if one track of the album is already queued # Good heuristic, at least enough to guess if the whole album is # already queued.