From 933d4d3ffaff2470710c4996a0f457a57536334c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 22 Mar 2014 11:29:19 +0000 Subject: [PATCH] RSS: Another attempt at fixing encoding issues. --- plugins/RSS/plugin.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 7807f4b70..6a1959021 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -150,14 +150,22 @@ class RSS(callbacks.Plugin): if headline[2]: pubDate = ' [%s]' % (headline[2],) if sys.version_info[0] < 3: + try: + import charade.universaldetector + u = charade.universaldetector.UniversalDetector() + u.feed(s) + u.close() + encoding = u.result['encoding'] + except ImportError: + encoding = 'utf8' if isinstance(headline[0], unicode): newheadlines.append(format('%s %u%s', - headline[0].encode('utf-8','replace'), + headline[0].encode(encoding,'replace'), link, pubDate)) else: newheadlines.append(format('%s %u%s', - headline[0].decode('utf-8','replace'), + headline[0] link, pubDate)) else: