.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
iqiyi.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""iQiyi: A search engine for retrieving videos from iQiyi."""
3
4from urllib.parse import urlencode
5from datetime import datetime
6
7from searx.exceptions import SearxEngineAPIException
8from searx.utils import parse_duration_string
9
10about = {
11 "website": "https://www.iqiyi.com/",
12 "wikidata_id": "Q15913890",
13 "use_official_api": False,
14 "require_api_key": False,
15 "results": "JSON",
16 "language": "zh",
17}
18
19paging = True
20time_range_support = True
21categories = ["videos"]
22
23time_range_dict = {'day': '1', 'week': '2', 'month': '3'}
24
25base_url = "https://mesh.if.iqiyi.com"
26
27
28def request(query, params):
29 query_params = {"key": query, "pageNum": params["pageno"], "pageSize": 25}
30
31 if time_range_dict.get(params['time_range']):
32 query_params["sitePublishDate"] = time_range_dict[params['time_range']]
33
34 params["url"] = f"{base_url}/portal/lw/search/homePageV3?{urlencode(query_params)}"
35 return params
36
37
38def response(resp):
39 try:
40 data = resp.json()
41 except Exception as e:
42 raise SearxEngineAPIException(f"Invalid response: {e}") from e
43 results = []
44
45 if "data" not in data or "templates" not in data["data"]:
46 raise SearxEngineAPIException("Invalid response")
47
48 for entry in data["data"]["templates"]:
49 album_info = entry.get("albumInfo", {})
50
51 published_date = None
52 release_time = album_info.get("releaseTime", {}).get("value")
53 if release_time:
54 try:
55 published_date = datetime.strptime(release_time, "%Y-%m-%d")
56 except (ValueError, TypeError):
57 pass
58
59 length = parse_duration_string(album_info.get("subscriptionContent"))
60 results.append(
61 {
62 'url': album_info.get("pageUrl", "").replace("http://", "https://"),
63 'title': album_info.get("title", ""),
64 'content': album_info.get("brief", {}).get("value", ""),
65 'template': 'videos.html',
66 'length': length,
67 'publishedDate': published_date,
68 'thumbnail': album_info.get("img", ""),
69 }
70 )
71
72 return results
request(query, params)
Definition iqiyi.py:28