From 6d8430680bdea646cd17f27e3ec58c5f9ee1d629 Mon Sep 17 00:00:00 2001 From: kaliko jack Date: Sun, 2 Mar 2014 14:16:21 +0100 Subject: [PATCH] Fixed typo in randomfallback Update documentation --- doc/examples/all_settings.cfg | 15 +++------------ sima/lib/plugin.py | 2 +- sima/plugins/internal/randomfallback.py | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/doc/examples/all_settings.cfg b/doc/examples/all_settings.cfg index 119d7f4..3be857d 100644 --- a/doc/examples/all_settings.cfg +++ b/doc/examples/all_settings.cfg @@ -4,16 +4,6 @@ # your $XDG_CONFIG_HOME (default is $HOME/.config/sima/) # You can also call it with --config option. # -# Pay Attention: -# * Inline comment are not possible -# -# WRONG: -# host = localhost # My host -# -# OK: -# # My host -# host = localhost -# ######################################################################## ########################## MPD SECTION ################################ @@ -77,10 +67,12 @@ verbosity = info # internal = "Crop, Lastfm, RandomFallBack" # contrib = # description: Plugins list declaration. -# Optional plugin's configuration must be in its own section. +# Optional plugin's configuration lays in its own section. # For instance a "AwesomePlugin" declared here # gets its configuration from the corresponding section: # "[awesomeplugin]" +# internal plugins will look for a section named after the lower-cased name +# of the pluglin, ie. RandomFallBack → randomfallback. # # Two plugins sources are available, internal and contrib # @@ -200,5 +192,4 @@ cache = True # ####################### END OF CONFIGURATION ########################## - # vim: syntax=cfg fileencoding=utf-8 diff --git a/sima/lib/plugin.py b/sima/lib/plugin.py index 1188d45..5f70942 100644 --- a/sima/lib/plugin.py +++ b/sima/lib/plugin.py @@ -58,7 +58,7 @@ class Plugin: """ conf = self.__daemon.config for sec in conf.sections(): - if sec.lower() == self.__class__.__name__.lower(): + if sec == self.__class__.__name__.lower(): self.plugin_conf = conf[sec] #if self.plugin_conf: # self.log.debug('Got config for {0}: {1}'.format(self, diff --git a/sima/plugins/internal/randomfallback.py b/sima/plugins/internal/randomfallback.py index bb41bde..aceff44 100644 --- a/sima/plugins/internal/randomfallback.py +++ b/sima/plugins/internal/randomfallback.py @@ -31,7 +31,10 @@ from ...lib.plugin import Plugin class RandomFallBack(Plugin): - """Add random track as fallback""" + """Add random track as fallback + TODO: refactor, this plugin does not look good to me. + callback_need_track_fb/get_trk articulation is not elegant at all + """ def __init__(self, daemon): super().__init__(daemon) @@ -56,18 +59,24 @@ class RandomFallBack(Plugin): def callback_need_track_fb(self): trks = list() target = self.plugin_conf.getint('track_to_add') + limit = 0 while len(trks) < target: trk = self.get_trk() if trk: trks.append(trk) + else: + limit += 1 + if limit > 3: + return trks return trks def get_trk(self): """Get a single track acording to random flavour """ trk = None + art = None artists = list(self.player.artists) - if self.mode == 'sensitive': + if self.mode == 'sensible': played_art = self.get_played_artist() while artists: art = random.choice(artists) @@ -76,6 +85,8 @@ class RandomFallBack(Plugin): artists.pop(art) elif self.mode == 'pure': art = random.choice(artists) + if art is None: + return None self.log.debug('Random art: {}'.format(art)) trks = self.player.find_track(art) if trks: -- 2.39.2