From: kaliko Date: Fri, 14 Feb 2014 20:23:56 +0000 (+0100) Subject: Improved RandomFallBack and update documentation X-Git-Tag: mpd-sima/0.12.0pr4~23 X-Git-Url: http://git.kaliko.me/?a=commitdiff_plain;h=ce32823ab9d41112d989f4543432926eb38487e6;p=mpd-sima.git Improved RandomFallBack and update documentation --- diff --git a/doc/examples/all_settings.cfg b/doc/examples/all_settings.cfg index 7eb0f24..047ee3c 100644 --- a/doc/examples/all_settings.cfg +++ b/doc/examples/all_settings.cfg @@ -79,8 +79,8 @@ verbosity = info # description: Plugins list declaration. # Optional plugin's configuration must be in its own section. # For instance a "AwesomePlugin" declared here -# gets its configuration from an "[AwesomePlugin]" -# or "[awesomeplugin]" section (case insensitive). +# gets its configuration from the corresponding section: +# "[awesomeplugin]" # # Two plugins sources are available, internal and contrib # @@ -122,6 +122,7 @@ queue_length = 1 key = Value [crop] +## CONSUME # type: integer # default: unset, not cropping playlist # description: How many played tracks to keep in the playlist. @@ -129,7 +130,8 @@ key = Value # Leave commented to keep all tracks #consume = 10 -[RandomFallback] +[randomfallback] +## FLAVOUR # type: string # default: sensible # description: When no similar tracks are found, falling back to random @@ -138,11 +140,21 @@ key = Value # * pure: complete random choice among all tracks available in the # player media library # * sensible: use play history to filter chosen tracks -# * genre: chose among the same genre as current track (using genre +# * genre: # NOT IMPLEMENTED # +# chose among the same genre as current track (using genre # tag). If no genre tag is available "sensible" flavour # is used instead #flavour=sensible +## TRACK_TO_ADD +# type: integer +# description: how many tracks the plugin will try to get +# default: 1 +#track_to_add = 1 + + +# EchoNest or LastFM +#[echonest] [lastfm] ## QUEUE_MODE # NOT COMPLETED # # type: string @@ -153,19 +165,12 @@ key = Value # album : Will queue whole album from similar artists. queue_mode = track -## SIMILARITY -# type: integer in [0 100] -# description: Similarity as a percentage of similarity between artists -# (this is a last.fm metric) -similarity = 15 - -## DYNAMIC +## MAX_ART # type: integer # description: Number of similar artist to retrieve from local media library. # When set to something superior to zero, MPD_sima tries to get as much similar -# artists from media library provided artists similarity is superior to -# similarity value. -dynamic = 10 +# artists from media library +max_art = 10 ## DEPTH # type: integer in [1, +∞] @@ -176,7 +181,8 @@ depth = 1 ## SINGLE_ALBUM # type: boolean # scope: "track" and "top" queue modes -# description: Prevent from queueing a track from the same album (for instance with OST). +# description: Prevent from queueing a track from the same album (for instance +# with OST). single_album = false ## TRACK_TO_ADD diff --git a/sima/core.py b/sima/core.py index d7a6136..0aaebec 100644 --- a/sima/core.py +++ b/sima/core.py @@ -49,9 +49,7 @@ class Sima(Daemon): try: self.player.connect() except (PlayerError, PlayerUnHandledError) as err: - self.log.error('Fails to connect player: {}'.format(err)) - self.shutdown() - sys.exit(1) + self.log.warning('Player: {}'.format(err)) self.short_history = deque(maxlen=60) def __get_player(self): diff --git a/sima/plugins/internal/randomfallback.py b/sima/plugins/internal/randomfallback.py index 12673de..cb19f49 100644 --- a/sima/plugins/internal/randomfallback.py +++ b/sima/plugins/internal/randomfallback.py @@ -32,6 +32,7 @@ from ...lib.track import Track class RandomFallBack(Plugin): + """Add random track as fallback""" def __init__(self, daemon): super().__init__(daemon) @@ -39,9 +40,9 @@ class RandomFallBack(Plugin): if not self.plugin_conf: return self.mode = self.plugin_conf.get('flavour', None) - if self.mode not in ['pure', 'sensible', 'genre']: + if self.mode not in ['pure', 'sensible']: self.log.warning('Bad value for flavour, ' - '{} not in ["pure", "sensible", "genre"]'.format(self.mode)) + '"{}" not in ["pure", "sensible"]'.format(self.mode)) self.mode = 'pure' def get_played_artist(self,): @@ -54,17 +55,26 @@ class RandomFallBack(Plugin): return set(artists) def callback_need_track_fb(self): - art = random.choice(self.player.list('artist')) - self.log.debug('Random art: {}'.format(art)) + trks = list() + target = self.plugin_conf.getint('track_to_add') + while len(trks) < target: + trks.append(self.get_trk()) + return trks + + def get_trk(self): + artists = list(self.player.artists) if self.mode == 'sensitive': played_art = self.get_played_artist() while 42: - art = random.choice(self.player.list('artist')) + art = random.choice(artists) if art not in played_art: break + 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)) - return [trk] + return trk diff --git a/sima/utils/config.py b/sima/utils/config.py index c425642..da66366 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -76,7 +76,7 @@ DEFAULT_CONF = { 'depth': "1", }, 'randomfallback': { - 'flavour': "sensible", # in pure, sensible, genre + 'flavour': "sensible", # in pure, sensible 'track_to_add': "1", } }