.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
360search_videos.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=invalid-name
3"""360Search-Videos: A search engine for retrieving videos from 360Search."""
4
5from urllib.parse import urlencode
6from datetime import datetime
7
8from searx.exceptions import SearxEngineAPIException
9from searx.utils import html_to_text, get_embeded_stream_url
10
11about = {
12 "website": "https://tv.360kan.com/",
13 "use_official_api": False,
14 "require_api_key": False,
15 "results": "JSON",
16}
17
18paging = True
19results_per_page = 10
20categories = ["videos"]
21
22base_url = "https://tv.360kan.com"
23
24
25def request(query, params):
26 query_params = {"count": 10, "q": query, "start": params["pageno"] * 10}
27
28 params["url"] = f"{base_url}/v1/video/list?{urlencode(query_params)}"
29 return params
30
31
32def response(resp):
33 try:
34 data = resp.json()
35 except Exception as e:
36 raise SearxEngineAPIException(f"Invalid response: {e}") from e
37 results = []
38
39 if "data" not in data or "result" not in data["data"]:
40 raise SearxEngineAPIException("Invalid response")
41
42 for entry in data["data"]["result"]:
43 if not entry.get("title") or not entry.get("play_url"):
44 continue
45
46 published_date = None
47 if entry.get("publish_time"):
48 try:
49 published_date = datetime.fromtimestamp(int(entry["publish_time"]))
50 except (ValueError, TypeError):
51 published_date = None
52
53 results.append(
54 {
55 'url': entry["play_url"],
56 'title': html_to_text(entry["title"]),
57 'content': html_to_text(entry["description"]),
58 'template': 'videos.html',
59 'publishedDate': published_date,
60 'thumbnail': entry["cover_img"],
61 "iframe_src": get_embeded_stream_url(entry["play_url"]),
62 }
63 )
64
65 return results