mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 10:32:21 +02:00
[feat] add 360search engine for searxng
Co-authored-by: Bnyro <bnyro@tutanota.com>
This commit is contained in:
parent
80f5fad16e
commit
71d1504e57
5 changed files with 159 additions and 1 deletions
64
searx/engines/360search_videos.py
Normal file
64
searx/engines/360search_videos.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# pylint: disable=invalid-name
|
||||
"""360Search-Videos: A search engine for retrieving videos from 360Search."""
|
||||
|
||||
from urllib.parse import urlencode
|
||||
from datetime import datetime
|
||||
|
||||
from searx.exceptions import SearxEngineAPIException
|
||||
from searx.utils import html_to_text
|
||||
|
||||
about = {
|
||||
"website": "https://tv.360kan.com/",
|
||||
"use_official_api": False,
|
||||
"require_api_key": False,
|
||||
"results": "JSON",
|
||||
}
|
||||
|
||||
paging = True
|
||||
results_per_page = 10
|
||||
categories = ["videos"]
|
||||
|
||||
base_url = "https://tv.360kan.com"
|
||||
|
||||
|
||||
def request(query, params):
|
||||
query_params = {"count": 10, "q": query, "start": params["pageno"] * 10}
|
||||
|
||||
params["url"] = f"{base_url}/v1/video/list?{urlencode(query_params)}"
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
try:
|
||||
data = resp.json()
|
||||
except Exception as e:
|
||||
raise SearxEngineAPIException(f"Invalid response: {e}") from e
|
||||
results = []
|
||||
|
||||
if "data" not in data or "result" not in data["data"]:
|
||||
raise SearxEngineAPIException("Invalid response")
|
||||
|
||||
for entry in data["data"]["result"]:
|
||||
if not entry.get("title") or not entry.get("play_url"):
|
||||
continue
|
||||
|
||||
published_date = None
|
||||
if entry.get("publish_time"):
|
||||
try:
|
||||
published_date = datetime.fromtimestamp(int(entry["publish_time"]))
|
||||
except (ValueError, TypeError):
|
||||
published_date = None
|
||||
|
||||
results.append(
|
||||
{
|
||||
'url': entry["play_url"],
|
||||
'title': html_to_text(entry["title"]),
|
||||
'content': html_to_text(entry["description"]),
|
||||
'template': 'videos.html',
|
||||
'publishedDate': published_date,
|
||||
'thumbnail': entry["cover_img"],
|
||||
}
|
||||
)
|
||||
|
||||
return results
|
Loading…
Add table
Add a link
Reference in a new issue