From 2719d060682e85c9571402a05319acdde3d776e3 Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 13 Dec 2020 15:37:02 +0100 Subject: [PATCH] Controls MPD protocol version (need 0.21 at least for filters) --- sima/plugins/internal/tags.py | 19 +++++++++++-------- sima/utils/utils.py | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/sima/plugins/internal/tags.py b/sima/plugins/internal/tags.py index cd1a4fe..0054767 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 @@ -58,7 +58,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 +71,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 +85,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') diff --git a/sima/utils/utils.py b/sima/utils/utils.py index 5c2a312..19603ba 100644 --- a/sima/utils/utils.py +++ b/sima/utils/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2010, 2011, 2013, 2014, 2015 kaliko +# Copyright (c) 2010, 2011, 2013, 2014, 2015, 2020 kaliko # # This file is part of sima # @@ -182,6 +182,9 @@ class WSHTTPError(WSError): class MPDSimaException(Exception): pass +class PluginException(MPDSimaException): + pass + class PluginConfException(MPDSimaException): pass -- 2.39.5