diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index dfdabf5ef..c712081ee 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -99,11 +99,11 @@ def embed_item(item, imagepath, maxwidth=None, itempath=None): """ try: item['images'] = [_mediafile_image(imagepath, maxwidth)] - item.try_write(itempath) except IOError as exc: log.error(u'embedart: could not read image file: {0}'.format(exc)) - finally: + else: # We don't want to store the image in the database + item.try_write(itempath) del item['images'] diff --git a/docs/changelog.rst b/docs/changelog.rst index 9c5dd0d0b..b596406e9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,8 +4,10 @@ Changelog 1.3.9 (in development) ---------------------- -Changelog goes here! +Fixes: +* :doc:`/plugins/convert`: Does not crash when embedding cover art + fails. 1.3.8 (September 17, 2014) -------------------------- diff --git a/test/helper.py b/test/helper.py index 6beac5d5a..880877e01 100644 --- a/test/helper.py +++ b/test/helper.py @@ -35,6 +35,7 @@ import os import os.path import shutil import subprocess +import logging from tempfile import mkdtemp, mkstemp from contextlib import contextmanager from StringIO import StringIO @@ -52,6 +53,27 @@ from beets.mediafile import MediaFile import _common +class LogCapture(logging.Handler): + + def __init__(self): + super(LogCapture, self).__init__() + self.messages = [] + + def emit(self, record): + self.messages.append(str(record.msg)) + + +@contextmanager +def capture_log(logger='beets'): + capture = LogCapture() + log = logging.getLogger(logger) + log.addHandler(capture) + try: + yield capture.messages + finally: + log.removeHandler(capture) + + @contextmanager def control_stdin(input=None): """Sends ``input`` to stdin. diff --git a/test/test_embedart.py b/test/test_embedart.py index 418ad56d8..494a81523 100644 --- a/test/test_embedart.py +++ b/test/test_embedart.py @@ -15,7 +15,7 @@ import os.path import _common from _common import unittest -from helper import TestHelper +from helper import TestHelper, capture_log from beets.mediafile import MediaFile @@ -51,6 +51,12 @@ class EmbedartCliTest(unittest.TestCase, TestHelper): mediafile = MediaFile(item.path) self.assertEqual(mediafile.images[0].data, self.image_data) + def test_art_file_missing(self): + self.add_album_fixture() + with capture_log() as logs: + self.run_command('embedart', '-f', '/doesnotexist') + self.assertIn(u'embedart: could not read image file:', ''.join(logs)) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)