diff --git a/beetsplug/keyfinder.py b/beetsplug/keyfinder.py index d5b3e9bc79..882ae3a88f 100644 --- a/beetsplug/keyfinder.py +++ b/beetsplug/keyfinder.py @@ -58,11 +58,18 @@ def find_key(self, items, write=False): continue try: - key = util.command_output([bin, '-f', item.path]) + output = util.command_output([bin, '-f', item.path]) except (subprocess.CalledProcessError, OSError) as exc: self._log.error(u'execution failed: {0}', exc) continue + key_raw = output.rsplit(None, 1)[-1] + try: + key = key_raw.decode('utf8') + except UnicodeDecodeError: + self._log.error(u'output is invalid UTF-8') + continue + item['initial_key'] = key self._log.info(u'added computed initial key {0} for {1}', key, util.displayable_path(item.path)) diff --git a/docs/changelog.rst b/docs/changelog.rst index 903eb48489..e6c28ee6bb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -39,6 +39,8 @@ Fixes: company since 2013, so we are assuming access will not be restored. * Incremental imports now (once again) show a "skipped N directories" message. * :doc:`/plugins/embedart`: Handle errors in ImageMagick's output. :bug:`1241` +* :doc:`/plugins/keyfinder`: Parse the underlying tool's output more robustly. + :bug:`1248` For developers: