🐞 fix: V1.6.7-lts 修复网易云音乐 & 修复皮皮虾问题

1. 修复函数`downloadMp3`导致的一系列下载问题
2. 修复netease music下载
3. 修复皮皮虾的问题
4. 修正部分注释
This commit is contained in:
zhiyu1998 2024-04-30 22:35:56 +08:00
parent c2c75fccc0
commit 7e820cbf26
4 changed files with 95 additions and 63 deletions

View File

@ -991,6 +991,15 @@ export class tools extends plugin {
async netease(e) {
let message =
e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim();
// 处理短号此时会变成y.music.163.com
if (message.includes("163cn.tv")) {
message = /(http:|https:)\/\/163cn\.tv\/([a-zA-Z1-9]+)/.exec(message)?.[0]
logger.info(message)
message = await axios.head(message).then((resp) => {
return resp.request.res.responseUrl;
});
}
// 处理网页链接
const musicUrlReg = /(http:|https:)\/\/music.163.com\/song\/media\/outer\/url\?id=(\d+)/;
const musicUrlReg2 = /(http:|https:)\/\/y.music.163.com\/m\/song\?(.*)&id=(\d+)/;
const id =
@ -1005,41 +1014,49 @@ export class tools extends plugin {
if (typeof message !== "string") {
return false;
}
try {
// 小程序
const musicJson = JSON.parse(message);
const { preview, title, desc } = musicJson.meta.music || musicJson.meta.news;
e.reply([`识别:网易云音乐,${ title }--${ desc }`, segment.image(preview)]);
JSON.parse(message);
return true;
} catch (err) {
axios.get(NETEASE_SONG_DOWNLOAD.replace("{}", id), {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
},
}).then(async resp => {
const url = await resp.data.data?.[0].url;
// 获取歌曲信息
const title = await axios.get(NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
const song = res.data.songs[0];
return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
axios.get(NETEASE_SONG_DOWNLOAD.replace("{}", id), {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
},
}).then(async resp => {
logger.info(resp.data)
let url = await resp.data.data?.[0].url;
// 获取歌曲信息
let title = await axios.get(NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
const song = res.data.songs[0];
return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
});
// 一般这个情况是VIP歌曲
if (url == null) {
// 临时接口
const vipMusicData = await axios.get(`https://www.hhlqilongzhu.cn/api/dg_wyymusic.php?gm=${ title }&n=1&type=json`, {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
},
});
e.reply(`识别:网易云音乐,${ title }`);
// const mvUrlJson = await getKugouMv(title, 1, 1, 0);
// const mvUrl = mvUrlJson.map(item => item.mv_url)?.[0];
// this.downloadVideo(mvUrl).then(path => {
// e.reply(segment.video(path + "/temp.mp4"));
// });
downloadMp3(url, 'follow').then(path => {
e.group.sendFile(fs.readFileSync(path), '/', `${ title.replace(/[\/\?<>\\:\*\|".… ]/g, '') }.mp3`);
})
.catch(err => {
console.error(`下载音乐失败,错误信息为: ${ err.message }`);
});
})
return true;
}
title += "\nR插件检测到当前为VIP音乐正在转换...";
url = vipMusicData.data.music_url;
}
e.reply(`识别:网易云音乐,${ title }`);
// const mvUrlJson = await getKugouMv(title, 1, 1, 0);
// const mvUrl = mvUrlJson.map(item => item.mv_url)?.[0];
// this.downloadVideo(mvUrl).then(path => {
// e.reply(segment.video(path + "/temp.mp4"));
// });
downloadMp3(url, 'follow').then(path => {
// 判断是不是icqq
if (e.bot?.sendUni) {
e.group.fs.upload(path);
} else {
e.group.sendFile(path);
}
}).catch(err => {
logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
});
})
return true;
}
// 微博解析

View File

@ -92,7 +92,7 @@ export const TWITTER_TWEET_INFO = "https://api.twitter.com/2/tweets?ids={}"
export const XHS_REQ_LINK = "https://www.xiaohongshu.com/explore/"
/**
* 🍉 的请求链接
* 通用解析的请求链接
* @type {string}
*/
export const GENERAL_REQ_LINK = {

View File

@ -130,39 +130,54 @@ export function generateRandomStr(randomlength = 16) {
* @returns {Promise<unknown>}
*/
export async function downloadMp3(mp3Url, path, redirect = "manual") {
return fetch(mp3Url, {
// 如果没有目录就创建一个
await mkdirIfNotExists(path)
// 补充保存文件名
path += "/temp.mp3";
if (fs.existsSync(path)) {
console.log(`音频已存在`);
fs.unlinkSync(path);
}
// 发起请求
const response = await fetch(mp3Url, {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
},
responseType: "stream",
redirect: redirect,
}).then(async res => {
// 如果没有目录就创建一个
await mkdirIfNotExists(path)
// 补充保存文件名
path += "/temp.mp3";
if (fs.existsSync(path)) {
console.log(`音频已存在`);
fs.unlinkSync(path);
}
// 开始下载
const fileStream = fs.createWriteStream(path);
res.body.pipe(fileStream);
return new Promise((resolve, reject) => {
fileStream.on("finish", () => {
fileStream.close(() => {
resolve(path);
});
});
fileStream.on("error", err => {
fs.unlink(path, () => {
reject(err);
});
});
});
});
if (!response.ok) {
throw new Error(`Failed to fetch ${response.statusText}`);
}
try {
const response = await axios({
method: 'get',
url: mp3Url,
responseType: 'stream',
headers: {
"User-Agent": "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36"
}
});
// 开始下载
const writer = fs.createWriteStream(path);
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', () => resolve(path));
writer.on('error', reject);
});
} catch (error) {
console.error(`下载音乐失败,错误信息为: ${error.message}`);
throw error;
}
}
/**

View File

@ -33,6 +33,7 @@ class GeneralLinkAdapter {
* @returns {*}
*/
createReqLink(externalInterface, requestURL) {
// 这里必须使用{ ...GENERAL_REQ_LINK_2 }赋值,不然就是对象的引用赋值,会造成全局数据问题!
let reqLink = { ...externalInterface };
reqLink.link = reqLink.link.replace("{}", requestURL);
return reqLink;
@ -81,8 +82,7 @@ class GeneralLinkAdapter {
async pipixia(link) {
const msg = /https:\/\/h5\.pipix\.com\/s\/[A-Za-z0-9]+/.exec(link)?.[0];
// 这里必须使用{ ...GENERAL_REQ_LINK_2 }赋值,不然就是对象的引用赋值,会造成全局数据问题!
const reqLink = this.createReqLink(GENERAL_REQ_LINK_2, msg);
const reqLink = this.createReqLink(GENERAL_REQ_LINK, msg);
return { name: "皮皮虾", reqLink };
}