From f277c701da8611c0ce415b77e6a3da3c541de644 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 22 Jan 2012 23:52:56 +0100 Subject: [PATCH] Strip accents before simplifying string --- couchpotato/core/helpers/encoding.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index de53fa84..9e496e5f 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -1,6 +1,5 @@ from couchpotato.core.logger import CPLog from string import ascii_letters, digits -import os import re import unicodedata @@ -12,9 +11,9 @@ def toSafeString(original): cleanedFilename = unicodedata.normalize('NFKD', toUnicode(original)).encode('ASCII', 'ignore') return ''.join(c for c in cleanedFilename if c in valid_chars) - def simplifyString(original): - string = toSafeString(' '.join(re.split('\W+', original.lower()))) + string = stripAccents(original.lower()) + string = toSafeString(' '.join(re.split('\W+', string))) split = re.split('\W+', string.lower()) return toUnicode(' '.join(split)) @@ -45,3 +44,6 @@ def isInt(value): return True except ValueError: return False + +def stripAccents(s): + return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))