From a50f32bcfcfce1de94c4eadb646c35489617fba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9on=20Tiek=C3=B6tter?= Date: Sun, 6 Feb 2022 23:25:50 +0100 Subject: [PATCH] wikidata: load thumbnail instead of full image --- searx/engines/wikidata.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index ce500cda6..18dac3efb 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -187,7 +187,7 @@ def response(resp): _IMG_SRC_DEFAULT_URL_PREFIX = "https://commons.wikimedia.org/wiki/Special:FilePath/" -_IMG_SRC_NEW_URL_PREFIX = "https://upload.wikimedia.org/wikipedia/commons/" +_IMG_SRC_NEW_URL_PREFIX = "https://upload.wikimedia.org/wikipedia/commons/thumb/" def get_thumbnail(img_src): @@ -209,8 +209,21 @@ def get_thumbnail(img_src): .replace("%28", "(") .replace("%29", ")") ) + 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() - img_src = _IMG_SRC_NEW_URL_PREFIX + img_src_name_md5[0] + "/" + img_src_name_md5[0:2] + "/" + img_src_name + img_src = ( + _IMG_SRC_NEW_URL_PREFIX + + img_src_name_md5[0] + + "/" + + img_src_name_md5[0:2] + + "/" + + img_src_name + + "/" + + img_src_size + + "px-" + + img_src_name + ) logger.debug('get_thumbnail() redirected: %s', img_src) return img_src