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,65 @@
|
||||
"""蜻蜓FM 平台模块(对应 sdk/qt/index.ts)。
|
||||
|
||||
匿名可用面(2026-10-02 实测):搜索(官网 SSR 解析)/ 频道节目列表(SSR)/
|
||||
免费节目点播直链(audiostream 签名 302 到华为云 CDN)。
|
||||
|
||||
搜索结果为频道(专辑)级条目,songmid=channelId;节目条目 songmid="<channelId>:<programId>"。
|
||||
付费节目与直播电台签名(Lwrpu$K5oP)暂未接登录。有声内容不参与聚合(noAggregate)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.sdk.platforms._base import Platform
|
||||
from app.sdk.platforms.qt import album, music_search
|
||||
|
||||
|
||||
async def _get_music_url(song_info: dict[str, Any], quality: str, retry_num: int = 0) -> dict[str, Any]:
|
||||
from app.sdk.apis.qt import get_music_url
|
||||
|
||||
return await get_music_url(song_info, quality, retry_num)
|
||||
|
||||
|
||||
async def get_pic(song_info: dict[str, Any]) -> str | None:
|
||||
"""搜索结果已带封面;频道详情页无独立封面接口,降级用 SSR 页 og:image。"""
|
||||
channel_id = str(song_info.get("songmid") or "").split(":")[0]
|
||||
return await album.get_channel_og_image(channel_id)
|
||||
|
||||
|
||||
async def get_album_detail(channel_id: str, page: int = 1, limit: int = 20) -> dict[str, Any]:
|
||||
del page, limit # SSR 页一次吐出全部节目,与上游一致不分页
|
||||
result = await album.get_channel_programs(channel_id)
|
||||
songs = result["list"]
|
||||
return {
|
||||
"info": {"name": result["name"], "total": len(songs)},
|
||||
"list": songs,
|
||||
"total": len(songs),
|
||||
"limit": len(songs),
|
||||
"allPage": 1,
|
||||
"source": "qt",
|
||||
}
|
||||
|
||||
|
||||
class _QtAlbum:
|
||||
get_album_detail = staticmethod(get_album_detail)
|
||||
|
||||
|
||||
def get_music_detail_page_url(song_info: dict[str, Any]) -> str:
|
||||
parts = str(song_info.get("songmid") or "").split(":")
|
||||
channel_id = parts[0] if parts else ""
|
||||
program_id = parts[1] if len(parts) > 1 else ""
|
||||
if program_id:
|
||||
return f"https://www.qingting.fm/channels/{channel_id}/programs/{program_id}"
|
||||
return f"https://www.qingting.fm/channels/{channel_id}"
|
||||
|
||||
|
||||
MODULE = Platform(
|
||||
id="qt",
|
||||
name="蜻蜓FM",
|
||||
music_search=music_search,
|
||||
album=_QtAlbum,
|
||||
get_music_url=_get_music_url,
|
||||
get_pic=get_pic,
|
||||
get_music_detail_page_url=get_music_detail_page_url,
|
||||
)
|
||||
@@ -0,0 +1,68 @@
|
||||
"""蜻蜓FM 频道节目列表(对应 sdk/qt/album.ts,官网 SSR 页解析)。
|
||||
|
||||
接口: https://www.qingting.fm/channels/<id>(302 → www.qtfm.cn,见 http.py)
|
||||
实测(2026-10-02)SSR 输出含节目表格:a.pTitle href=/channels/<cid>/programs/<pid> + p[title] + span.col2 时长
|
||||
节目条目的 songmid 采用复合 id ``<channelId>:<programId>``(取流签名需要两者)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from app.sdk.platforms.qt.http import ssr_get
|
||||
|
||||
|
||||
def _decode_entities(text: str) -> str:
|
||||
return (
|
||||
text.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(""", '"')
|
||||
.replace("'", "'")
|
||||
)
|
||||
|
||||
|
||||
async def _fetch_channel_html(channel_id: str) -> str:
|
||||
result = await ssr_get(f"https://www.qingting.fm/channels/{channel_id}")
|
||||
if result["statusCode"] != 200:
|
||||
raise RuntimeError(f"获取频道失败(HTTP {result['statusCode']})")
|
||||
return str(result["html"])
|
||||
|
||||
|
||||
async def get_channel_programs(channel_id: str) -> dict[str, Any]:
|
||||
html = await _fetch_channel_html(channel_id)
|
||||
|
||||
title_match = re.search(r"<title>([^<]*)<", html)
|
||||
raw_name = title_match.group(1).split("-")[0].strip() if title_match else ""
|
||||
name = _decode_entities(raw_name or str(channel_id))
|
||||
|
||||
songs = []
|
||||
for match in re.finditer(r'href="/channels/(\d+)/programs/(\d+)"[^>]*>\s*<p[^>]*title="([^"]*)"', html):
|
||||
songs.append(
|
||||
{
|
||||
"songmid": f"{match.group(1)}:{match.group(2)}",
|
||||
"name": _decode_entities(match.group(3)) or f"节目 {match.group(2)}",
|
||||
"singer": name,
|
||||
"albumId": str(channel_id),
|
||||
"albumName": name,
|
||||
"interval": 0,
|
||||
"payPlay": False,
|
||||
"img": None,
|
||||
"lrc": "",
|
||||
"lrcx": "",
|
||||
"types": [],
|
||||
"_types": {},
|
||||
"disabled": False,
|
||||
}
|
||||
)
|
||||
return {"name": name, "list": songs}
|
||||
|
||||
|
||||
async def get_channel_og_image(channel_id: str) -> str | None:
|
||||
"""频道封面(SSR 页 og:image)。"""
|
||||
html = await _fetch_channel_html(channel_id)
|
||||
match = re.search(r'property="og:image"\s+content="([^"]+)"', html) or re.search(
|
||||
r'content="([^"]+)"\s+property="og:image"', html
|
||||
)
|
||||
return match.group(1).replace("http://", "https://") if match else None
|
||||
@@ -0,0 +1,44 @@
|
||||
"""蜻蜓FM SSR 请求助手(对应 sdk/qt/http.ts)。
|
||||
|
||||
域名迁移(www.qingting.fm → www.qtfm.cn)伴随华为 WAF 会话:
|
||||
302 时需带上 Set-Cookie 的 HWWAFSESID/HWWAFSESTIME 再请求 Location,否则可能被 WAF 拦。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from app.sdk.common.request import http_fetch
|
||||
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||||
|
||||
|
||||
async def ssr_get(url: str) -> dict[str, Any]:
|
||||
"""GET 并跟随最多 3 跳重定向(累计收集 Cookie 回带),返回最终响应 ``{statusCode, html}``。"""
|
||||
current = url
|
||||
cookie = ""
|
||||
for _hop in range(4):
|
||||
headers: dict[str, str] = {
|
||||
"User-Agent": UA,
|
||||
"Referer": "https://www.qtfm.cn/",
|
||||
"Accept": "text/html,application/xhtml+xml",
|
||||
}
|
||||
if cookie:
|
||||
headers["Cookie"] = cookie
|
||||
resp = await http_fetch(current, headers=headers, timeout=15_000)
|
||||
pairs = [item.split(";")[0].strip() for item in resp.set_cookies]
|
||||
pairs = [pair for pair in pairs if pair]
|
||||
if pairs:
|
||||
cookie = "; ".join([part for part in cookie.split("; ") if part] + pairs)
|
||||
|
||||
if 300 <= resp.status_code < 400:
|
||||
location = str(resp.headers.get("location") or "")
|
||||
if location:
|
||||
current = location if location.startswith("http") else urljoin(current, location)
|
||||
continue
|
||||
return {
|
||||
"statusCode": resp.status_code,
|
||||
"html": resp.raw.decode("utf-8", errors="replace") if resp.raw else str(resp.body or ""),
|
||||
}
|
||||
raise RuntimeError("重定向次数过多")
|
||||
@@ -0,0 +1,54 @@
|
||||
"""蜻蜓FM 搜索(对应 sdk/qt/musicSearch.ts,官网 SSR 频道结果页解析)。
|
||||
|
||||
接口: https://www.qingting.fm/search/channel_ondemand/<keyword>(302 → www.qtfm.cn,见 http.py)
|
||||
实测(2026-10-02)SSR 渲染且与关键词强相关;?keyword= 混合页的结果区为客户端渲染
|
||||
(服务端只吐热门推荐),JSON 搜索端点(webapi/webbff/searchapi)均 404——本页是唯一匿名搜索通道。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from app.sdk.platforms.fivesing.util import encode_uri_component
|
||||
from app.sdk.platforms.qt.http import ssr_get
|
||||
|
||||
|
||||
async def search(keyword: str, page: int = 1, limit: int = 20, retry_num: int = 0) -> dict[str, Any]:
|
||||
del retry_num # 契约参数,SSR 搜索无重试语义
|
||||
result = await ssr_get(
|
||||
f"https://www.qingting.fm/search/channel_ondemand/{encode_uri_component(keyword)}?page={page}"
|
||||
)
|
||||
if result["statusCode"] != 200:
|
||||
raise RuntimeError(f"搜索失败(HTTP {result['statusCode']})")
|
||||
html = str(result["html"])
|
||||
|
||||
# 结果项:href=/channels/<id> … <span title="<名称>">,封面在随后的 img src
|
||||
items = []
|
||||
for match in re.finditer(r'href="/channels/(\d+)"[\s\S]{0,400}?<span title="([^"]*)">', html):
|
||||
after = html[match.start() : match.start() + 700]
|
||||
img = re.search(r'<img src="(http[^"]+)"', after)
|
||||
items.append(
|
||||
{
|
||||
"songmid": match.group(1),
|
||||
"name": match.group(2),
|
||||
"singer": "",
|
||||
"albumId": "",
|
||||
"albumName": "",
|
||||
"interval": 0,
|
||||
"img": img.group(1).replace("http://", "https://") if img else None,
|
||||
"lrc": "",
|
||||
"lrcx": "",
|
||||
"types": [],
|
||||
"_types": {},
|
||||
"disabled": False,
|
||||
}
|
||||
)
|
||||
songs = [item for item in items if item["name"]][:limit]
|
||||
return {
|
||||
"allPage": page + (1 if len(songs) >= 10 else 0),
|
||||
"total": len(songs),
|
||||
"limit": limit,
|
||||
"source": "qt",
|
||||
"list": songs,
|
||||
}
|
||||
Reference in new issue
Block a user