diff options
| author | Zhijie He <hezhijie0327@hotmail.com> | 2025-02-23 13:47:03 +0800 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2025-03-02 13:31:31 +0100 |
| commit | 97aa5a779b3910efb2cc8f7497969fbe0d126910 (patch) | |
| tree | 2ece13de46369a42d7441ec531ebabaae97ac919 /searx/engines/sogou_videos.py | |
| parent | 71d1504e572074327f851688a4caac90a5e41fe8 (diff) | |
[feat] add Sogou engine for searxng
Co-authored-by: Bnyro <bnyro@tutanota.com>
Diffstat (limited to 'searx/engines/sogou_videos.py')
| -rw-r--r-- | searx/engines/sogou_videos.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/searx/engines/sogou_videos.py b/searx/engines/sogou_videos.py new file mode 100644 index 000000000..1149996c9 --- /dev/null +++ b/searx/engines/sogou_videos.py @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Sogou-Videos: A search engine for retrieving videos from Sogou.""" + +from urllib.parse import urlencode +from datetime import datetime + +from searx.exceptions import SearxEngineAPIException + +about = { + "website": "https://v.sogou.com/", + "use_official_api": False, + "require_api_key": False, + "results": "JSON", +} + +categories = ["videos"] +paging = True +results_per_page = 10 + +# Base URL +base_url = "https://v.sogou.com" + + +def request(query, params): + query_params = { + "page": params["pageno"], + "pagesize": 10, + "query": query, + } + + params["url"] = f"{base_url}/api/video/shortVideoV2?{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 not data.get("data", {}).get("list"): + raise SearxEngineAPIException("Invalid response") + + for entry in data["data"]["list"]: + if not entry.get("titleEsc") or not entry.get("url"): + continue + + video_url = entry.get("url") + if video_url.startswith("/vc/np"): + video_url = f"{base_url}{video_url}" + + published_date = None + if entry.get("date") and entry.get("duration"): + try: + date_time_str = f"{entry['date']} {entry['duration']}" + published_date = datetime.strptime(date_time_str, "%Y-%m-%d %H:%M") + except (ValueError, TypeError): + published_date = None + + results.append( + { + 'url': video_url, + 'title': entry["titleEsc"], + 'content': f"{entry['site']} | {entry['duration']}", + 'template': 'videos.html', + 'publishedDate': published_date, + 'thumbnail': entry["picurl"], + } + ) + + return results |