From a0e133ae5d769c03b121b15de63d23ef3eae975e Mon Sep 17 00:00:00 2001 From: Nicolas Dietrich Date: Wed, 9 May 2012 00:21:06 +0200 Subject: [PATCH] Allow unicode in rewrite items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit makes rewrite explicitely match items using the .lower() function instead of using Pythons builtin re.I flag. This is required as the re.I flag only allows for case-independent pattern matching with ascii chars. Even worse, the pattern is stored in lowercase when using re.I, but the value to be matched isn't lowercased. Example: [rewrite] artist Сергей Васильевич Рахманинов: Sergei Rachmaninoff --- beetsplug/rewrite.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/rewrite.py b/beetsplug/rewrite.py index 609999749..f97ec58f6 100644 --- a/beetsplug/rewrite.py +++ b/beetsplug/rewrite.py @@ -33,7 +33,7 @@ def rewriter(field, rules): def fieldfunc(item): value = getattr(item, field) for pattern, replacement in rules: - if pattern.match(value): + if pattern.match(value.lower()): # Rewrite activated. return replacement # Not activated; return original value. @@ -59,7 +59,7 @@ class RewritePlugin(BeetsPlugin): raise ui.UserError("invalid field name (%s) in rewriter" % fieldname) log.debug(u'adding template field %s' % key) - pattern = re.compile(pattern, re.I) + pattern = re.compile(pattern.lower()) rules[fieldname].append((pattern, value)) if fieldname == 'artist': # Special case for the artist field: apply the same