Skip to content

Commit

Permalink
feat(provider/kuwo): allow custom CSRF Token
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Jul 19, 2023
1 parent 599eadd commit b871bb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your_wmid>; session_key=<your_session_key>"` |
| KUWO_COOKIE | str | 酷我音源的 CSRF Token | `KUWO_COOKIE=Hm_Iuvt_<encpwd>=<token>; Secret=<secret>` |
| MIGU_COOKIE | str | 咪咕音源的 aversionid cookie | `MIGU_COOKIE="<your_aversionid>"` |
| QQ_COOKIE | str | QQ 音源的 uin 和 qm_keyst cookie | `QQ_COOKIE="uin=<your_uin>; qm_keyst=<your_qm_keyst>"` |
| YOUTUBE_KEY | str | Youtube 音源的 Data API v3 Key | `YOUTUBE_KEY="<your_data_api_key>"` |
Expand Down
14 changes: 5 additions & 9 deletions src/provider/kuwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b871bb9

Please sign in to comment.