Allow unicode in rewrite items

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
This commit is contained in:
Nicolas Dietrich 2012-05-09 00:21:06 +02:00
parent f7040f922c
commit a0e133ae5d

View file

@ -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