]> kaliko git repositories - mpd-sima.git/commitdiff
Integrate dynamic option in echonest plugin
authorkaliko <efrim@azylum.org>
Sat, 8 Feb 2014 00:28:54 +0000 (01:28 +0100)
committerkaliko <efrim@azylum.org>
Sat, 8 Feb 2014 13:11:43 +0000 (14:11 +0100)
sima/lib/simaecho.py
sima/plugins/internal/echonest.py
sima/utils/config.py

index 310bff110fc9558f925de5b28f4ca55beee38026..fbb60b07fb973305beec2aa2a5a168ca7db8f0ca 100644 (file)
@@ -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
index bcccff62eda46d4f0b35a04e316b84cb31733437..d5a5122d8c2c7a12d709fc8e5ac68a3b1a856a2c 100644 (file)
@@ -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]])))
index 42c010329c2ab12e80ce8dab1022beb694def9c9..dbc29d691b40b93c93dddeead3ddb02062048568 100644 (file)
@@ -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",