summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorLéon Tiekötter <leon@tiekoetter.com>2022-02-07 00:19:25 +0100
committerLéon Tiekötter <leon@tiekoetter.com>2022-02-07 00:21:02 +0100
commit1c151ae92bfe51faa89af523194dca631a7c9378 (patch)
tree78bc5507d31e3c17ef892101b96bab8588fda409 /searx/engines
parenta13c5d70c7b3773afcb2c6bfe684f212b3a70707 (diff)
downloadsearxng-1c151ae92bfe51faa89af523194dca631a7c9378.tar.gz
searxng-1c151ae92bfe51faa89af523194dca631a7c9378.zip
[fix] wikidata: URL decoding and file extension handling
Add '.png' to the second img_src_name if it has the extension '.svg'. Use urllib.parse.unquote for URL decoding.
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/wikidata.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py
index c6a551e9c..a89f79bf9 100644
--- a/searx/engines/wikidata.py
+++ b/searx/engines/wikidata.py
@@ -4,7 +4,7 @@
"""
-from urllib.parse import urlencode
+from urllib.parse import urlencode, unquote
from json import loads
from dateutil.parser import isoparse
@@ -202,13 +202,13 @@ def get_thumbnail(img_src):
"""
logger.debug('get_thumbnail(): %s', img_src)
if not img_src is None and _IMG_SRC_DEFAULT_URL_PREFIX in img_src.split()[0]:
- img_src_name = (
- img_src.replace(_IMG_SRC_DEFAULT_URL_PREFIX, "")
- .split("?", 1)[0]
- .replace("%20", "_")
- .replace("%28", "(")
- .replace("%29", ")")
- )
+ img_src_name = unquote(img_src.replace(_IMG_SRC_DEFAULT_URL_PREFIX, "").split("?", 1)[0].replace("%20", "_"))
+ img_src_name_first = img_src_name
+ img_src_name_second = img_src_name
+
+ if ".svg" in img_src_name.split()[0]:
+ img_src_name_second = img_src_name + ".png"
+
img_src_size = img_src.replace(_IMG_SRC_DEFAULT_URL_PREFIX, "").split("?", 1)[1]
img_src_size = img_src_size[img_src_size.index("=") + 1 : img_src_size.index("&")]
img_src_name_md5 = md5(img_src_name.encode("utf-8")).hexdigest()
@@ -218,11 +218,11 @@ def get_thumbnail(img_src):
+ "/"
+ img_src_name_md5[0:2]
+ "/"
- + img_src_name
+ + img_src_name_first
+ "/"
+ img_src_size
+ "px-"
- + img_src_name
+ + img_src_name_second
)
logger.debug('get_thumbnail() redirected: %s', img_src)