Convert always uses bytestring args (#1461)

This commit is contained in:
Adrian Sampson 2015-05-19 16:38:08 -07:00
parent 36c2241a34
commit 07242f65e2
2 changed files with 13 additions and 4 deletions

View file

@ -169,7 +169,12 @@ class ConvertPlugin(BeetsPlugin):
Raises `subprocess.CalledProcessError` if the command exited with a
non-zero status code.
"""
quiet = self.config['quiet'].get()
# The paths and arguments must be bytes.
assert isinstance(command, bytes)
assert isinstance(source, bytes)
assert isinstance(dest, bytes)
quiet = self.config['quiet'].get(bool)
if not quiet and not pretend:
self._log.info(u'Encoding {0}', util.displayable_path(source))
@ -178,8 +183,8 @@ class ConvertPlugin(BeetsPlugin):
args = shlex.split(command)
for i, arg in enumerate(args):
args[i] = Template(arg).safe_substitute({
'source': source.decode('utf8'),
'dest': dest.decode('utf8'),
b'source': source,
b'dest': dest,
})
if pretend:
@ -391,6 +396,7 @@ class ConvertPlugin(BeetsPlugin):
command, ext = get_format()
tmpdir = self.config['tmpdir'].get()
fd, dest = tempfile.mkstemp('.' + ext, dir=tmpdir)
dest = util.bytestring_path(dest)
os.close(fd)
_temp_files.append(dest) # Delete the transcode later.
try:

View file

@ -23,6 +23,7 @@ from test import helper
from test.helper import control_stdin
from beets.mediafile import MediaFile
from beets import util
class TestHelper(helper.TestHelper):
@ -105,7 +106,9 @@ class ConvertCliTest(unittest.TestCase, TestHelper):
self.item = self.album.items()[0]
self.load_plugins('convert')
self.convert_dest = os.path.join(self.temp_dir, 'convert_dest')
self.convert_dest = util.bytestring_path(
os.path.join(self.temp_dir, 'convert_dest')
)
self.config['convert'] = {
'dest': self.convert_dest,
'paths': {'default': 'converted'},