mirror of https://github.com/searx/searx
Add hostname_replace plugin
This commit is contained in:
parent
c00a33feee
commit
fc4bf4bf10
|
@ -32,6 +32,7 @@ from searx.plugins import (oa_doi_rewrite,
|
||||||
https_rewrite,
|
https_rewrite,
|
||||||
infinite_scroll,
|
infinite_scroll,
|
||||||
self_info,
|
self_info,
|
||||||
|
hostname_replace,
|
||||||
search_on_category_select,
|
search_on_category_select,
|
||||||
tracker_url_remover,
|
tracker_url_remover,
|
||||||
vim_hotkeys)
|
vim_hotkeys)
|
||||||
|
@ -168,6 +169,7 @@ plugins.register(hash_plugin)
|
||||||
plugins.register(https_rewrite)
|
plugins.register(https_rewrite)
|
||||||
plugins.register(infinite_scroll)
|
plugins.register(infinite_scroll)
|
||||||
plugins.register(self_info)
|
plugins.register(self_info)
|
||||||
|
plugins.register(hostname_replace)
|
||||||
plugins.register(search_on_category_select)
|
plugins.register(search_on_category_select)
|
||||||
plugins.register(tracker_url_remover)
|
plugins.register(tracker_url_remover)
|
||||||
plugins.register(vim_hotkeys)
|
plugins.register(vim_hotkeys)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import re
|
||||||
|
from urllib.parse import urlunparse
|
||||||
|
from searx import settings
|
||||||
|
from searx.plugins import logger
|
||||||
|
from flask_babel import gettext
|
||||||
|
|
||||||
|
name = gettext('Hostname replace')
|
||||||
|
description = gettext('Rewrite result hostnames')
|
||||||
|
default_on = False
|
||||||
|
preference_section = 'general'
|
||||||
|
|
||||||
|
plugin_id = 'hostname_replace'
|
||||||
|
parsed = 'parsed_url'
|
||||||
|
|
||||||
|
replacements = {re.compile(p): r for (p, r) in settings[plugin_id].items()} if plugin_id in settings else {}
|
||||||
|
|
||||||
|
logger = logger.getChild(plugin_id)
|
||||||
|
|
||||||
|
|
||||||
|
def on_result(request, search, result):
|
||||||
|
if parsed not in result:
|
||||||
|
return True
|
||||||
|
for (pattern, replacement) in replacements.items():
|
||||||
|
if pattern.search(result[parsed].netloc):
|
||||||
|
result[parsed] = result[parsed]._replace(netloc=pattern.sub(replacement, result[parsed].netloc))
|
||||||
|
result['url'] = urlunparse(result[parsed])
|
||||||
|
|
||||||
|
return True
|
|
@ -104,6 +104,18 @@ outgoing: # communication with search engines
|
||||||
# - "HTTPS rewrite"
|
# - "HTTPS rewrite"
|
||||||
# - ...
|
# - ...
|
||||||
|
|
||||||
|
# Example to rewrite hostnames in external links
|
||||||
|
#
|
||||||
|
# enabled_plugins:
|
||||||
|
# - 'Hostname replace'
|
||||||
|
# hostname_replace:
|
||||||
|
# '(.*\.)?youtube\.com$': 'invidious.example.com'
|
||||||
|
# '(.*\.)?youtu\.be$': 'invidious.example.com'
|
||||||
|
# '(.*\.)?youtube-noocookie\.com$': 'yotter.example.com'
|
||||||
|
# '(.*\.)?reddit\.com$': 'teddit.example.com'
|
||||||
|
# '(.*\.)?redd\.it$': 'teddit.example.com'
|
||||||
|
# '(www\.)?twitter\.com$': 'nitter.example.com'
|
||||||
|
|
||||||
checker:
|
checker:
|
||||||
# disable checker when in debug mode
|
# disable checker when in debug mode
|
||||||
off_when_debug: True
|
off_when_debug: True
|
||||||
|
|
Loading…
Reference in New Issue