summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-02-25 18:09:04 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-02-29 13:12:40 +0100
commitf3b4bf86a786e33193b46feeb56bc4e5b6f08067 (patch)
treea3b44243523e6819361fa9fda02d72ac8948d66b
parentd58760ef751a2df47fa7f118c04d0502d1b37d16 (diff)
downloadsearxng-f3b4bf86a786e33193b46feeb56bc4e5b6f08067.tar.gz
searxng-f3b4bf86a786e33193b46feeb56bc4e5b6f08067.zip
[feat] engine: implementation of void linux packages
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
-rw-r--r--docs/dev/engines/online/void.rst13
-rw-r--r--searx/engines/voidlinux.py91
-rw-r--r--searx/settings.yml5
3 files changed, 109 insertions, 0 deletions
diff --git a/docs/dev/engines/online/void.rst b/docs/dev/engines/online/void.rst
new file mode 100644
index 000000000..a1839d4f2
--- /dev/null
+++ b/docs/dev/engines/online/void.rst
@@ -0,0 +1,13 @@
+.. _voidlinux engine:
+
+==========================
+Void Linux binary packages
+==========================
+
+.. contents:: Contents
+ :depth: 2
+ :local:
+ :backlinks: entry
+
+.. automodule:: searx.engines.voidlinux
+ :members:
diff --git a/searx/engines/voidlinux.py b/searx/engines/voidlinux.py
new file mode 100644
index 000000000..608402d13
--- /dev/null
+++ b/searx/engines/voidlinux.py
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""SearXNG engine for `Void Linux binary packages`_. Void is a general purpose
+operating system, based on the monolithic Linux kernel. Its package system
+allows you to quickly install, update and remove software; software is provided
+in binary packages or can be built directly from sources with the help of the
+XBPS source packages collection.
+
+.. _Void Linux binary packages: https://voidlinux.org/packages/
+
+"""
+
+import re
+
+from urllib.parse import quote_plus
+from searx.utils import humanize_bytes
+
+about = {
+ 'website': 'https://voidlinux.org/packages/',
+ 'wikidata_id': 'Q19310966',
+ 'use_official_api': True,
+ 'official_api_documentation': None,
+ 'require_api_key': False,
+ 'results': 'JSON',
+}
+
+categories = ['packages', 'it']
+
+base_url = "https://xq-api.voidlinux.org"
+pkg_repo_url = "https://github.com/void-linux/void-packages"
+
+void_arch = 'x86_64'
+"""Default architecture to search for. For valid values see :py:obj:`ARCH_RE`"""
+
+ARCH_RE = re.compile('aarch64-musl|armv6l-musl|armv7l-musl|x86_64-musl|aarch64|armv6l|armv7l|i686|x86_64')
+"""Regular expresion that match a architecture in the query string."""
+
+
+def request(query, params):
+ arch_path = ARCH_RE.search(query)
+ if arch_path:
+ arch_path = arch_path.group(0)
+ query = query.replace(arch_path, '').strip()
+ else:
+ arch_path = void_arch
+
+ params['url'] = f"{base_url}/v1/query/{arch_path}?q={quote_plus(query)}"
+ return params
+
+
+def response(resp):
+ """
+ At Void Linux, several packages sometimes share the same source code
+ (template) and therefore also have the same URL. Results with identical
+ URLs are merged as one result for SearXNG.
+ """
+
+ packages = {}
+ for result in resp.json()['data']:
+
+ # 32bit and dbg packages don't have their own package templates
+ github_slug = re.sub(r"-(32bit|dbg)$", "", result['name'])
+ pkg_url = f"{pkg_repo_url}/tree/master/srcpkgs/{github_slug}"
+
+ pkg_list = packages.get(pkg_url, [])
+ pkg_list.append(
+ {
+ 'title': result['name'],
+ 'content': f"{result['short_desc']} - {humanize_bytes(result['filename_size'])}",
+ 'package_name': result['name'],
+ 'version': f"v{result['version']}_{result['revision']}",
+ 'tags': result['repository'],
+ }
+ )
+ packages[pkg_url] = pkg_list
+
+ results = []
+ for pkg_url, pkg_list in packages.items():
+
+ results.append(
+ {
+ 'url': pkg_url,
+ 'template': 'packages.html',
+ 'title': ' | '.join(x['title'] for x in pkg_list),
+ 'content': pkg_list[0]['content'],
+ 'package_name': ' | '.join(x['package_name'] for x in pkg_list),
+ 'version': pkg_list[0]['version'],
+ 'tags': [x['tags'] for x in pkg_list],
+ }
+ )
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 6c1f7bdd0..72cf4e7ac 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -2147,6 +2147,11 @@ engines:
engine: tootfinder
shortcut: toot
+ - name: voidlinux
+ engine: voidlinux
+ shortcut: void
+ disabled: true
+
- name: wallhaven
engine: wallhaven
# api_key: abcdefghijklmnopqrstuvwxyz