From 46b78e9f438e665929b314e6ca36fd4ad4e22d29 Mon Sep 17 00:00:00 2001 From: Hackurei <138650713+Hackurei@users.noreply.github.com> Date: Tue, 5 Dec 2023 22:55:48 -0700 Subject: [PATCH] add subdomain replacement to hostname_replace.py --- searx/plugins/hostname_replace.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/searx/plugins/hostname_replace.py b/searx/plugins/hostname_replace.py index 039aadb91..42d56a292 100644 --- a/searx/plugins/hostname_replace.py +++ b/searx/plugins/hostname_replace.py @@ -30,7 +30,9 @@ def on_result(request, search, result): # (only) on the 'parsed_url' if not replacement: return False - result[parsed] = result[parsed]._replace(netloc=pattern.sub(replacement, result[parsed].netloc)) + subdomain = pattern.search(result[parsed].netloc).group(1) or '' + new_netloc = replacement.replace('(*)', subdomain) + result[parsed] = result[parsed]._replace(netloc=pattern.sub(new_netloc, result[parsed].netloc)) result['url'] = urlunparse(result[parsed]) for url_field in _url_fields: @@ -40,7 +42,9 @@ def on_result(request, search, result): if not replacement: del result[url_field] else: - url_src = url_src._replace(netloc=pattern.sub(replacement, url_src.netloc)) + subdomain = pattern.search(url_src.netloc).group(1) or '' + new_netloc = replacement.replace('(*)', subdomain) + url_src = url_src._replace(netloc=pattern.sub(new_netloc, url_src.netloc)) result[url_field] = urlunparse(url_src) return True