mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
fix(qq): bypass broken c.y.qq.com search API, use u.y.qq.com directly
This commit is contained in:
1 parent
f9e2a210b7
commit
4de8ac1810
1 file changed
+30
-11
+30
-11
@@ -10,6 +10,14 @@ import type {
|
||||
} from "./provider.js";
|
||||
import { parseLyrics } from "./netease.js";
|
||||
|
||||
// Direct QQ Music API client — bypasses the local API server for search
|
||||
// because @sansenjian/qq-music-api still uses the broken c.y.qq.com endpoint.
|
||||
const qqDirectApi = axios.create({
|
||||
baseURL: "https://u.y.qq.com",
|
||||
timeout: 10000,
|
||||
headers: { referer: "https://y.qq.com" },
|
||||
});
|
||||
|
||||
export class QQMusicProvider implements MusicProvider {
|
||||
readonly platform = "qq" as const;
|
||||
private api: AxiosInstance;
|
||||
@@ -36,23 +44,34 @@ export class QQMusicProvider implements MusicProvider {
|
||||
}
|
||||
|
||||
async search(query: string, limit = 20): Promise<SearchResult> {
|
||||
const res = await this.api.get("/getSearchByKey", {
|
||||
params: { key: query, pageSize: limit, ...this.cookieParams },
|
||||
const reqData = JSON.stringify({
|
||||
req_0: {
|
||||
module: "music.search.SearchCgiService",
|
||||
method: "DoSearchForQQMusicDesktop",
|
||||
param: {
|
||||
searchid: "1",
|
||||
query,
|
||||
num_per_page: Math.min(limit, 50),
|
||||
},
|
||||
},
|
||||
});
|
||||
const res = await qqDirectApi.get("/cgi-bin/musicu.fcg", {
|
||||
params: { format: "json", data: reqData },
|
||||
});
|
||||
const list: any[] =
|
||||
res.data?.req_0?.data?.body?.song?.list ?? [];
|
||||
|
||||
const songs: Song[] = (res.data?.response?.data?.song?.list ?? []).map(
|
||||
(s: any) => ({
|
||||
id: String(s.mid ?? s.songmid ?? s.songid),
|
||||
name: s.songname ?? "",
|
||||
const songs: Song[] = list.map((s: any) => ({
|
||||
id: String(s.mid ?? s.id),
|
||||
name: s.title ?? s.name ?? "",
|
||||
artist: (s.singer ?? []).map((a: any) => a.name).join(" / "),
|
||||
album: s.albumname ?? "",
|
||||
album: s.album?.name ?? s.album?.title ?? "",
|
||||
duration: s.interval ?? 0,
|
||||
coverUrl: s.albummid
|
||||
? `https://y.gtimg.cn/music/photo_new/T002R300x300M000${s.albummid}.jpg`
|
||||
coverUrl: s.album?.mid
|
||||
? `https://y.gtimg.cn/music/photo_new/T002R300x300M000${s.album.mid}.jpg`
|
||||
: "",
|
||||
platform: "qq",
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
||||
return { songs, playlists: [], albums: [] };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user