feat(python): 完成 Python 全量迁移——剩余平台、登录通道与公共层修复
- 新增 5sing/apple/xm/me/qt/lr 平台包与取流实现(含 xm-sign、MissEvan 签名、蜻蜓 HMAC、Apple developer token) - 新增 wy/kg/tx/lr 登录:扫码、手机号、账密(kg 20028 风控指纹)、cookie 绑定、kg/tx 续期 - request 层:保留多值 Set-Cookie;JSON body 紧凑化(修复 kg 网关验签);直连不经系统代理(对齐 Node) - 登录路由统一 Body(embed=True),修复扫码轮询 422;lifespan 接入登录续期调度 - ruff/format/pyright 全绿;14 平台真实联网与 HTTP 路由验证通过
This commit is contained in:
1 parent
800871ef6e
commit
dfc06bf4de
182 files changed
+26620
No files matched your search
@@ -0,0 +1,54 @@
|
||||
"""网易云 eapi 请求通道(移植自 sdk/wy/utils/index.ts)。
|
||||
|
||||
登录后携带 MUSIC_U(见 app/sdk/auth/wy.py),未登录不附加 —— 匿名接口同样要求
|
||||
eapi 签名,区别只在 cookie 决定的可访问范围/音质。
|
||||
|
||||
`weapi_headers(with_cookie=False)` 用于原实现里本就不带 cookie 的 weapi 请求
|
||||
(playlist/list、catalogue、hottags、comment、toplist),避免登录态意外改变返回内容。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.sdk.auth_store import get_wy_cookie
|
||||
from app.sdk.common.request import HttpResponse, http_fetch
|
||||
from app.sdk.platforms.wy.utils.crypto import eapi
|
||||
|
||||
UA_LINUX_CHROME = (
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
|
||||
)
|
||||
UA_WIN_CHROME = (
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
)
|
||||
|
||||
|
||||
def weapi_headers(referer: str = "https://music.163.com/", *, with_cookie: bool = True) -> dict[str, str]:
|
||||
headers = {
|
||||
"User-Agent": UA_LINUX_CHROME,
|
||||
"Referer": referer,
|
||||
"origin": "https://music.163.com",
|
||||
}
|
||||
if with_cookie:
|
||||
cookie = get_wy_cookie()
|
||||
if cookie:
|
||||
headers["cookie"] = cookie
|
||||
return headers
|
||||
|
||||
|
||||
async def eapi_request(
|
||||
url: str,
|
||||
data: dict[str, Any],
|
||||
*,
|
||||
host: str = "https://interface.music.163.com/eapi/batch",
|
||||
timeout_ms: int = 60_000,
|
||||
headers: dict[str, str] | None = None,
|
||||
) -> HttpResponse:
|
||||
"""POST 到 eapi 通道。`url` 是业务路径(如 /api/song/enhance/player/url/v1)。"""
|
||||
merged = {"User-Agent": UA_LINUX_CHROME, "origin": "https://music.163.com"}
|
||||
cookie = get_wy_cookie()
|
||||
if cookie:
|
||||
merged["cookie"] = cookie
|
||||
if headers:
|
||||
merged.update(headers)
|
||||
return await http_fetch(host, method="post", headers=merged, form=eapi(url, data), timeout=timeout_ms)
|
||||
Reference in new issue
Block a user