summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/admin/engines/settings.rst10
-rw-r--r--searx/engines/deepl.py62
-rw-r--r--searx/engines/xpath.py18
-rw-r--r--searx/settings.yml12
-rw-r--r--searx/settings_defaults.py1
-rw-r--r--searx/templates/simple/macros.html2
-rwxr-xr-xsearx/webapp.py1
7 files changed, 104 insertions, 2 deletions
diff --git a/docs/admin/engines/settings.rst b/docs/admin/engines/settings.rst
index f85c6a75f..b1853a11b 100644
--- a/docs/admin/engines/settings.rst
+++ b/docs/admin/engines/settings.rst
@@ -240,6 +240,7 @@ Global Settings
query_in_title: false
infinite_scroll: false
center_alignment: false
+ cache_url: https://web.archive.org/web/
default_theme: simple
theme_args:
simple_style: auto
@@ -267,6 +268,15 @@ Global Settings
side of the screen. This setting only affects the *desktop layout*
(:origin:`min-width: @tablet <searx/static/themes/simple/src/less/definitions.less>`)
+.. cache_url:
+
+``cache_url`` : ``https://web.archive.org/web/``
+ URL prefix of the internet archive or cache, don't forgett trailing slash (if
+ needed). The default is https://web.archive.org/web/ alternatives are:
+
+ - https://webcache.googleusercontent.com/search?q=cache:
+ - https://archive.today/
+
``default_theme`` :
Name of the theme you want to use by default on your SearXNG instance.
diff --git a/searx/engines/deepl.py b/searx/engines/deepl.py
new file mode 100644
index 000000000..85072710f
--- /dev/null
+++ b/searx/engines/deepl.py
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Deepl translation engine"""
+
+from json import loads
+
+about = {
+ "website": 'https://deepl.com',
+ "wikidata_id": 'Q43968444',
+ "official_api_documentation": 'https://www.deepl.com/docs-api',
+ "use_official_api": True,
+ "require_api_key": True,
+ "results": 'JSON',
+}
+
+engine_type = 'online_dictionary'
+categories = ['general']
+
+url = 'https://api-free.deepl.com/v2/translate'
+api_key = None
+
+
+def request(_query, params):
+ '''pre-request callback
+
+ params<dict>:
+
+ - ``method`` : POST/GET
+ - ``headers``: {}
+ - ``data``: {} # if method == POST
+ - ``url``: ''
+ - ``category``: 'search category'
+ - ``pageno``: 1 # number of the requested page
+ '''
+
+ params['url'] = url
+ params['method'] = 'POST'
+ params['data'] = {'auth_key': api_key, 'text': params['query'], 'target_lang': params['to_lang'][1]}
+
+ return params
+
+
+def response(resp):
+ results = []
+ result = loads(resp.text)
+ translations = result['translations']
+
+ infobox = "<dl>"
+
+ for translation in translations:
+ infobox += f"<dd>{translation['text']}</dd>"
+
+ infobox += "</dl>"
+
+ results.append(
+ {
+ 'infobox': 'Deepl',
+ 'content': infobox,
+ }
+ )
+
+ return results
diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py
index 705a5211d..f9528e92d 100644
--- a/searx/engines/xpath.py
+++ b/searx/engines/xpath.py
@@ -22,6 +22,7 @@ from urllib.parse import urlencode
from lxml import html
from searx.utils import extract_text, extract_url, eval_xpath, eval_xpath_list
+from searx.network import raise_for_httperror
search_url = None
"""
@@ -61,6 +62,14 @@ lang_all = 'en'
selected.
'''
+no_result_for_http_status = []
+'''Return empty result for these HTTP status codes instead of throwing an error.
+
+.. code:: yaml
+
+ no_result_for_http_status: []
+'''
+
soft_max_redirects = 0
'''Maximum redirects, soft limit. Record an error but don't stop the engine'''
@@ -177,11 +186,18 @@ def request(query, params):
params['url'] = search_url.format(**fargs)
params['soft_max_redirects'] = soft_max_redirects
+ params['raise_for_httperror'] = False
+
return params
-def response(resp):
+def response(resp): # pylint: disable=too-many-branches
'''Scrap *results* from the response (see :ref:`engine results`).'''
+ if no_result_for_http_status and resp.status_code in no_result_for_http_status:
+ return []
+
+ raise_for_httperror(resp)
+
results = []
dom = html.fromstring(resp.text)
is_onion = 'onions' in categories
diff --git a/searx/settings.yml b/searx/settings.yml
index 55b95a601..96ebd9715 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -95,6 +95,8 @@ ui:
default_theme: simple
# center the results ?
center_alignment: false
+ # URL prefix of the internet archive, don't forgett trailing slash (if needed).
+ # cache_url: "https://webcache.googleusercontent.com/search?q=cache:"
# Default interface locale - leave blank to detect from browser information or
# use codes from the 'locales' config section
default_locale: ""
@@ -1684,6 +1686,15 @@ engines:
engine: seznam
disabled: true
+ # - name: deepl
+ # engine: deepl
+ # shortcut: dpl
+ # # You can use the engine using the official stable API, but you need an API key
+ # # See: https://www.deepl.com/pro-api?cta=header-pro-api
+ # api_key: '' # required!
+ # timeout: 5.0
+ # disabled: true
+
- name: mojeek
shortcut: mjk
engine: xpath
@@ -1799,6 +1810,7 @@ engines:
url_xpath: //div[@class="upper-synonyms"]/a/@href
content_xpath: //div[@class="synonyms-list-group"]
title_xpath: //div[@class="upper-synonyms"]/a
+ no_result_for_http_status: [404]
about:
website: https://www.woxikon.de/
wikidata_id: # No Wikidata ID
diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py
index 4e06fb023..330878c1f 100644
--- a/searx/settings_defaults.py
+++ b/searx/settings_defaults.py
@@ -190,6 +190,7 @@ SCHEMA = {
'advanced_search': SettingsValue(bool, False),
'query_in_title': SettingsValue(bool, False),
'infinite_scroll': SettingsValue(bool, False),
+ 'cache_url': SettingsValue(str, 'https://web.archive.org/web/'),
},
'preferences': {
'lock': SettingsValue(list, []),
diff --git a/searx/templates/simple/macros.html b/searx/templates/simple/macros.html
index e06157867..d9af3fbbb 100644
--- a/searx/templates/simple/macros.html
+++ b/searx/templates/simple/macros.html
@@ -42,7 +42,7 @@
{%- macro result_sub_footer(result, proxify) -%}
<div class="engines">
{% for engine in result.engines %}<span>{{ engine }}</span>{% endfor %}
- {{ result_link("https://web.archive.org/web/" + result.url, icon_small('ellipsis-vertical-outline') + _('cached'), "cache_link") }}&lrm; {% if proxify and proxify_results %} {{ result_link(proxify(result.url), icon('link') + _('proxied'), "proxyfied_link") }} {% endif %}
+ {{ result_link(cache_url + result.url, icon_small('ellipsis-vertical-outline') + _('cached'), "cache_link") }}&lrm; {% if proxify and proxify_results %} {{ result_link(proxify(result.url), icon('link') + _('proxied'), "proxyfied_link") }} {% endif %}
</div>{{- '' -}}
<div class="break"></div>{{- '' -}}
{%- endmacro -%}
diff --git a/searx/webapp.py b/searx/webapp.py
index 5c30a6ed7..bd76cc534 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -465,6 +465,7 @@ def render(template_name: str, **kwargs):
kwargs['image_proxify'] = image_proxify
kwargs['proxify'] = morty_proxify if settings['result_proxy']['url'] is not None else None
kwargs['proxify_results'] = settings['result_proxy']['proxify_results']
+ kwargs['cache_url'] = settings['ui']['cache_url']
kwargs['get_result_template'] = get_result_template
kwargs['opensearch_url'] = (
url_for('opensearch')