fix #280: unicode error when formatting artpath

The `artpath` field for Albums is a bytestring, not a Unicode string, and this
was causing a UnicodeDecodeError in `format_for_path`.
This commit is contained in:
Adrian Sampson 2013-05-19 10:05:23 -07:00
parent 4d62a83210
commit 71666c7ac2

View file

@ -196,12 +196,12 @@ def format_for_path(value, key=None, pathmod=None):
pathmod = pathmod or os.path
if isinstance(value, basestring):
if isinstance(value, str):
value = value.decode('utf8', 'ignore')
sep_repl = beets.config['path_sep_replace'].get(unicode)
for sep in (pathmod.sep, pathmod.altsep):
if sep:
value = value.replace(
sep,
beets.config['path_sep_replace'].get(unicode),
)
value = value.replace(sep, sep_repl)
elif key in ('track', 'tracktotal', 'disc', 'disctotal'):
# Pad indices with zeros.
value = u'%02i' % (value or 0)