# 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 ################################
# 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
#
#
####################### END OF CONFIGURATION ##########################
-
# vim: syntax=cfg fileencoding=utf-8
"""
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,
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)
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)
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: