2022-07-14 12:29:41 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# lint: pylint
|
|
|
|
"""
|
|
|
|
Derpibooru (Images)
|
|
|
|
"""
|
2022-07-14 14:47:26 +02:00
|
|
|
from urllib.parse import urlencode
|
2022-07-14 12:29:41 +02:00
|
|
|
from json import loads
|
|
|
|
|
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://derpibooru.org/',
|
|
|
|
"wikidata_id": 'Q28233552',
|
|
|
|
"official_api_documentation": 'https://derpibooru.org/pages/api/',
|
2022-07-15 08:08:47 +02:00
|
|
|
"use_official_api": True,
|
2022-07-14 12:29:41 +02:00
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'JSON',
|
|
|
|
}
|
|
|
|
|
|
|
|
base_url = 'https://derpibooru.org/'
|
|
|
|
search_url = base_url + 'api/v1/json/search/images?'
|
|
|
|
categories = ['images']
|
|
|
|
page_size = 20
|
|
|
|
paging = True
|
|
|
|
filter_id = 100073
|
|
|
|
|
|
|
|
|
|
|
|
def request(query, params):
|
2022-07-14 13:53:55 +02:00
|
|
|
params['url'] = search_url + urlencode(
|
2022-07-14 14:14:58 +02:00
|
|
|
{'q': query, 'filter_id': filter_id, 'page': params['pageno'], 'per_page': page_size}
|
|
|
|
)
|
2022-07-14 12:29:41 +02:00
|
|
|
logger.debug("query_url --> %s", params['url'])
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
json_data = loads(resp.text)
|
|
|
|
|
|
|
|
if 'results' in json_data:
|
|
|
|
for result in json_data['images']:
|
2022-07-15 08:39:42 +02:00
|
|
|
logger.debug("query --> %s", result.get(result['representations']['thumb']))
|
2022-07-14 12:29:41 +02:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'template': 'images.html',
|
|
|
|
'url': 'https://derpibooru.org/images/' + result.get('id'),
|
2022-07-14 14:47:26 +02:00
|
|
|
'thumbnail_src': result.get(result['representations']['thumb']),
|
|
|
|
'img_src': result.get(result['representations']['full']),
|
2022-07-14 12:29:41 +02:00
|
|
|
'title': result.get('name') or 'unknown',
|
|
|
|
'content': result.get('description') or '',
|
|
|
|
}
|
|
|
|
)
|
2022-07-15 08:39:42 +02:00
|
|
|
|
2022-07-14 12:29:41 +02:00
|
|
|
return results
|