Skip to content

Commit

Permalink
keyfinder: Better output parsing (#1248)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sampsyo committed Jan 20, 2015
1 parent dae1776 commit f617d16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion beetsplug/keyfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit f617d16

Please sign in to comment.