2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-01-01 14:50:21 +00:00
|
|
|
# lint: pylint
|
|
|
|
"""SepiaSearch uses the same languages as :py:obj:`Peertube
|
|
|
|
<searx.engines.peertube>` and the response is identical to the response from the
|
|
|
|
peertube engines.
|
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
"""
|
2020-10-03 11:00:10 +00:00
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2020-10-03 11:00:10 +00:00
|
|
|
from urllib.parse import urlencode
|
|
|
|
from datetime import datetime
|
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
from searx.engines.peertube import fetch_traits # pylint: disable=unused-import
|
|
|
|
from searx.engines.peertube import (
|
|
|
|
# pylint: disable=unused-import
|
|
|
|
video_response,
|
|
|
|
safesearch_table,
|
|
|
|
time_range_table,
|
|
|
|
)
|
|
|
|
from searx.enginelib.traits import EngineTraits
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logger: logging.Logger
|
|
|
|
|
|
|
|
traits: EngineTraits
|
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
about = {
|
2023-01-01 14:50:21 +00:00
|
|
|
# pylint: disable=line-too-long
|
2021-01-13 10:31:25 +00:00
|
|
|
"website": 'https://sepiasearch.org',
|
|
|
|
"wikidata_id": None,
|
2023-01-01 14:50:21 +00:00
|
|
|
"official_api_documentation": 'https://docs.joinpeertube.org/api-rest-reference.html#tag/Search/operation/searchVideos',
|
2021-01-13 10:31:25 +00:00
|
|
|
"use_official_api": True,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'JSON',
|
|
|
|
}
|
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
# engine dependent config
|
2020-10-03 11:00:10 +00:00
|
|
|
categories = ['videos']
|
|
|
|
paging = True
|
2023-01-01 14:50:21 +00:00
|
|
|
|
|
|
|
base_url = 'https://sepiasearch.org'
|
|
|
|
|
2020-10-03 11:00:10 +00:00
|
|
|
time_range_support = True
|
|
|
|
safesearch = True
|
|
|
|
|
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
def request(query, params):
|
|
|
|
"""Assemble request for the SepiaSearch API"""
|
|
|
|
|
|
|
|
if not query:
|
|
|
|
return False
|
2020-10-03 11:00:10 +00:00
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
# eng_region = traits.get_region(params['searxng_locale'], 'en_US')
|
|
|
|
eng_lang = traits.get_language(params['searxng_locale'], None)
|
2020-10-03 11:00:10 +00:00
|
|
|
|
2021-12-27 08:26:22 +00:00
|
|
|
params['url'] = (
|
2023-01-01 14:50:21 +00:00
|
|
|
base_url.rstrip("/")
|
|
|
|
+ "/api/v1/search/videos?"
|
2021-12-27 08:26:22 +00:00
|
|
|
+ urlencode(
|
|
|
|
{
|
|
|
|
'search': query,
|
|
|
|
'start': (params['pageno'] - 1) * 10,
|
|
|
|
'count': 10,
|
2023-01-01 14:50:21 +00:00
|
|
|
# -createdAt: sort by date ascending / createdAt: date descending
|
|
|
|
'sort': '-match', # sort by *match descending*
|
2021-12-27 08:26:22 +00:00
|
|
|
'nsfw': safesearch_table[params['safesearch']],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2020-10-03 11:00:10 +00:00
|
|
|
|
2023-01-01 14:50:21 +00:00
|
|
|
if eng_lang is not None:
|
|
|
|
params['url'] += '&languageOneOf[]=' + eng_lang
|
|
|
|
params['url'] += '&boostLanguages[]=' + eng_lang
|
|
|
|
|
2020-10-03 11:00:10 +00:00
|
|
|
if params['time_range'] in time_range_table:
|
|
|
|
time = datetime.now().date() + time_range_table[params['time_range']]
|
|
|
|
params['url'] += '&startDate=' + time.isoformat()
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
2023-01-01 14:50:21 +00:00
|
|
|
return video_response(resp)
|