diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-30 16:05:08 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-30 16:05:08 +0100 |
| commit | e92d40c854eb22f22baed9558257941057cf13fa (patch) | |
| tree | e36674e4d5e76078e9097679543c0ea06d5409b1 /searx/search/processors/online_url_search.py | |
| parent | b7f74fbe42f54ebd60aeeed77312bcb4c4d63f76 (diff) | |
[enh] implement a OnlineUrlSearchProcessor
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/search/processors/online_url_search.py')
| -rw-r--r-- | searx/search/processors/online_url_search.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/searx/search/processors/online_url_search.py b/searx/search/processors/online_url_search.py new file mode 100644 index 000000000..2863be28e --- /dev/null +++ b/searx/search/processors/online_url_search.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +"""Processores for engine-type: ``online_url_search`` + +""" + +import re +from .online import OnlineProcessor + +re_search_urls = { + 'http': re.compile(r'https?:\/\/[^ ]*'), + 'ftp': re.compile(r'ftps?:\/\/[^ ]*'), + 'data:image': re.compile('data:image/[^; ]*;base64,[^ ]*'), +} + + +class OnlineUrlSearchProcessor(OnlineProcessor): + """Processor class used by ``online_url_search`` engines.""" + + engine_type = 'online_url_search' + + def get_params(self, search_query, engine_category): + params = super().get_params(search_query, engine_category) + if params is None: + return None + + url_match = False + search_urls = {} + + for k, v in re_search_urls.items(): + m = v.search(search_query.query) + v = None + if m: + url_match = True + v = m[0] + search_urls[k] = v + + if not url_match: + return None + + params['search_urls'] = search_urls + return params |