]> kaliko git repositories - mpd-sima.git/commitdiff
More robust randomfallback
authorkaliko jack <kaliko@azylum.org>
Sat, 1 Mar 2014 18:33:41 +0000 (19:33 +0100)
committerkaliko jack <kaliko@azylum.org>
Sat, 1 Mar 2014 18:33:41 +0000 (19:33 +0100)
sima/plugins/internal/randomfallback.py

index e6bd78be91821d36d36362751ae4233b0f9b5e2e..bb41bde933df9b6b9e51f892f915b9bdc38fd68a 100644 (file)
@@ -57,24 +57,30 @@ class RandomFallBack(Plugin):
         trks = list()
         target = self.plugin_conf.getint('track_to_add')
         while len(trks) < target:
-            trks.append(self.get_trk())
+            trk = self.get_trk()
+            if trk:
+                trks.append(trk)
         return trks
 
     def get_trk(self):
         """Get a single track acording to random flavour
         """
+        trk = None
         artists = list(self.player.artists)
         if self.mode == 'sensitive':
             played_art = self.get_played_artist()
-            while 42:
+            while artists:
                 art = random.choice(artists)
                 if art not in played_art:
                     break
+                artists.pop(art)
         elif self.mode == 'pure':
             art = random.choice(artists)
         self.log.debug('Random art: {}'.format(art))
-        trk = random.choice(self.player.find_track(art))
-        self.log.info('random fallback ({}): {}'.format(self.mode, trk))
+        trks = self.player.find_track(art)
+        if trks:
+            trk = random.choice(trks)
+            self.log.info('random fallback ({}): {}'.format(self.mode, trk))
         return trk