1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2021 kaliko <kaliko@azylum.org>
4 # This file is part of sima
6 # sima is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # sima is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with sima. If not, see <http://www.gnu.org/licenses/>.
21 from logging import getLogger
23 from ..mpdclient import MPD, PlayerError
25 from ..plugins.internal.tags import forge_filter, control_config
27 log = getLogger('sima')
30 def tags_config_test(cli, config):
31 tags_cfg = config['tags']
32 if not control_config(tags_cfg):
34 filt = forge_filter(tags_cfg, log)
35 log.info('Trying tags and filter config')
36 log.debug('Complete filter (tag+filter): %s', filt)
38 # Use window to limit reponse size
39 res = cli.find(filt, 'window', (0, 300))
40 except PlayerError as err:
41 msg = re.split('{find}', str(err))
42 if len(msg) == 2 and tags_cfg.get('filter'):
43 log.info('user filter: %s', tags_cfg.get('filter'))
44 log.error('failed to find tracks, error: %s', msg[1])
45 raise PlayerError(err) from err
46 artists = list({trk.albumartist for trk in res if trk.albumartist})
48 log.info('Tags config correct but got nothing from MPD\'s library')
50 log.info('Got results, here are some of the artists found:')
51 log.info('%s', ' / '.join(artists[:6]))
54 def config_test(config):
56 log.info('Trying to connect MPD: %s:%s',
57 config.get('MPD', 'host'),
58 config.get('MPD', 'port'))
60 if 'Tags' in config.get('sima', 'internal'):
61 tags_config_test(cli, config)
65 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8