on master help sign in
Add hostname_replace plugin
fc4bf4b3nprob
searx/plugins/__init__.py+2
@@ -32,6 +32,7 @@ from searx.plugins import (oa_doi_rewrite,
32 https_rewrite,
32 https_rewrite,
33 infinite_scroll,
33 infinite_scroll,
34 self_info,
34 self_info,
35+ hostname_replace,
35 search_on_category_select,
36 search_on_category_select,
36 tracker_url_remover,
37 tracker_url_remover,
37 vim_hotkeys)
38 vim_hotkeys)
@@ -168,6 +169,7 @@ plugins.register(hash_plugin)
168plugins.register(https_rewrite)
169plugins.register(https_rewrite)
169plugins.register(infinite_scroll)
170plugins.register(infinite_scroll)
170plugins.register(self_info)
171plugins.register(self_info)
172+plugins.register(hostname_replace)
171plugins.register(search_on_category_select)
173plugins.register(search_on_category_select)
172plugins.register(tracker_url_remover)
174plugins.register(tracker_url_remover)
173plugins.register(vim_hotkeys)
175plugins.register(vim_hotkeys)
searx/plugins/hostname_replace.pynew file+28
@@ -0,0 +1,28 @@
1+import re
2+from urllib.parse import urlunparse
3+from searx import settings
4+from searx.plugins import logger
5+from flask_babel import gettext
6+
7+name = gettext('Hostname replace')
8+description = gettext('Rewrite result hostnames')
9+default_on = False
10+preference_section = 'general'
11+
12+plugin_id = 'hostname_replace'
13+parsed = 'parsed_url'
14+
15+replacements = {re.compile(p): r for (p, r) in settings[plugin_id].items()} if plugin_id in settings else {}
16+
17+logger = logger.getChild(plugin_id)
18+
19+
20+def on_result(request, search, result):
21+ if parsed not in result:
22+ return True
23+ for (pattern, replacement) in replacements.items():
24+ if pattern.search(result[parsed].netloc):
25+ result[parsed] = result[parsed]._replace(netloc=pattern.sub(replacement, result[parsed].netloc))
26+ result['url'] = urlunparse(result[parsed])
27+
28+ return True
searx/settings.yml+12
@@ -104,6 +104,18 @@ outgoing: # communication with search engines
104# - "HTTPS rewrite"
104# - "HTTPS rewrite"
105# - ...
105# - ...
106
106
107+# Example to rewrite hostnames in external links
108+#
109+# enabled_plugins:
110+# - 'Hostname replace'
111+# hostname_replace:
112+# '(.*\.)?youtube\.com$': 'invidious.example.com'
113+# '(.*\.)?youtu\.be$': 'invidious.example.com'
114+# '(.*\.)?youtube-noocookie\.com$': 'yotter.example.com'
115+# '(.*\.)?reddit\.com$': 'teddit.example.com'
116+# '(.*\.)?redd\.it$': 'teddit.example.com'
117+# '(www\.)?twitter\.com$': 'nitter.example.com'
118+
107checker:
119checker:
108 # disable checker when in debug mode
120 # disable checker when in debug mode
109 off_when_debug: True
121 off_when_debug: True