mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: V1.6.7-lts 完善函数downloadMp3
& 修复netease-music国内无法解析问题
1. 完善函数`downloadMp3` 2. 修复netease-music国内无法解析问题
This commit is contained in:
parent
7e820cbf26
commit
36a1ebd098
@ -7,13 +7,15 @@ import axios from "axios";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import tunnel from "tunnel";
|
import tunnel from "tunnel";
|
||||||
import HttpProxyAgent from "https-proxy-agent";
|
import HttpProxyAgent from "https-proxy-agent";
|
||||||
import { execSync, exec } from "child_process";
|
import { exec, execSync } from "child_process";
|
||||||
import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists, readCurrentDir } from "../utils/file.js";
|
import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists, readCurrentDir } from "../utils/file.js";
|
||||||
import {
|
import {
|
||||||
downloadBFile,
|
downloadBFile,
|
||||||
getBiliAudio, getBiliVideoWithSession,
|
getBiliAudio,
|
||||||
|
getBiliVideoWithSession,
|
||||||
getDownloadUrl,
|
getDownloadUrl,
|
||||||
getDynamic, getScanCodeData,
|
getDynamic,
|
||||||
|
getScanCodeData,
|
||||||
getVideoInfo,
|
getVideoInfo,
|
||||||
m4sToMp3,
|
m4sToMp3,
|
||||||
mergeFileToMp4
|
mergeFileToMp4
|
||||||
@ -29,12 +31,13 @@ import {
|
|||||||
XHS_NO_WATERMARK_HEADER,
|
XHS_NO_WATERMARK_HEADER,
|
||||||
} from "../constants/constant.js";
|
} from "../constants/constant.js";
|
||||||
import {
|
import {
|
||||||
containsChinese,
|
|
||||||
downloadImg,
|
downloadImg,
|
||||||
downloadMp3,
|
downloadMp3,
|
||||||
formatBiliInfo, formatSeconds,
|
formatBiliInfo,
|
||||||
getIdVideo,
|
getIdVideo,
|
||||||
secondsToTime, testProxy, truncateString
|
secondsToTime,
|
||||||
|
testProxy,
|
||||||
|
truncateString
|
||||||
} from "../utils/common.js";
|
} from "../utils/common.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
import Translate from "../utils/trans-strategy.js";
|
import Translate from "../utils/trans-strategy.js";
|
||||||
@ -48,11 +51,15 @@ import { getWbi } from "../utils/biliWbi.js";
|
|||||||
import {
|
import {
|
||||||
BILI_SUMMARY,
|
BILI_SUMMARY,
|
||||||
DY_INFO,
|
DY_INFO,
|
||||||
MIYOUSHE_ARTICLE, NETEASE_SONG_DETAIL, NETEASE_SONG_DOWNLOAD,
|
GENERAL_REQ_LINK,
|
||||||
|
MIYOUSHE_ARTICLE,
|
||||||
|
NETEASE_SONG_DETAIL,
|
||||||
|
NETEASE_SONG_DOWNLOAD,
|
||||||
TIKTOK_INFO,
|
TIKTOK_INFO,
|
||||||
TWITTER_TWEET_INFO,
|
TWITTER_TWEET_INFO,
|
||||||
XHS_REQ_LINK,
|
WEIBO_SINGLE_INFO,
|
||||||
GENERAL_REQ_LINK, WEIBO_SINGLE_INFO, WEISHI_VIDEO_INFO, BILI_SCAN_CODE_GENERATE
|
WEISHI_VIDEO_INFO,
|
||||||
|
XHS_REQ_LINK
|
||||||
} from "../constants/tools.js";
|
} from "../constants/tools.js";
|
||||||
import { processTikTokUrl } from "../utils/tiktok.js";
|
import { processTikTokUrl } from "../utils/tiktok.js";
|
||||||
import { getDS } from "../utils/mihoyo.js";
|
import { getDS } from "../utils/mihoyo.js";
|
||||||
@ -1009,21 +1016,26 @@ export class tools extends plugin {
|
|||||||
// 如果没有下载地址跳出if
|
// 如果没有下载地址跳出if
|
||||||
if (_.isEmpty(id)) {
|
if (_.isEmpty(id)) {
|
||||||
e.reply(`识别:网易云音乐,解析失败!`);
|
e.reply(`识别:网易云音乐,解析失败!`);
|
||||||
|
logger.error("[R插件][网易云解析] 没有找到id,无法进行下一步!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (typeof message !== "string") {
|
// 判断海外
|
||||||
return false;
|
const isOversea = await this.isOverseasServer();
|
||||||
}
|
// 国内解决方案,替换为国内API
|
||||||
axios.get(NETEASE_SONG_DOWNLOAD.replace("{}", id), {
|
const AUTO_NETEASE_SONG_DOWNLOAD = isOversea ? NETEASE_SONG_DOWNLOAD : `http://cloud-music.pl-fe.cn/song/url?id={}`;
|
||||||
|
const AUTO_NETEASE_SONG_DETAIL = isOversea ? NETEASE_SONG_DETAIL : `http://cloud-music.pl-fe.cn/song/detail?ids={}`;
|
||||||
|
logger.info(AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", id));
|
||||||
|
// 请求netease数据
|
||||||
|
axios.get(AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", id), {
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent":
|
"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",
|
"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 => {
|
}).then(async resp => {
|
||||||
logger.info(resp.data)
|
// 国内解决方案,替换API后这里也需要修改
|
||||||
let url = await resp.data.data?.[0].url;
|
let url = isOversea ? await resp.data.data?.[0].url : await resp.data.data.url;
|
||||||
// 获取歌曲信息
|
// 获取歌曲信息
|
||||||
let title = await axios.get(NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
|
let title = await axios.get(AUTO_NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
|
||||||
const song = res.data.songs[0];
|
const song = res.data.songs[0];
|
||||||
return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
|
return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
|
||||||
});
|
});
|
||||||
@ -1036,26 +1048,28 @@ export class tools extends plugin {
|
|||||||
"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",
|
"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",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
title += "\nR插件检测到当前为VIP音乐,正在转换...";
|
const messageTitle = title + "\nR插件检测到当前为VIP音乐,正在转换...";
|
||||||
url = vipMusicData.data.music_url;
|
url = vipMusicData.data.music_url;
|
||||||
|
e.reply(`识别:网易云音乐,${ messageTitle }`);
|
||||||
|
} else {
|
||||||
|
// 不是VIP歌曲,直接识别完就下一步
|
||||||
|
e.reply(`识别:网易云音乐,${ title }`);
|
||||||
}
|
}
|
||||||
e.reply(`识别:网易云音乐,${ title }`);
|
// 下载音乐
|
||||||
// const mvUrlJson = await getKugouMv(title, 1, 1, 0);
|
downloadMp3(url, this.getCurDownloadPath(e), title, 'follow').then(async path => {
|
||||||
// const mvUrl = mvUrlJson.map(item => item.mv_url)?.[0];
|
// 发送语音
|
||||||
// this.downloadVideo(mvUrl).then(path => {
|
e.reply(segment.record(path));
|
||||||
// e.reply(segment.video(path + "/temp.mp4"));
|
|
||||||
// });
|
|
||||||
downloadMp3(url, 'follow').then(path => {
|
|
||||||
// 判断是不是icqq
|
// 判断是不是icqq
|
||||||
if (e.bot?.sendUni) {
|
if (e.bot?.sendUni) {
|
||||||
e.group.fs.upload(path);
|
e.group.fs.upload(path);
|
||||||
} else {
|
} else {
|
||||||
e.group.sendFile(path);
|
e.group.sendFile(path);
|
||||||
}
|
}
|
||||||
|
await checkAndRemoveFile(path);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
|
logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,15 +126,16 @@ export function generateRandomStr(randomlength = 16) {
|
|||||||
* 下载mp3
|
* 下载mp3
|
||||||
* @param mp3Url MP3地址
|
* @param mp3Url MP3地址
|
||||||
* @param path 下载目录
|
* @param path 下载目录
|
||||||
|
* @param title 音乐名
|
||||||
* @param redirect 是否要重定向
|
* @param redirect 是否要重定向
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
export async function downloadMp3(mp3Url, path, redirect = "manual") {
|
export async function downloadMp3(mp3Url, path, title = "temp", redirect = "manual") {
|
||||||
// 如果没有目录就创建一个
|
// 如果没有目录就创建一个
|
||||||
await mkdirIfNotExists(path)
|
await mkdirIfNotExists(path)
|
||||||
|
|
||||||
// 补充保存文件名
|
// 补充保存文件名
|
||||||
path += "/temp.mp3";
|
path += `/${ title }.mp3`;
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
console.log(`音频已存在`);
|
console.log(`音频已存在`);
|
||||||
fs.unlinkSync(path);
|
fs.unlinkSync(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user