diff --git a/sickbeard/db.py b/sickbeard/db.py index e1045711e7f09f2380978610b9f325579df46675..a5f8701f7c2ee99e2667ed77d9a6ed0b3f6fe843 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -229,19 +229,23 @@ class DBConnection(object): def _unicode_text_factory(self, x): try: + # Already unicode, empty string, or ascii x = unicode(x) except Exception: try: - x = unicode(x, sickbeard.SYS_ENCODING) + # most common encoding from web + x = unicode(x, 'utf-8') except Exception: try: - x = unicode(x, 'utf-8') + # most common from web if utf-8 fails + x = unicode(x, 'latin-1') except Exception: try: - x = unicode(x, 'latin-1') + # try system encoding before trusting chardet + x = unicode(x, sickbeard.SYS_ENCODING) except Exception: try: - # Chardet can be wrong, so try it before ignoring + # Chardet can be wrong, so try it last before ignoring x = unicode(x, chardet.detect(x).get('encoding')) except Exception: x = unicode(x, sickbeard.SYS_ENCODING, errors="ignore")