summaryrefslogtreecommitdiffstats
path: root/deluge/ui
diff options
context:
space:
mode:
authorDjLegolas <djlegolas@protonmail.com>2022-01-05 02:02:32 +0200
committerCalum Lind <calumlind+deluge@gmail.com>2022-01-06 10:04:19 +0000
commit517b2c653b6fed4b4a9ef5a8e866cc7aa4bd771d (patch)
tree10da8ed4cce669b978ba24350459dfffbbe7dbea /deluge/ui
parent44dcbee5f43b454994b3a6173bdd27802120e707 (diff)
downloaddeluge-517b2c653b6fed4b4a9ef5a8e866cc7aa4bd771d.tar.gz
deluge-517b2c653b6fed4b4a9ef5a8e866cc7aa4bd771d.tar.bz2
deluge-517b2c653b6fed4b4a9ef5a8e866cc7aa4bd771d.zip
[TrackerIcon] Fixed parse error on UTF-8 sites with non-english chars
When parsing the site's page in search for the FAVICON, the page gets opens. The default file encoding in dependent on the running OS, and might not be `UTF-8` on Windows. Therefor, some trackers might not get their icon downloaded at all because of an error: `UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2158: character maps to <undefined>`. This fix adds a detection of file encoding using the optional `chardet` dependency, and also a test. Closes: deluge-torrent/deluge#333 Closes: https://dev.deluge-torrent.org/ticket/3479
Diffstat (limited to 'deluge/ui')
-rw-r--r--deluge/ui/tracker_icons.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py
index a771a0ecf..813f82df4 100644
--- a/deluge/ui/tracker_icons.py
+++ b/deluge/ui/tracker_icons.py
@@ -22,6 +22,11 @@ from deluge.decorators import proxy
from deluge.httpdownloader import download_file
try:
+ import chardet
+except ImportError:
+ chardet = None
+
+try:
from PIL import Image
except ImportError:
Image = None
@@ -289,7 +294,13 @@ class TrackerIcons(Component):
:returns: a Deferred which callbacks a list of available favicons (url, type)
:rtype: Deferred
"""
- with open(page) as _file:
+ encoding = 'UTF-8'
+ if chardet:
+ with open(page, 'rb') as _file:
+ result = chardet.detect(_file.read())
+ encoding = result['encoding']
+
+ with open(page, encoding=encoding) as _file:
parser = FaviconParser()
for line in _file:
parser.feed(line)