diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index b705ed7e7..19e9a145d 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -26,7 +26,7 @@ from beets.plugins import BeetsPlugin from beets import mediafile from beets import ui from beets.ui import decargs -from beets.util import syspath, normpath, displayable_path +from beets.util import syspath, normpath, displayable_path, bytestring_path from beets.util.artresizer import ArtResizer from beets import config @@ -101,7 +101,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): self.extract_first(normpath(opts.outpath), lib.items(decargs(args))) else: - filename = opts.filename or config['art_filename'].get() + filename = bytestring_path(opts.filename or + config['art_filename'].get()) if os.path.dirname(filename) != '': self._log.error(u"Only specify a name rather than a path " u"for -n") @@ -265,7 +266,7 @@ class EmbedCoverArtPlugin(BeetsPlugin): self._log.warning(u'Unknown image type in {0}.', displayable_path(item.path)) return - outpath += '.' + ext + outpath = outpath + b'.' + ext self._log.info(u'Extracting album art from: {0} to: {1}', item, displayable_path(outpath)) diff --git a/test/test_embedart.py b/test/test_embedart.py index 6347c32d1..729f5853d 100644 --- a/test/test_embedart.py +++ b/test/test_embedart.py @@ -16,6 +16,7 @@ from __future__ import (division, absolute_import, print_function, unicode_literals) import os.path +import shutil from mock import Mock, patch from test import _common @@ -41,7 +42,7 @@ def require_artresizer_compare(test): return wrapper -class EmbedartCliTest(unittest.TestCase, TestHelper): +class EmbedartCliTest(_common.TestCase, TestHelper): small_artpath = os.path.join(_common.RSRC, 'image-2x3.jpg') abbey_artpath = os.path.join(_common.RSRC, 'abbey.jpg') @@ -114,6 +115,18 @@ class EmbedartCliTest(unittest.TestCase, TestHelper): 'Image written is not {0}'.format( self.abbey_similarpath)) + def test_non_ascii_album_path(self): + resource_path = os.path.join(_common.RSRC, 'image.mp3') + album = self.add_album_fixture() + trackpath = album.items()[0].path + albumpath = album.path + shutil.copy(resource_path, trackpath.decode('utf-8')) + + self.run_command('extractart', '-n', 'extracted') + + self.assertExists(os.path.join(albumpath.decode('utf-8'), + 'extracted.png')) + class EmbedartTest(unittest.TestCase): @patch('beetsplug.embedart.subprocess')