From 9f0698013d6bb9d63fe9636f6f3b9b418bd3de0c Mon Sep 17 00:00:00 2001 From: Nicolai Ehemann Date: Wed, 30 Jul 2014 14:41:55 +0200 Subject: [PATCH] changed searching of local db to ignore (some) special characters like umlauts --- sickbeard/db.py | 10 ++++++++++ sickbeard/helpers.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index 08fabe662f..57e41f7f5d 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Author: Nic Wolfe # URL: http://code.google.com/p/sickbeard/ # @@ -51,6 +52,14 @@ def dbFilename(filename="sickbeard.db", suffix=None): filename = "%s.%s" % (filename, suffix) return ek.ek(os.path.join, sickbeard.DATA_DIR, filename) +# functions for sqlite UDFs +def _udf_dropspecialchars(text): + reps = {'á':'a', 'ã':'a', 'â':'a', 'é':'e', 'ê':'e', 'í':'i','ó':'o' ,'õ':'o' ,'ô':'o','ú':'u', 'ç':'c', 'ä':'ae', 'ü':'ue', 'ö':'oe', 'ß':'ss'} + text = text.lower() + for a, b in reps.iteritems(): + text = text.replace(a, b) + return text + class DBConnection: def __init__(self, filename="sickbeard.db", suffix=None, row_type=None): @@ -60,6 +69,7 @@ def __init__(self, filename="sickbeard.db", suffix=None, row_type=None): self.connection.row_factory = self._dict_factory else: self.connection.row_factory = sqlite3.Row + self.connection.create_function('dropspecialchars', 1, _udf_dropspecialchars) def checkDBVersion(self): try: diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 61ca216740..4ff2714e75 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -380,7 +380,7 @@ def searchDBForShow(regShowName): for showName in showNames: - sqlResults = myDB.select("SELECT * FROM tv_shows WHERE show_name LIKE ? OR tvr_name LIKE ?", [showName, showName]) + sqlResults = myDB.select("SELECT * FROM tv_shows WHERE dropspecialchars(show_name) LIKE dropspecialchars(?) OR dropspecialchars(tvr_name) LIKE dropspecialchars(?)", [showName, showName]) if len(sqlResults) == 1: return (int(sqlResults[0]["tvdb_id"]), sqlResults[0]["show_name"])