From 71666c7ac2f54ad9c2ef1bd64159668d1e617598 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 19 May 2013 10:05:23 -0700 Subject: [PATCH] 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`. --- beets/library.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beets/library.py b/beets/library.py index 8d9060ad2..a8fe0be73 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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)