Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 kuwo 音源 && 音乐云盘上传 #1207

Merged
merged 7 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ hook.request.before = (ctx) => {
if ('x-napm-retry' in req.headers)
delete req.headers['x-napm-retry'];
req.headers['X-Real-IP'] = '118.88.88.88';
req.headers['Accept-Encoding'] = 'gzip, deflate'; // https://blog.csdn.net/u013022222/article/details/51707352
if (!req.url.includes("/eapi/cloud/upload/check"))
req.headers['Accept-Encoding'] = 'gzip, deflate'; // https://blog.csdn.net/u013022222/article/details/51707352
if (req.url.includes('stream')) return; // look living eapi can not be decrypted
if (body) {
let data;
Expand Down
45 changes: 29 additions & 16 deletions src/provider/kuwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const request = require('../request');
const { getManagedCacheStorage } = require('../cache');

const format = (song) => ({
id: song.musicrid.split('_').pop(),
name: song.name,
id: song.MUSICRID.split('_').pop(),
name: song.SONGNAME,
// duration: song.songTimeMinutes.split(':').reduce((minute, second) => minute * 60 + parseFloat(second), 0) * 1000,
duration: song.duration * 1000,
album: { id: song.albumid, name: song.album },
artists: song.artist
album: { id: song.ALBUMID, name: song.album },
artists: song.ARTIST
.split('&')
.map((name, index) => ({ id: index ? null : song.artistid, name })),
.map((name, index) => ({ id: index ? null : song.ARTISTID, name })),
});

const search = (info) => {
Expand Down Expand Up @@ -43,22 +43,35 @@ const search = (info) => {
// return Promise.reject()
// })

// const keyword = encodeURIComponent(info.keyword.replace(' - ', ' '));
// const url = `http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=${keyword}&pn=1&rn=30`;
// const cookie = process.env.KUWO_COOKIE || null;

// return request('GET', url, {
// referer: `http://www.kuwo.cn/search/list?key=${keyword}`,
// secret: cookie
// ? (cookie.match(/Secret=([0-9a-f]{72})/) || [])[1]
// : null,
// cookie,
// })
// .then((response) => response.json())
// .then((jsonBody) => {
// if (!jsonBody || jsonBody.code !== 200 || jsonBody.data.total < 1)
// return Promise.reject();
// const list = jsonBody.data.list.map(format);
// const matched = select(list, info);
// return matched ? matched.id : Promise.reject();
// });

const keyword = encodeURIComponent(info.keyword.replace(' - ', ' '));
const url = `http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key=${keyword}&pn=1&rn=30`;
const cookie = process.env.KUWO_COOKIE || null;
const url = `http://search.kuwo.cn/r.s?user=114514&android_id=114514&prod=kwplayer_ar_10.5.5.0&corp=kuwo&newver=3&vipver=10.5.5.0&source=kwplayer_ar_10.5.5.0_40.apk&p2p=1&q36=f2ce3c2ef68ddfd1b2bea7ed00001f314716&loginUid=114514&loginSid=1919810&notrace=0&client=kt&all=${keyword}&correct=1&uid=114514&loginid=1919810&ver=kwplayer_ar_10.5.5.0&stype=comprehensive&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&show_copyright_off=1&issubtitle=1&searchapi=6&province=&city=&latitude=&longtitude=&userIP=8.8.8.8&spPrivilege=0&qq-pf-to=pcqq.group`;

return request('GET', url, {
referer: `http://www.kuwo.cn/search/list?key=${keyword}`,
secret: cookie
? (cookie.match(/Secret=([0-9a-f]{72})/) || [])[1]
: null,
cookie,
})
return request('GET', url)
.then((response) => response.json())
.then((jsonBody) => {
if (!jsonBody || jsonBody.code !== 200 || jsonBody.data.total < 1)
if (!jsonBody || jsonBody.content.length < 2 || !jsonBody.content[1].musicpage || jsonBody.content[1].musicpage.abslist.length < 1)
return Promise.reject();
const list = jsonBody.data.list.map(format);
const list = jsonBody.content[1].musicpage.abslist.map(format);
const matched = select(list, info);
return matched ? matched.id : Promise.reject();
});
Expand Down