X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fplugins%2Finternal%2Ftags.py;h=9000c37cf6fa3af52a09222b5b776354efa247c7;hb=abd0ec90f9ae6ea8eae2bc1515fcc8358bb6d4c9;hp=cd1a4fe3bbdf91660c8be23a2c15d5e304bd4b29;hpb=29cca9ed73ed4bd87b909398ccc80bceddc89c73;p=mpd-sima.git diff --git a/sima/plugins/internal/tags.py b/sima/plugins/internal/tags.py index cd1a4fe..9000c37 100644 --- a/sima/plugins/internal/tags.py +++ b/sima/plugins/internal/tags.py @@ -29,7 +29,7 @@ import random # local import from ...lib.plugin import Plugin from ...lib.track import Track -from ...utils.utils import PluginConfException +from ...utils.utils import PluginConfException, PluginException def forge_filter(cfg): tags = set(cfg.keys()) & Tags.supported_tags @@ -38,8 +38,10 @@ def forge_filter(cfg): if cfg_filter: mpd_filter.append(cfg_filter) for tag in tags: + if not cfg[tag]: # avoid empty tags entries in config + continue if ',' in cfg[tag]: - patt = '|'.join(cfg[tag].split(',')) + patt = '|'.join(map(str.strip, cfg[tag].split(','))) mpd_filter.append(f"({tag} =~ '({patt})')") else: mpd_filter.append(f"({tag} == '{cfg[tag].strip()}')") @@ -58,7 +60,6 @@ class Tags(Plugin): super().__init__(daemon) self.daemon = daemon self._control_conf() - #self._control_server() self._setup_tagsneeded() self.mpd_filter = forge_filter(self.plugin_conf) self.log.debug('mpd filter: %s', self.mpd_filter) @@ -72,13 +73,9 @@ class Tags(Plugin): self.log.info('Supported Tags are : %s', ', '.join(sup_tags)) raise PluginConfException('plugin misconfiguration') - def _control_server(self): - #TODO: - # * control tags used are available - # * filters are available mpd version >= 0.21 - raise NotImplemented - def _setup_tagsneeded(self): + self.log.debug('%s plugin needs the followinng metadata: %s', + self, set(self.plugin_conf.keys()) & Tags.supported_tags) tags = set(self.plugin_conf.keys()) & Tags.supported_tags self.player.needed_tags |= tags @@ -90,6 +87,14 @@ class Tags(Plugin): hist = [Track(file=tr[3], artist=tr[0]) for tr in tracks_from_db] return hist + def start(self): + if (0, 21, 0) > tuple(map(int, self.player.mpd_version.split('.'))): + self.log.warning('MPD protocol version: %s < 0.21.0', + self.player.mpd_version) + self.log.error('Need at least MPD 0.21 to use Tags plugin (filters required)') + self.player.disconnect() + raise PluginException('MPD >= 0.21 required') + def callback_need_track(self): candidates = [] target = self.plugin_conf.getint('track_to_add')