Merge pull request #1328 from mried/extractart-unicode

Fix a crash when extracting album art
This commit is contained in:
Adrian Sampson 2015-02-18 10:33:33 -08:00
commit ccd8a7e1d4
2 changed files with 18 additions and 4 deletions

View file

@ -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))

View file

@ -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')