summaryrefslogtreecommitdiff
path: root/searx/plugins
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-02-07 16:45:48 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2022-02-13 14:20:47 +0100
commitb9a2e8b387212d35cc83da50a07ee8fa47d2a56e (patch)
treeba6fd96f8deb162b7d80bc4ae6a9cc6abcbeb29f /searx/plugins
parent46e131fdadd94910c0e258aa4e855ad8019edbf7 (diff)
downloadsearxng-b9a2e8b387212d35cc83da50a07ee8fa47d2a56e.tar.gz
searxng-b9a2e8b387212d35cc83da50a07ee8fa47d2a56e.zip
[mod] hostname_replace: replace hostnames in result's data_src param
To test you need to redirect embeded videos (e.g.) from youtube to a invidios instance. Search for videos using engine `!youtube lebowski`. The result URLs and the embeded videos should link to the invidios instance. Here is an example of such a `hostname_replace` configuration:: hostname_replace: # youtube --> Invidious '(.*\.)?youtube-nocookie\.com': 'invidio.xamh.de' '(.*\.)?youtube\.com$': 'invidio.xamh.de' '(.*\.)?invidious\.snopyta\.org$': 'invidio.xamh.de' '(.*\.)?vid\.puffyan\.us': 'invidio.xamh.de' '(.*\.)?invidious\.kavin\.rocks$': 'invidio.xamh.de' '(.*\.)?inv\.riverside\.rocks$': 'invidio.xamh.de' Closes: https://github.com/searxng/searxng/issues/873 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/plugins')
-rw-r--r--searx/plugins/hostname_replace.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/searx/plugins/hostname_replace.py b/searx/plugins/hostname_replace.py
index 778b84615..e22b2dca0 100644
--- a/searx/plugins/hostname_replace.py
+++ b/searx/plugins/hostname_replace.py
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
import re
-from urllib.parse import urlunparse
+from urllib.parse import urlunparse, urlparse
from searx import settings
from searx.plugins import logger
from flask_babel import gettext
@@ -28,5 +28,10 @@ def on_result(request, search, result):
return False
result[parsed] = result[parsed]._replace(netloc=pattern.sub(replacement, result[parsed].netloc))
result['url'] = urlunparse(result[parsed])
+ if result.get('data_src', False):
+ parsed_data_src = urlparse(result['data_src'])
+ if pattern.search(parsed_data_src.netloc):
+ parsed_data_src = parsed_data_src._replace(netloc=pattern.sub(replacement, parsed_data_src.netloc))
+ result['data_src'] = urlunparse(parsed_data_src)
return True