From 4240fefd9d393365932ff04c063cb31fc5dce85c Mon Sep 17 00:00:00 2001 From: kaliko Date: Sat, 8 Feb 2014 01:28:54 +0100 Subject: [PATCH] Integrate dynamic option in echonest plugin --- sima/lib/simaecho.py | 2 +- sima/plugins/internal/echonest.py | 16 +++++++++------- sima/utils/config.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sima/lib/simaecho.py b/sima/lib/simaecho.py index 310bff1..fbb60b0 100644 --- a/sima/lib/simaecho.py +++ b/sima/lib/simaecho.py @@ -35,7 +35,7 @@ from requests import get, Request, Timeout, ConnectionError from sima import ECH from sima.lib.meta import Artist from sima.utils.utils import getws -if len(ECH.get('apikey')) == 23: +if len(ECH.get('apikey')) == 23: # simple hack allowing imp.reload getws(ECH) # Some definitions diff --git a/sima/plugins/internal/echonest.py b/sima/plugins/internal/echonest.py index bcccff6..d5a5122 100644 --- a/sima/plugins/internal/echonest.py +++ b/sima/plugins/internal/echonest.py @@ -152,8 +152,13 @@ class EchoNest(Plugin): Look in player library for availability of similar artists in similarities """ + dynamic = self.plugin_conf.getint('dynamic') + if dynamic <= 0: + dynamic = 100 + similarity = self.plugin_conf.getint('similarity') results = list() - while len(similarities) > 0: + while (len(results) < dynamic + and len(similarities) > 0): art_pop = similarities.pop() results.extend(self.player.fuzzy_find_artist(art_pop)) return results @@ -175,10 +180,7 @@ class EchoNest(Plugin): as_artists = simaech.get_similar(artist=current) self.log.debug('Requesting EchoNest for "{0}"'.format(current)) try: - for art in as_artists: - if len(as_art) > self.plugin_conf.getint('artists'): - break - as_art.append(str(art)) + [as_art.append(str(art)) for art in as_artists] except EchoNotFound as err: self.log.warning(err) except EchoError as err: @@ -218,13 +220,13 @@ class EchoNest(Plugin): return ret_extra def get_local_similar_artists(self): - """Check against local player for similar artists fetched from last.fm + """Check against local player for similar artists fetched from echonest """ current = self.player.current self.log.info('Looking for artist similar to "{0.artist}"'.format(current)) similar = list(self.lfm_similar_artists()) if not similar: - self.log.info('Got nothing from last.fm!') + self.log.info('Got nothing from echonest!') return [] self.log.info('First five similar artist(s): {}...'.format( ' / '.join([a for a in similar[0:5]]))) diff --git a/sima/utils/config.py b/sima/utils/config.py index 42c0103..dbc29d6 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -62,7 +62,7 @@ DEFAULT_CONF = { }, 'echonest': { 'queue_mode': "track", #TODO control values - 'artists': "80", + 'dynamic': "15", 'single_album': "false", 'track_to_add': "1", 'album_to_add': "1", -- 2.39.5