mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Changes as requested
This commit is contained in:
parent
0c6f826478
commit
39ca5b7be6
3 changed files with 28 additions and 33 deletions
|
|
@ -1108,3 +1108,25 @@ def lazy_property(func):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def decode_commandline_path(path):
|
||||||
|
"""Prepare a path for substitution into commandline template.
|
||||||
|
|
||||||
|
On Python 3, we need to construct the subprocess commands to invoke as a
|
||||||
|
Unicode string. On Unix, this is a little unfortunate---the OS is
|
||||||
|
expecting bytes---so we use surrogate escaping and decode with the
|
||||||
|
argument encoding, which is the same encoding that will then be
|
||||||
|
*reversed* to recover the same bytes before invoking the OS. On
|
||||||
|
Windows, we want to preserve the Unicode filename "as is."
|
||||||
|
"""
|
||||||
|
if six.PY2:
|
||||||
|
# On Python 2, substitute the bytestring directly into the template.
|
||||||
|
return path
|
||||||
|
else:
|
||||||
|
# On Python 3, the template is a Unicode string, which only supports
|
||||||
|
# substitution of Unicode variables.
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
return path.decode(_fsencoding())
|
||||||
|
else:
|
||||||
|
return path.decode(arg_encoding(), 'surrogateescape')
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"""Converts tracks or albums to external directory
|
"""Converts tracks or albums to external directory
|
||||||
"""
|
"""
|
||||||
from __future__ import division, absolute_import, print_function
|
from __future__ import division, absolute_import, print_function
|
||||||
from beets.util import par_map
|
from beets.util import par_map, decode_commandline_path
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
|
@ -25,7 +25,6 @@ import tempfile
|
||||||
import shlex
|
import shlex
|
||||||
import six
|
import six
|
||||||
from string import Template
|
from string import Template
|
||||||
import platform
|
|
||||||
|
|
||||||
from beets import ui, util, plugins, config
|
from beets import ui, util, plugins, config
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
|
|
@ -205,20 +204,8 @@ class ConvertPlugin(BeetsPlugin):
|
||||||
if not quiet and not pretend:
|
if not quiet and not pretend:
|
||||||
self._log.info(u'Encoding {0}', util.displayable_path(source))
|
self._log.info(u'Encoding {0}', util.displayable_path(source))
|
||||||
|
|
||||||
# On Python 3, we need to construct the command to invoke as a
|
source = decode_commandline_path(source)
|
||||||
# Unicode string. On Unix, this is a little unfortunate---the OS is
|
dest = decode_commandline_path(dest)
|
||||||
# expecting bytes---so we use surrogate escaping and decode with the
|
|
||||||
# argument encoding, which is the same encoding that will then be
|
|
||||||
# *reversed* to recover the same bytes before invoking the OS. On
|
|
||||||
# Windows, we want to preserve the Unicode filename "as is."
|
|
||||||
if not six.PY2:
|
|
||||||
command = command.decode(util.arg_encoding(), 'surrogateescape')
|
|
||||||
if platform.system() == 'Windows':
|
|
||||||
source = source.decode(util._fsencoding())
|
|
||||||
dest = dest.decode(util._fsencoding())
|
|
||||||
else:
|
|
||||||
source = source.decode(util.arg_encoding(), 'surrogateescape')
|
|
||||||
dest = dest.decode(util.arg_encoding(), 'surrogateescape')
|
|
||||||
|
|
||||||
# Substitute $source and $dest in the argument list.
|
# Substitute $source and $dest in the argument list.
|
||||||
args = shlex.split(command)
|
args = shlex.split(command)
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,13 @@
|
||||||
"""
|
"""
|
||||||
from __future__ import division, absolute_import, print_function
|
from __future__ import division, absolute_import, print_function
|
||||||
|
|
||||||
import platform
|
|
||||||
import shlex
|
import shlex
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from beets import util
|
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
from beets.ui import decargs, print_, Subcommand, UserError
|
from beets.ui import decargs, print_, Subcommand, UserError
|
||||||
from beets.util import command_output, displayable_path, subprocess, \
|
from beets.util import command_output, displayable_path, subprocess, \
|
||||||
bytestring_path, MoveOperation
|
bytestring_path, MoveOperation, decode_commandline_path
|
||||||
from beets.library import Item, Album
|
from beets.library import Item, Album
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -200,20 +198,8 @@ class DuplicatesPlugin(BeetsPlugin):
|
||||||
output as flexattr on a key that is the name of the program, and
|
output as flexattr on a key that is the name of the program, and
|
||||||
return the key, checksum tuple.
|
return the key, checksum tuple.
|
||||||
"""
|
"""
|
||||||
# On Python 3, we need to construct the command to invoke as a
|
args = [p.format(file=decode_commandline_path(item.path))
|
||||||
# Unicode string. On Unix, this is a little unfortunate---the OS is
|
for p in shlex.split(prog)]
|
||||||
# expecting bytes---so we use surrogate escaping and decode with the
|
|
||||||
# argument encoding, which is the same encoding that will then be
|
|
||||||
# *reversed* to recover the same bytes before invoking the OS. On
|
|
||||||
# Windows, we want to preserve the Unicode filename "as is."
|
|
||||||
if not six.PY2:
|
|
||||||
if platform.system() == 'Windows':
|
|
||||||
args = [p.format(file=item.path.decode(util._fsencoding()))
|
|
||||||
for p in shlex.split(prog)]
|
|
||||||
else:
|
|
||||||
args = [p.format(file=item.path.decode(util.arg_encoding(),
|
|
||||||
'surrogateescape')) for p in shlex.split(prog)]
|
|
||||||
|
|
||||||
key = args[0]
|
key = args[0]
|
||||||
checksum = getattr(item, key, False)
|
checksum = getattr(item, key, False)
|
||||||
if not checksum:
|
if not checksum:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue