From f7040f922c0afe0fd406efb8e823549fb2863d6c Mon Sep 17 00:00:00 2001 From: Nicolas Dietrich Date: Wed, 9 May 2012 00:19:38 +0200 Subject: [PATCH 1/2] allow unicode items in config file --- beets/ui/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index e2eebb738..e19e005f1 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -27,6 +27,7 @@ import logging import sqlite3 import errno import re +import codecs from beets import library from beets import plugins @@ -673,7 +674,7 @@ def main(args=None, configfh=None): if configpath: configpath = util.syspath(configpath) if os.path.exists(util.syspath(configpath)): - configfh = open(configpath) + configfh = codecs.open(configpath, 'r', encoding='utf-8') else: configfh = None if configfh: From a0e133ae5d769c03b121b15de63d23ef3eae975e Mon Sep 17 00:00:00 2001 From: Nicolas Dietrich Date: Wed, 9 May 2012 00:21:06 +0200 Subject: [PATCH 2/2] 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