From f617d162cf65d93bf8ae471f5bd229f44a089d3c Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 20 Jan 2015 15:17:21 -0800 Subject: [PATCH] keyfinder: Better output parsing (#1248) We were being sloppy about bytes output from the process. Also, it seems like the tools outputs the path also, so it's necessary to break on whitespace to actually get the key name. --- beetsplug/keyfinder.py | 9 ++++++++- docs/changelog.rst | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beetsplug/keyfinder.py b/beetsplug/keyfinder.py index d5b3e9bc7..882ae3a88 100644 --- a/beetsplug/keyfinder.py +++ b/beetsplug/keyfinder.py @@ -58,11 +58,18 @@ class KeyFinderPlugin(BeetsPlugin): 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 903eb4848..e6c28ee6b 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: