diff options
author | Léon Tiekötter <leon@tiekoetter.com> | 2022-02-06 23:25:50 +0100 |
---|---|---|
committer | Léon Tiekötter <leon@tiekoetter.com> | 2022-02-06 23:25:50 +0100 |
commit | a50f32bcfcfce1de94c4eadb646c35489617fba3 (patch) | |
tree | 462c998e11951c41c5fe3c07a75a6dfee94a8eda /searx/engines/wikidata.py | |
parent | 560a14e77bcf804ab55ae1cc8c93ce0b2289cf2a (diff) | |
download | searxng-a50f32bcfcfce1de94c4eadb646c35489617fba3.tar.gz searxng-a50f32bcfcfce1de94c4eadb646c35489617fba3.zip |
wikidata: load thumbnail instead of full image
Diffstat (limited to 'searx/engines/wikidata.py')
-rw-r--r-- | searx/engines/wikidata.py | 17 |
1 files 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 |