mirror of https://github.com/searxng/searxng.git
[feat] engine: implementation of brave goggles
This commit is contained in:
parent
53898b8c37
commit
b0fe0924a3
|
@ -169,4 +169,5 @@ features or generally made searx better:
|
||||||
- @llmII
|
- @llmII
|
||||||
- @blob42 `<https://blob42.xyz>`_
|
- @blob42 `<https://blob42.xyz>`_
|
||||||
- Paolo Basso `<https://github.com/paolobasso99>`
|
- Paolo Basso `<https://github.com/paolobasso99>`
|
||||||
- Bernie Huang `<https://github.com/BernieHuang2008>`
|
- Bernie Huang `<https://github.com/BernieHuang2008>`
|
||||||
|
- Austin Olacsi `<https://github.com/Austin-Olacsi>`
|
|
@ -30,6 +30,13 @@ Configured ``brave`` engines:
|
||||||
...
|
...
|
||||||
brave_category: news
|
brave_category: news
|
||||||
|
|
||||||
|
- name: brave.goggles
|
||||||
|
brave_category: goggles
|
||||||
|
time_range_support: true
|
||||||
|
paging: true
|
||||||
|
...
|
||||||
|
brave_category: goggles
|
||||||
|
|
||||||
|
|
||||||
.. _brave regions:
|
.. _brave regions:
|
||||||
|
|
||||||
|
@ -58,6 +65,23 @@ region are mapped to regions in SearXNG (see :py:obj:`babel
|
||||||
low quality.
|
low quality.
|
||||||
|
|
||||||
|
|
||||||
|
.. _brave googles:
|
||||||
|
|
||||||
|
Brave Goggles
|
||||||
|
=============
|
||||||
|
|
||||||
|
.. _list of Goggles: https://search.brave.com/goggles/discover
|
||||||
|
.. _Goggles Whitepaper: https://brave.com/static-assets/files/goggles.pdf
|
||||||
|
.. _Goggles Quickstart: https://github.com/brave/goggles-quickstart
|
||||||
|
|
||||||
|
Goggles allow you to choose, alter, or extend the ranking of Brave Search
|
||||||
|
results (`Goggles Whitepaper`_). Goggles are openly developed by the community
|
||||||
|
of Brave Search users.
|
||||||
|
|
||||||
|
Select from the `list of Goggles`_ people have published, or create your own
|
||||||
|
(`Goggles Quickstart`_).
|
||||||
|
|
||||||
|
|
||||||
.. _brave languages:
|
.. _brave languages:
|
||||||
|
|
||||||
Brave languages
|
Brave languages
|
||||||
|
@ -95,7 +119,7 @@ Implementations
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from urllib.parse import (
|
from urllib.parse import (
|
||||||
urlencode,
|
urlencode,
|
||||||
|
@ -135,12 +159,14 @@ about = {
|
||||||
base_url = "https://search.brave.com/"
|
base_url = "https://search.brave.com/"
|
||||||
categories = []
|
categories = []
|
||||||
brave_category = 'search'
|
brave_category = 'search'
|
||||||
"""Brave supports common web-search, video search, image and video search.
|
Goggles = Any
|
||||||
|
"""Brave supports common web-search, videos, images, news, and goggles search.
|
||||||
|
|
||||||
- ``search``: Common WEB search
|
- ``search``: Common WEB search
|
||||||
- ``videos``: search for videos
|
- ``videos``: search for videos
|
||||||
- ``images``: search for images
|
- ``images``: search for images
|
||||||
- ``news``: search for news
|
- ``news``: search for news
|
||||||
|
- ``goggles``: Common WEB search with custom rules
|
||||||
"""
|
"""
|
||||||
|
|
||||||
brave_spellcheck = False
|
brave_spellcheck = False
|
||||||
|
@ -153,7 +179,7 @@ in SearXNG, the spellchecking is disabled by default.
|
||||||
send_accept_language_header = True
|
send_accept_language_header = True
|
||||||
paging = False
|
paging = False
|
||||||
"""Brave only supports paging in :py:obj:`brave_category` ``search`` (UI
|
"""Brave only supports paging in :py:obj:`brave_category` ``search`` (UI
|
||||||
category All)."""
|
category All) and in the goggles category."""
|
||||||
max_page = 10
|
max_page = 10
|
||||||
"""Tested 9 pages maximum (``&offset=8``), to be save max is set to 10. Trying
|
"""Tested 9 pages maximum (``&offset=8``), to be save max is set to 10. Trying
|
||||||
to do more won't return any result and you will most likely be flagged as a bot.
|
to do more won't return any result and you will most likely be flagged as a bot.
|
||||||
|
@ -164,7 +190,7 @@ safesearch_map = {2: 'strict', 1: 'moderate', 0: 'off'} # cookie: safesearch=of
|
||||||
|
|
||||||
time_range_support = False
|
time_range_support = False
|
||||||
"""Brave only supports time-range in :py:obj:`brave_category` ``search`` (UI
|
"""Brave only supports time-range in :py:obj:`brave_category` ``search`` (UI
|
||||||
category All)."""
|
category All) and in the goggles category."""
|
||||||
|
|
||||||
time_range_map = {
|
time_range_map = {
|
||||||
'day': 'pd',
|
'day': 'pd',
|
||||||
|
@ -185,12 +211,15 @@ def request(query, params):
|
||||||
if brave_spellcheck:
|
if brave_spellcheck:
|
||||||
args['spellcheck'] = '1'
|
args['spellcheck'] = '1'
|
||||||
|
|
||||||
if brave_category == 'search':
|
if brave_category in ('search', 'goggles'):
|
||||||
if params.get('pageno', 1) - 1:
|
if params.get('pageno', 1) - 1:
|
||||||
args['offset'] = params.get('pageno', 1) - 1
|
args['offset'] = params.get('pageno', 1) - 1
|
||||||
if time_range_map.get(params['time_range']):
|
if time_range_map.get(params['time_range']):
|
||||||
args['tf'] = time_range_map.get(params['time_range'])
|
args['tf'] = time_range_map.get(params['time_range'])
|
||||||
|
|
||||||
|
if brave_category == 'goggles':
|
||||||
|
args['goggles_id'] = Goggles
|
||||||
|
|
||||||
params["url"] = f"{base_url}{brave_category}?{urlencode(args)}"
|
params["url"] = f"{base_url}{brave_category}?{urlencode(args)}"
|
||||||
|
|
||||||
# set properties in the cookies
|
# set properties in the cookies
|
||||||
|
@ -221,7 +250,7 @@ def _extract_published_date(published_date_raw):
|
||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
|
|
||||||
if brave_category == 'search':
|
if brave_category in ('search', 'goggles'):
|
||||||
return _parse_search(resp)
|
return _parse_search(resp)
|
||||||
|
|
||||||
datastr = ""
|
datastr = ""
|
||||||
|
|
|
@ -2173,6 +2173,16 @@ engines:
|
||||||
categories: news
|
categories: news
|
||||||
brave_category: news
|
brave_category: news
|
||||||
|
|
||||||
|
# - name: brave.goggles
|
||||||
|
# engine: brave
|
||||||
|
# network: brave
|
||||||
|
# shortcut: brgog
|
||||||
|
# time_range_support: true
|
||||||
|
# paging: true
|
||||||
|
# categories: [general, web]
|
||||||
|
# brave_category: goggles
|
||||||
|
# Goggles: # required! This should be a URL ending in .goggle
|
||||||
|
|
||||||
- name: lib.rs
|
- name: lib.rs
|
||||||
shortcut: lrs
|
shortcut: lrs
|
||||||
engine: xpath
|
engine: xpath
|
||||||
|
|
Loading…
Reference in New Issue