From ed143d5cacd0a591895d69a635b479f772146ad0 Mon Sep 17 00:00:00 2001 From: Dustyn Gibson <miigotu@gmail.com> Date: Fri, 24 Jul 2015 16:17:08 -0700 Subject: [PATCH] Text factory decoding order change - Fixes SiCKRAGETV/sickrage-issues#2319 --- sickbeard/db.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index e1045711e..a5f8701f7 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") -- GitLab