From e7c403d3131449c2701ee252e5b97eda3dbc9d81 Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 3 Nov 2019 18:17:05 +0100 Subject: [PATCH] Add options for album mode (closes #28) * Allow limiting numbers of tracks to queue from an album * Allow shuffling album tracks Thanks: sacha --- data/man/mpd_sima.cfg.5.xml | 12 +++++++++--- doc/Changelog | 2 ++ doc/examples/all_settings.cfg | 13 +++++++++++++ sima/lib/webserv.py | 13 +++++++++++-- sima/utils/config.py | 11 +++++++---- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/data/man/mpd_sima.cfg.5.xml b/data/man/mpd_sima.cfg.5.xml index 8481c4c..678e4de 100644 --- a/data/man/mpd_sima.cfg.5.xml +++ b/data/man/mpd_sima.cfg.5.xml @@ -374,9 +374,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ and queue modes. This is actually an upper limit, min(, - ) will be used, and - might be inferior lower - than value set in config. + ) will be used. @@ -386,6 +384,14 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ queue modes. + + 0 + + How many track(s) to add from each selected albums. Only relevant in + queue modes. When set to 0 or lower the whole album is queued. + + + True diff --git a/doc/Changelog b/doc/Changelog index 69be666..6fd8125 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,8 @@ MPD_sima v0.15.2 UNRELEASED * Fixed sqlite sqlite3.OperationalError VACUUM Error cf. https://bugs.python.org/issue28518 + * Add option to queue a chosen number of tracks from an album (closes #28) + * Add option to shuffle tracks in album mode (Thanks Sacha) -- kaliko jack diff --git a/doc/examples/all_settings.cfg b/doc/examples/all_settings.cfg index a720375..2551f34 100644 --- a/doc/examples/all_settings.cfg +++ b/doc/examples/all_settings.cfg @@ -193,6 +193,19 @@ track_to_add = 1 # description: how many albums the plugin will try to get album_to_add = 1 +## TRACK_TO_ADD_FROM_ALBUM +# type: integer +# scope: "album" queue mode +# description: how many tracks from one album the plugin will try to get +# defaults to 0 to queue the whole album +track_to_add_from_album = 0 + +## SHUFFLE_ALBUM +# type: boolean +# scope: "album" queue mode +# description: should the tracks of the album be shuffled +shuffle_album = false + ## CACHE # type: boolean # description: whether or not to use on-disk persistent http cache diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index 2ff88d2..9800b92 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2015 Jack Kaliko +# Copyright (c) 2009-2019 Jack Kaliko +# Copyright (c) 2019 sacha # # This file is part of sima # @@ -344,7 +345,15 @@ class WebService(Plugin): continue self.log.info('%s album candidate: %s - %s', self.ws.name, artist, album_to_queue) nb_album_add += 1 - self.to_add.extend(self.player.find_album(artist, album_to_queue)) + candidates = self.player.find_album(artist, album_to_queue) + if self.plugin_conf.getboolean('shuffle_album'): + random.shuffle(candidates) + # this allows to select a maximum number of track from the album + # a value of 0 (default) means keep all + nbtracks = self.plugin_conf.getint('track_to_add_from_album') + if nbtracks > 0: + candidates = candidates[0:nbtracks] + self.to_add.extend(candidates) if nb_album_add == target_album_to_add: return True diff --git a/sima/utils/config.py b/sima/utils/config.py index b21b1f9..488eec1 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2011, 2013, 2014, 2015 Jack Kaliko +# Copyright (c) 2009, 2010, 2011, 2013, 2014, 2015, 2019 Jack Kaliko +# Copyright (c) 2019 sacha # # This file is part of sima # @@ -57,7 +58,7 @@ DEFAULT_CONF = { 'single_disable_queue': "true", 'mopidy_compat': "false", }, - 'daemon':{ + 'daemon': { 'daemon': False, 'pidfile': "", }, @@ -70,17 +71,19 @@ DEFAULT_CONF = { 'priority': 0, }, 'lastfm': { - 'queue_mode': "track", #TODO control values + 'queue_mode': "track", # TODO control values 'max_art': 10, 'single_album': "false", 'track_to_add': 1, 'album_to_add': 1, + 'shuffle_album': False, + 'track_to_add_from_album': 0, # <=0 means keep all 'depth': 1, 'cache': True, 'priority': 100, }, 'random': { - 'flavour': "sensible", # in pure, sensible + 'flavour': "sensible", # in pure, sensible 'track_to_add': 1, 'priority': 50, }, -- 2.39.2