.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
sepiasearch.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""SepiaSearch uses the same languages as :py:obj:`Peertube
3<searx.engines.peertube>` and the response is identical to the response from the
4peertube engines.
5
6"""
7
8from typing import TYPE_CHECKING
9
10from urllib.parse import urlencode
11from datetime import datetime
12
13from searx.engines.peertube import fetch_traits # pylint: disable=unused-import
14from searx.engines.peertube import (
15 # pylint: disable=unused-import
16 video_response,
17 safesearch_table,
18 time_range_table,
19)
20from searx.enginelib.traits import EngineTraits
21
22if TYPE_CHECKING:
23 import logging
24
25 logger: logging.Logger
26
27traits: EngineTraits
28
29about = {
30 # pylint: disable=line-too-long
31 "website": 'https://sepiasearch.org',
32 "wikidata_id": None,
33 "official_api_documentation": 'https://docs.joinpeertube.org/api-rest-reference.html#tag/Search/operation/searchVideos',
34 "use_official_api": True,
35 "require_api_key": False,
36 "results": 'JSON',
37}
38
39# engine dependent config
40categories = ['videos']
41paging = True
42
43base_url = 'https://sepiasearch.org'
44
45time_range_support = True
46safesearch = True
47
48
49def request(query, params):
50 """Assemble request for the SepiaSearch API"""
51
52 if not query:
53 return False
54
55 # eng_region = traits.get_region(params['searxng_locale'], 'en_US')
56 eng_lang = traits.get_language(params['searxng_locale'], None)
57
58 params['url'] = (
59 base_url.rstrip("/")
60 + "/api/v1/search/videos?"
61 + urlencode(
62 {
63 'search': query,
64 'start': (params['pageno'] - 1) * 10,
65 'count': 10,
66 # -createdAt: sort by date ascending / createdAt: date descending
67 'sort': '-match', # sort by *match descending*
68 'nsfw': safesearch_table[params['safesearch']],
69 }
70 )
71 )
72
73 if eng_lang is not None:
74 params['url'] += '&languageOneOf[]=' + eng_lang
75 params['url'] += '&boostLanguages[]=' + eng_lang
76
77 if params['time_range'] in time_range_table:
78 time = datetime.now().date() + time_range_table[params['time_range']]
79 params['url'] += '&startDate=' + time.isoformat()
80
81 return params
82
83
84def response(resp):
85 return video_response(resp)