X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fwebserv.py;h=0a04ddb5c505ae69464285d75aaf9209e70cca9b;hb=64f927d489fa6f0edfe47e9c6105198c7f2a1c89;hp=d7fb6faa4558219d1046942328ea6e7f4882b33e;hpb=6402445cb58902ab23298df19c020bd453914048;p=mpd-sima.git diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index d7fb6fa..0a04ddb 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2014 Jack Kaliko +# Copyright (c) 2009-2015 Jack Kaliko # # This file is part of sima # @@ -168,7 +168,7 @@ class WebService(Plugin): results.append(res) return results - def ws_similar_artists(self, artist=None): + def ws_similar_artists(self, artist): """ Retrieve similar artists from WebServive. """ @@ -179,9 +179,13 @@ class WebService(Plugin): try: [as_art.append(art) for art in as_artists] except WSNotFound as err: - if artist.mbid: - return self.ws_similar_artists(Artist(name=artist.name)) self.log.warning('{}: {}'.format(self.ws.name, err)) + if artist.mbid: + self.log.debug('Trying without MusicBrainzID') + try: + return self.ws_similar_artists(Artist(name=artist.name)) + except WSNotFound as err: + self.log.debug('{}: {}'.format(self.ws.name, err)) except WSError as err: self.log.warning('{}: {}'.format(self.ws.name, err)) if as_art: @@ -207,7 +211,7 @@ class WebService(Plugin): continue extra_arts.append(trk.Artist) depth += 1 - self.log.info('EXTRA ARTS: {}'.format( + self.log.debug('EXTRA ARTS: {}'.format( '/'.join(map(str, extra_arts)))) for artist in extra_arts: self.log.debug('Looking for artist similar ' @@ -217,11 +221,11 @@ class WebService(Plugin): continue ret_extra.extend(self.get_artists_from_player(similar)) - if ret_extra: - self.log.debug('similar artist(s) fond: {}...'.format( - ' / '.join(map(str, ret_extra)))) if last_trk.Artist in ret_extra: ret_extra.remove(last_trk.Artist) + if ret_extra: + self.log.debug('similar artist(s) found: {}'.format( + ' / '.join(map(str, MetaContainer(ret_extra))))) return ret_extra def get_local_similar_artists(self): @@ -240,6 +244,11 @@ class WebService(Plugin): ' / '.join(map(str, list(similar)[:5])))) self.log.info('Looking availability in music library') ret = MetaContainer(self.get_artists_from_player(similar)) + if ret: + self.log.debug('regular found in library: {}'.format( + ' / '.join(map(str, ret)))) + else: + self.log.debug('Got nothing similar from library!') ret_extra = None if len(self.history) >= 2: if self.plugin_conf.getint('depth') > 1: @@ -247,17 +256,18 @@ class WebService(Plugin): if ret_extra: # get them reorg to pick up best element ret_extra = self._get_artists_list_reorg(ret_extra) - # pickup half the number of ret artist - ret_extra = MetaContainer(ret_extra[:len(ret)//2]) - self.log.debug('Using extra: {}'.format( - ' / '.join(map(str, ret_extra)))) + # tries to pickup less artist from extra art + if len(ret) < 4: + ret_extra = MetaContainer(ret_extra) + else: + ret_extra = MetaContainer(ret_extra[:max(4, len(ret))//2]) + if ret_extra: + self.log.debug('extra found in library: {}'.format( + ' / '.join(map(str, ret_extra)))) ret = ret | ret_extra if not ret: self.log.warning('Got nothing from music library.') return [] - # WARNING: - # * operation on set will not match against aliases - # * composite set w/ mbid set and whitout won't match either queued_artists = MetaContainer([trk.Artist for trk in self.player.queue]) if ret & queued_artists: self.log.debug('Removing already queued artists: ' @@ -334,7 +344,6 @@ class WebService(Plugin): self.to_add = list() nbtracks_target = self.plugin_conf.getint('track_to_add') for artist in artists: - artist = Artist(name=artist) if len(self.to_add) == nbtracks_target: return True self.log.info('Looking for a top track for {0}'.format(artist))