- def _control_similarity(self):
- """
- * Regex check of command line similarity
- * Controls artist presence in MPD library
- """
- usage = ('USAGE: "main artist,similar artist:<match score>,other' +
- 'similar artist:<match score>,..."')
- cli_sim = self.options.similarity
- pattern = '^([^,]+?),([^:,]+?:\d{1,2},?)+$'
- regexp = re.compile(pattern, re.U).match(cli_sim)
- if not regexp:
- mess = 'ERROR: similarity badly formated: "%s"' % cli_sim
- print(mess, file=stderr)
- print(usage, file=stderr)
- exit(1)
- if self.options.check_names:
- if not self._control_artist_names():
- mess = 'ERROR: some artist names not found in MPD library!'
- print(mess, file=stderr)
- exit(1)
-
- def _control_artist_names(self):
- """Controls artist names exist in MPD library"""
- mpd_cli = self._get_mpd_client()
- artists_list = mpd_cli.list('artist')
- sim_formated = self._parse_similarity()
- control = True
- if sim_formated[0] not in artists_list:
- mess = 'WARNING: Main artist not found in MPD: %s' % sim_formated[0]
- print(mess)
- control = False
- for sart in sim_formated[1]:
- art = sart.get('artist')
- if art not in artists_list:
- mess = str('WARNING: Similar artist not found in MPD: %s' % art)
- print(mess)
- control = False
- mpd_cli.disconnect()
- return control
-