From b0fe0924a3fbfbc6a8e9459fa14a12d1ef4e31d8 Mon Sep 17 00:00:00 2001 From: Hackurei <138650713+Hackurei@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:14:54 -0700 Subject: [PATCH] [feat] engine: implementation of brave goggles --- AUTHORS.rst | 3 ++- searx/engines/brave.py | 41 +++++++++++++++++++++++++++++++++++------ searx/settings.yml | 10 ++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 8692c03d4..47af54f26 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -169,4 +169,5 @@ features or generally made searx better: - @llmII - @blob42 ``_ - Paolo Basso `` -- Bernie Huang `` \ No newline at end of file +- Bernie Huang `` +- Austin Olacsi `` \ No newline at end of file diff --git a/searx/engines/brave.py b/searx/engines/brave.py index 6b65ae667..397af6094 100644 --- a/searx/engines/brave.py +++ b/searx/engines/brave.py @@ -30,6 +30,13 @@ Configured ``brave`` engines: ... brave_category: news + - name: brave.goggles + brave_category: goggles + time_range_support: true + paging: true + ... + brave_category: goggles + .. _brave regions: @@ -58,6 +65,23 @@ region are mapped to regions in SearXNG (see :py:obj:`babel 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 @@ -95,7 +119,7 @@ Implementations """ -from typing import TYPE_CHECKING +from typing import Any, TYPE_CHECKING from urllib.parse import ( urlencode, @@ -135,12 +159,14 @@ about = { base_url = "https://search.brave.com/" categories = [] 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 - ``videos``: search for videos - ``images``: search for images - ``news``: search for news +- ``goggles``: Common WEB search with custom rules """ brave_spellcheck = False @@ -153,7 +179,7 @@ in SearXNG, the spellchecking is disabled by default. send_accept_language_header = True paging = False """Brave only supports paging in :py:obj:`brave_category` ``search`` (UI -category All).""" +category All) and in the goggles category.""" max_page = 10 """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. @@ -164,7 +190,7 @@ safesearch_map = {2: 'strict', 1: 'moderate', 0: 'off'} # cookie: safesearch=of time_range_support = False """Brave only supports time-range in :py:obj:`brave_category` ``search`` (UI -category All).""" +category All) and in the goggles category.""" time_range_map = { 'day': 'pd', @@ -185,12 +211,15 @@ def request(query, params): if brave_spellcheck: args['spellcheck'] = '1' - if brave_category == 'search': + if brave_category in ('search', 'goggles'): if params.get('pageno', 1) - 1: args['offset'] = params.get('pageno', 1) - 1 if 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)}" # set properties in the cookies @@ -221,7 +250,7 @@ def _extract_published_date(published_date_raw): def response(resp): - if brave_category == 'search': + if brave_category in ('search', 'goggles'): return _parse_search(resp) datastr = "" diff --git a/searx/settings.yml b/searx/settings.yml index bebb7b47e..c44339938 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -2173,6 +2173,16 @@ engines: categories: 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 shortcut: lrs engine: xpath