Merge pull request #3930 from arogl/fix_#2873

Attempt to fix duplicates
This commit is contained in:
Benedikt 2021-06-15 11:19:55 +02:00 committed by GitHub
commit 5fad8ee0b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 18 deletions

View file

@ -1108,3 +1108,25 @@ def lazy_property(func):
return value
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')

View file

@ -16,7 +16,7 @@
"""Converts tracks or albums to external directory
"""
from __future__ import division, absolute_import, print_function
from beets.util import par_map
from beets.util import par_map, decode_commandline_path, arg_encoding
import os
import threading
@ -25,7 +25,6 @@ import tempfile
import shlex
import six
from string import Template
import platform
from beets import ui, util, plugins, config
from beets.plugins import BeetsPlugin
@ -205,20 +204,11 @@ class ConvertPlugin(BeetsPlugin):
if not quiet and not pretend:
self._log.info(u'Encoding {0}', util.displayable_path(source))
# On Python 3, we need to construct the command 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 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')
command = command.decode(arg_encoding(), 'surrogateescape')
source = decode_commandline_path(source)
dest = decode_commandline_path(dest)
# Substitute $source and $dest in the argument list.
args = shlex.split(command)

View file

@ -18,13 +18,14 @@
from __future__ import division, absolute_import, print_function
import shlex
import six
from beets.plugins import BeetsPlugin
from beets.ui import decargs, print_, Subcommand, UserError
from beets.util import command_output, displayable_path, subprocess, \
bytestring_path, MoveOperation
bytestring_path, MoveOperation, decode_commandline_path
from beets.library import Item, Album
import six
PLUGIN = 'duplicates'
@ -197,7 +198,8 @@ class DuplicatesPlugin(BeetsPlugin):
output as flexattr on a key that is the name of the program, and
return the key, checksum tuple.
"""
args = [p.format(file=item.path) for p in shlex.split(prog)]
args = [p.format(file=decode_commandline_path(item.path))
for p in shlex.split(prog)]
key = args[0]
checksum = getattr(item, key, False)
if not checksum:

View file

@ -375,6 +375,9 @@ Fixes:
* :doc:`/plugins/lyrics`: Fix crashes for Tekstowo false positives
:bug:`3904`
* :doc`/reference/cli`: Remove reference to rarfile version in link
* Fix :bug:`2873`. Duplicates can now generate checksums. Thanks user:`wisp3rwind`
for the pointer to how to solve. Thanks to :user:`arogl`.
For plugin developers: