150 lines
3.9 KiB
Python
150 lines
3.9 KiB
Python
from server.services.huangdou.client import ApiError, TokenExpired, client
|
|
from server.services.huangdou.crypto import USER_AGENT
|
|
|
|
|
|
def device_info() -> dict:
|
|
return {
|
|
"browserName": "Chrome",
|
|
"language": "zh-CN",
|
|
"userAgent": USER_AGENT,
|
|
"platform": "Win32",
|
|
}
|
|
|
|
|
|
def login_device(*, force_new: bool = False) -> dict:
|
|
data = client.request(
|
|
"/login/device",
|
|
{
|
|
"line_code": "china_1",
|
|
"channel_code": "",
|
|
"share_code": "",
|
|
"clipboard_text": "",
|
|
"force_new": "1" if force_new else "",
|
|
"device_info": device_info(),
|
|
},
|
|
auth=False,
|
|
)
|
|
if not isinstance(data, dict):
|
|
raise RuntimeError("设备登录没有返回数据")
|
|
token = str(data.get("token") or "").strip()
|
|
if not token:
|
|
raise RuntimeError("设备登录没有返回 token")
|
|
client.token = token
|
|
return data
|
|
|
|
|
|
def user_info() -> dict:
|
|
data = client.request("/user/info", {}, auth=True)
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def system_info() -> dict:
|
|
data = client.request(
|
|
"/system/info",
|
|
{
|
|
"line_code": "china_1",
|
|
"channel_code": "",
|
|
"share_code": "",
|
|
"clipboard_text": "",
|
|
"device_info": device_info(),
|
|
"package_name": "",
|
|
},
|
|
auth=True,
|
|
)
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def nav_list() -> list[dict]:
|
|
data = client.request("/drama/navList", {"with_filters": "1"}, auth=True)
|
|
rows = _list_of(data)
|
|
return [item for item in rows if isinstance(item, dict)]
|
|
|
|
|
|
def nav_block(code: str, tab: str = "", page: int = 1) -> list[dict]:
|
|
data = client.request(
|
|
"/drama/navBlock",
|
|
{"code": str(code or ""), "tab": str(tab or ""), "page": str(page)},
|
|
auth=True,
|
|
)
|
|
rows = _list_of(data)
|
|
return [item for item in rows if isinstance(item, dict)]
|
|
|
|
|
|
def drama_list(
|
|
*,
|
|
page: int = 1,
|
|
page_size: int = 18,
|
|
keywords: str = "",
|
|
order: str = "",
|
|
cat_id: str = "",
|
|
tag_id: str = "",
|
|
source: str = "",
|
|
canvas: str = "",
|
|
pay_type: str = "",
|
|
update_status: str = "",
|
|
) -> list[dict]:
|
|
body = {"page": str(page), "page_size": str(page_size)}
|
|
if order:
|
|
body["order"] = order
|
|
if cat_id:
|
|
body["cat_id"] = cat_id
|
|
if tag_id:
|
|
body["tag_id"] = tag_id
|
|
if source:
|
|
body["source"] = source
|
|
if canvas:
|
|
body["canvas"] = canvas
|
|
if keywords:
|
|
body["keywords"] = keywords
|
|
if update_status:
|
|
body["update_status"] = update_status
|
|
if pay_type:
|
|
body["pay_type"] = pay_type
|
|
data = client.request("/drama/list", body, auth=True)
|
|
rows = _list_of(data)
|
|
return [item for item in rows if isinstance(item, dict)]
|
|
|
|
|
|
def limited_free(page: int = 1, size: int = 50) -> dict:
|
|
data = client.request("/drama/limitedFree", {"page": str(page), "size": str(size)}, auth=True)
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def drama_detail(drama_id: str) -> dict:
|
|
data = client.request("/drama/detail", {"id": str(drama_id)}, auth=True)
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def drama_play(drama_id: str, seq: int) -> dict:
|
|
data = client.request("/drama/play", {"id": str(drama_id), "seq": str(seq)}, auth=True)
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def _list_of(data) -> list:
|
|
if isinstance(data, list):
|
|
return data
|
|
if isinstance(data, dict):
|
|
rows = data.get("list")
|
|
if isinstance(rows, list):
|
|
return rows
|
|
items = data.get("items")
|
|
if isinstance(items, list):
|
|
return items
|
|
return []
|
|
|
|
|
|
__all__ = [
|
|
"ApiError",
|
|
"TokenExpired",
|
|
"client",
|
|
"drama_detail",
|
|
"drama_list",
|
|
"drama_play",
|
|
"limited_free",
|
|
"login_device",
|
|
"nav_block",
|
|
"nav_list",
|
|
"system_info",
|
|
"user_info",
|
|
]
|