.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
openverse.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3
4 Openverse (formerly known as: Creative Commons search engine) [Images]
5
6"""
7
8from json import loads
9from urllib.parse import urlencode
10
11
12about = {
13 "website": 'https://wordpress.org/openverse/',
14 "wikidata_id": None,
15 "official_api_documentation": 'https://api.openverse.engineering/v1/',
16 "use_official_api": True,
17 "require_api_key": False,
18 "results": 'JSON',
19}
20
21categories = ['images']
22
23paging = True
24nb_per_page = 20
25
26base_url = 'https://api.openverse.engineering/v1/images/'
27search_string = '?page={page}&page_size={nb_per_page}&format=json&{query}'
28
29
30def request(query, params):
31
32 search_path = search_string.format(query=urlencode({'q': query}), nb_per_page=nb_per_page, page=params['pageno'])
33
34 params['url'] = base_url + search_path
35
36 return params
37
38
39def response(resp):
40 results = []
41
42 json_data = loads(resp.text)
43
44 for result in json_data['results']:
45 results.append(
46 {
47 'url': result['foreign_landing_url'],
48 'title': result['title'],
49 'img_src': result['url'],
50 'template': 'images.html',
51 }
52 )
53
54 return results
request(query, params)
Definition openverse.py:30