mirror of
https://github.com/searxng/searxng.git
synced 2024-11-26 04:41:00 +00:00
[feat] engine: brave - support for images
This commit is contained in:
parent
bcaaae699f
commit
73364e158e
3 changed files with 72 additions and 0 deletions
|
@ -17,3 +17,4 @@ markdown-it-py==3.0.0
|
||||||
typing_extensions==4.7.1
|
typing_extensions==4.7.1
|
||||||
fasttext-predict==0.9.2.1
|
fasttext-predict==0.9.2.1
|
||||||
pytomlpp==1.0.13
|
pytomlpp==1.0.13
|
||||||
|
chompjs==1.2.2
|
65
searx/engines/brave.py
Normal file
65
searx/engines/brave.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
"""
|
||||||
|
Brave (General, news, videos, images)
|
||||||
|
"""
|
||||||
|
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
from lxml import html
|
||||||
|
from searx.utils import extract_text, eval_xpath, eval_xpath_list
|
||||||
|
import chompjs, json
|
||||||
|
import re
|
||||||
|
|
||||||
|
about = {
|
||||||
|
"website": 'https://search.brave.com/',
|
||||||
|
"wikidata_id": 'Q22906900',
|
||||||
|
"official_api_documentation": None,
|
||||||
|
"use_official_api": False,
|
||||||
|
"require_api_key": False,
|
||||||
|
"results": 'HTML',
|
||||||
|
}
|
||||||
|
base_url = "https://search.brave.com/"
|
||||||
|
paging = False
|
||||||
|
categories = ['images', 'videos', 'news'] # images, videos, news
|
||||||
|
|
||||||
|
def request(query, params):
|
||||||
|
args = {
|
||||||
|
'q': query,
|
||||||
|
'spellcheck': 1,
|
||||||
|
}
|
||||||
|
params["url"] = f"{base_url}{categories[0]}?{urlencode(args)}"
|
||||||
|
|
||||||
|
def get_image_results(text):
|
||||||
|
results = []
|
||||||
|
|
||||||
|
datastr = ""
|
||||||
|
for line in text.split("\n"):
|
||||||
|
if "const data = " in line:
|
||||||
|
datastr = line.replace("const data = ", "").strip()[:-1]
|
||||||
|
break
|
||||||
|
|
||||||
|
json_data = chompjs.parse_js_object(datastr)
|
||||||
|
|
||||||
|
for result in json_data[1]["data"]["body"]["response"]["results"]:
|
||||||
|
results.append(
|
||||||
|
{
|
||||||
|
'template': 'images.html',
|
||||||
|
'url': result['url'],
|
||||||
|
'thumbnail_src': result['thumbnail']['src'],
|
||||||
|
'img_src': result['properties']['url'],
|
||||||
|
'content': result['description'],
|
||||||
|
'title': result['title'],
|
||||||
|
'source': result['source'],
|
||||||
|
'img_format': result['properties']['format'],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def response(resp):
|
||||||
|
dom = html.fromstring(resp.text)
|
||||||
|
|
||||||
|
match categories[0]:
|
||||||
|
case 'images':
|
||||||
|
return get_image_results(resp.text)
|
||||||
|
case _:
|
||||||
|
return []
|
|
@ -1843,6 +1843,12 @@ engines:
|
||||||
require_api_key: false
|
require_api_key: false
|
||||||
results: HTML
|
results: HTML
|
||||||
|
|
||||||
|
- name: brave.images
|
||||||
|
shortcut: braveimg
|
||||||
|
engine: brave
|
||||||
|
categories: images
|
||||||
|
disabled: false
|
||||||
|
|
||||||
- name: petalsearch
|
- name: petalsearch
|
||||||
shortcut: pts
|
shortcut: pts
|
||||||
engine: xpath
|
engine: xpath
|
||||||
|
|
Loading…
Reference in a new issue