From c75425655fdadf9554b97ae0309a6181acd34ce3 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Fri, 4 Jun 2021 09:35:26 +0200 Subject: [enh] openstreetmap / map template: improve results implements ideas described in #69 * update the engine * use wikidata * update map.html template --- searx/external_urls.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'searx/external_urls.py') diff --git a/searx/external_urls.py b/searx/external_urls.py index da58b8f54..11c6a32d9 100644 --- a/searx/external_urls.py +++ b/searx/external_urls.py @@ -10,6 +10,7 @@ IMDB_PREFIX_TO_URL_ID = { 'co': 'imdb_company', 'ev': 'imdb_event' } +HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/' def get_imdb_url_id(imdb_item_id): @@ -17,6 +18,14 @@ def get_imdb_url_id(imdb_item_id): return IMDB_PREFIX_TO_URL_ID.get(id_prefix) +def get_wikimedia_image_id(url): + if url.startswith(HTTP_WIKIMEDIA_IMAGE): + return url[len(HTTP_WIKIMEDIA_IMAGE):] + if url.startswith('File:'): + return url[len('File:'):] + return url + + def get_external_url(url_id, item_id, alternative="default"): """Return an external URL or None if url_id is not found. @@ -25,8 +34,11 @@ def get_external_url(url_id, item_id, alternative="default"): If item_id is None, the raw URL with the $1 is returned. """ - if url_id == 'imdb_id' and item_id is not None: - url_id = get_imdb_url_id(item_id) + if item_id is not None: + if url_id == 'imdb_id': + url_id = get_imdb_url_id(item_id) + elif url_id == 'wikimedia_image': + item_id = get_wikimedia_image_id(item_id) url_description = EXTERNAL_URLS.get(url_id) if url_description: -- cgit v1.2.3