.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 urllib.parse import urlencode
9from datetime import datetime
10
11from searx.engines.peertube import fetch_traits # pylint: disable=unused-import
12from searx.engines.peertube import (
13 # pylint: disable=unused-import
14 video_response,
15 safesearch_table,
16 time_range_table,
17)
18
19about = {
20 # pylint: disable=line-too-long
21 "website": 'https://sepiasearch.org',
22 "wikidata_id": None,
23 "official_api_documentation": 'https://docs.joinpeertube.org/api-rest-reference.html#tag/Search/operation/searchVideos',
24 "use_official_api": True,
25 "require_api_key": False,
26 "results": 'JSON',
27}
28
29# engine dependent config
30categories = ['videos']
31paging = True
32
33base_url = 'https://sepiasearch.org'
34
35time_range_support = True
36safesearch = True
37
38
39def request(query, params):
40 """Assemble request for the SepiaSearch API"""
41
42 if not query:
43 return False
44
45 # eng_region = traits.get_region(params['searxng_locale'], 'en_US')
46 eng_lang = traits.get_language(params['searxng_locale'], None)
47
48 params['url'] = (
49 base_url.rstrip("/")
50 + "/api/v1/search/videos?"
51 + urlencode(
52 {
53 'search': query,
54 'start': (params['pageno'] - 1) * 10,
55 'count': 10,
56 # -createdAt: sort by date ascending / createdAt: date descending
57 'sort': '-match', # sort by *match descending*
58 'nsfw': safesearch_table[params['safesearch']],
59 }
60 )
61 )
62
63 if eng_lang is not None:
64 params['url'] += '&languageOneOf[]=' + eng_lang
65 params['url'] += '&boostLanguages[]=' + eng_lang
66
67 if params['time_range'] in time_range_table:
68 time = datetime.now().date() + time_range_table[params['time_range']]
69 params['url'] += '&startDate=' + time.isoformat()
70
71 return params
72
73
74def response(resp):
75 return video_response(resp)