keyfinder: Catch output from keyfinder-cli with no key

This commit is contained in:
Adam Miller 2020-12-07 22:04:05 -05:00
parent 9657919968
commit e11687f80a
3 changed files with 20 additions and 1 deletions

View file

@ -76,7 +76,14 @@ class KeyFinderPlugin(BeetsPlugin):
item.path)
continue
key_raw = output.rsplit(None, 1)[-1]
try:
key_raw = output.rsplit(None, 1)[-1]
except IndexError:
# Sometimes keyfinder-cli returns 0 but with no key, usually when
# the file is silent or corrupt, so we log and skip.
self._log.error(u'no key returned for path: {0}', item.path)
continue
try:
key = util.text_string(key_raw)
except UnicodeDecodeError:

View file

@ -282,6 +282,8 @@ Fixes:
:bug:`3773` :bug:`3774`
* Fix a bug causing PIL to generate poor quality JPEGs when resizing artwork.
:bug:`3743`
* :doc:`plugins/keyfinder`: Catch output from ``keyfinder-cli`` that is missing key.
:bug:`2242`
For plugin developers:

View file

@ -76,6 +76,16 @@ class KeyFinderTest(unittest.TestCase, TestHelper):
item.load()
self.assertEqual(item['initial_key'], 'F')
def test_no_key(self, command_output):
item = Item(path='/file')
item.add(self.lib)
command_output.return_value = util.CommandOutput(b"", b"")
self.run_command('keyfinder')
item.load()
self.assertEqual(item['initial_key'], None)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)