From b871bb9c83bb80870261ba6656c1433941807099 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 19 Jul 2023 05:16:31 +0800 Subject: [PATCH] feat(provider/kuwo): allow custom CSRF Token Signed-off-by: Tianling Shen --- README.md | 1 + src/provider/kuwo.js | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e6a3cbd3e8..82fa2827fa 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ node app.js -o bilibili ytdlp | LOG_LEVEL | str | 日志输出等级。请见〈日志等级〉部分。 | `LOG_LEVEL=debug` | | LOG_FILE | str | 从 Pino 端设置日志输出的文件位置。也可以用 `*sh` 的输出重导向功能 (`node app.js >> app.log`) 代替 | `LOG_FILE=app.log` | | JOOX_COOKIE | str | JOOX 音源的 wmid 和 session_key cookie | `JOOX_COOKIE="wmid=; session_key="` | +| KUWO_COOKIE | str | 酷我音源的 CSRF Token | `KUWO_COOKIE=Hm_Iuvt_=; Secret=` | | MIGU_COOKIE | str | 咪咕音源的 aversionid cookie | `MIGU_COOKIE=""` | | QQ_COOKIE | str | QQ 音源的 uin 和 qm_keyst cookie | `QQ_COOKIE="uin=; qm_keyst="` | | YOUTUBE_KEY | str | Youtube 音源的 Data API v3 Key | `YOUTUBE_KEY=""` | diff --git a/src/provider/kuwo.js b/src/provider/kuwo.js index ecd930951a..e220ac7b3f 100644 --- a/src/provider/kuwo.js +++ b/src/provider/kuwo.js @@ -46,20 +46,16 @@ const search = (info) => { const keyword = encodeURIComponent(info.keyword.replace(' - ', ' ')); const url = `http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=${keyword}&pn=1&rn=30`; - const token = crypto.random.hex(32).toUpperCase(); return request('GET', url, { referer: `http://www.kuwo.cn/search/list?key=${keyword}`, - cross: crypto.md5.digest(crypto.sha1.digest(token)), - cookie: `Hm_token=${token}`, + secret: + ((process.env.KUWO_COOKIE || '').match(/Secret=([0-9a-f]{72})/) || + [])[1] || '0', + cookie: process.env.KUWO_COOKIE || null, }) .then((response) => response.json()) .then((jsonBody) => { - if ( - jsonBody && - typeof jsonBody === 'object' && - 'code' in jsonBody && - jsonBody.code !== 200 - ) + if (!jsonBody || jsonBody.code !== 200 || jsonBody.data.total < 1) return Promise.reject(); const list = jsonBody.data.list.map(format); const matched = select(list, info);