Skip to content

Commit

Permalink
feat: setup getMusicURL_v2
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Oct 7, 2024
1 parent 4fd0a16 commit e854769
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions server/api/search/song.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMusicURL } from '~/server/lib/song';
import { getMusicURL, getMusicURL_v2 } from '~/server/lib/song';
import type { TSearchResponse } from '~~/types';
import { searchSchema } from '~~/types';

Expand Down Expand Up @@ -37,7 +37,14 @@ export default eventHandler(async (event) => {
},
});
const songMidArray = res.data.song.itemlist.map(item => item.mid);
const urls = await getMusicURL(songMidArray);
const urls: Record<string, string> = {};

for (const mid of songMidArray) {
const b = await getMusicURL_v2(mid);
urls[mid] = b;
}

// const urls = await getMusicURL(songMidArray);
const songList = res.data.song.itemlist.map(item => ({
mid: item.mid,
name: item.name,
Expand Down
18 changes: 18 additions & 0 deletions server/lib/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,21 @@ export async function getMusicURL(midArray: string[]) {
}
return data;
}

export async function getMusicURL_v2(mid: string) {
const res = await $fetch<any>(
`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data=%7B%22req_0%22%3A%7B%22module%22%3A%22vkey.GetVkeyServer%22%2C%22method%22%3A%22CgiGetVkey%22%2C%22param%22%3A%7B%22guid%22%3A%22358840384%22%2C%22songmid%22%3A%5B%22${mid}%22%5D%2C%22songtype%22%3A%5B0%5D%2C%22uin%22%3A%221443481947%22%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A%2218585073516%22%2C%22format%22%3A%22json%22%2C%22ct%22%3A24%2C%22cv%22%3A0%7D%7D`,
{
parseResponse(responseText) {
try {
return JSON.parse(responseText);
} catch {
return responseText;
}
},
},
);

const url_b = res.req_0.data.testfile2g.split('?');
return `https://ws.stream.qqmusic.qq.com/${res.req_0.data.midurlinfo[0].filename}?${url_b[1]}&src=${url_b[0]}`;
}

0 comments on commit e854769

Please sign in to comment.