[mod] openverse - use of internal APIs and addition result fields (#6701)

Additional fields:
  add resolution, thumbnail and author to the image result

Types:
  use EngineResults and add type hints from internall APIs

Disabled engine:
  as of 09/2026: The availability of https://openverse.org/ is poor, and queries
  and image requests often time out. However, these issues also occur when using
  a WEB browser to search on openverse.org or view images.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser
2026-09-12 14:37:03 +02:00
committed by Markus Heiser
parent 0a94da4368
commit a667e8c905
2 changed files with 43 additions and 32 deletions

View File

@@ -1,54 +1,64 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
"""Openverse (formerly known as: Creative Commons search engine) [Images]
As of 09/2026: The availability of https://openverse.org/ is poor, and queries
and image requests often time out. However, these issues also occur when using a
WEB browser to search on openverse.org or view images.
""" """
Openverse (formerly known as: Creative Commons search engine) [Images] import typing as t
"""
from json import loads
from urllib.parse import urlencode from urllib.parse import urlencode
from dateutil import parser
from searx.result_types import EngineResults
if t.TYPE_CHECKING:
from searx.extended_types import SXNG_Response
from searx.search.processors import OnlineParams
about = { about = {
"website": 'https://openverse.org/', "website": "https://openverse.org/",
"wikidata_id": None, "wikidata_id": None,
"official_api_documentation": 'https://api.openverse.org/v1/', "official_api_documentation": "https://api.openverse.org/v1/",
"use_official_api": True, "use_official_api": True,
"require_api_key": False, "require_api_key": False,
"results": 'JSON', "results": "JSON",
} }
categories = ['images'] categories = ["images"]
paging = True paging = True
page_size = 20 page_size = 20
base_url = 'https://api.openverse.org/v1/images/' base_url = "https://api.openverse.org/v1/images/"
search_string = '?page={page}&page_size={page_size}&format=json&{query}'
def request(query, params): def request(query: str, params: "OnlineParams"):
args: dict[str, str | int] = {
search_path = search_string.format(query=urlencode({'q': query}), page_size=page_size, page=params['pageno']) "q": query,
"page": params["pageno"],
params['url'] = base_url + search_path "page_size": page_size,
"format": "json",
return params }
params["url"] = f"{base_url}?{urlencode(args)}"
def response(resp): def response(resp: "SXNG_Response") -> EngineResults:
results = [] res = EngineResults()
json_data = resp.json() # type: ignore
json_data = loads(resp.text) for result in json_data["results"]: # pyright: ignore[reportUnknownVariableType]
res.add(
for result in json_data['results']: res.types.Image(
results.append( url=result["foreign_landing_url"],
{ title=result["title"],
'url': result['foreign_landing_url'], img_src=result["url"],
'title': result['title'], thumbnail_src=result["thumbnail"],
'img_src': result['url'], resolution=f"{result['width']} x {result['height']}",
'template': 'images.html', author=result["creator"],
} publishedDate=parser.parse(result["indexed_on"]),
)
) )
return res
return results

View File

@@ -620,6 +620,7 @@ engines:
engine: openverse engine: openverse
categories: images categories: images
shortcut: opv shortcut: opv
disabled: true
- name: media.ccc.de - name: media.ccc.de
engine: ccc_media engine: ccc_media