mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: 修复国内AM解析不出问题
This commit is contained in:
parent
eb9c130bca
commit
e6397ed8b5
@ -39,7 +39,7 @@ import {
|
|||||||
getIdVideo, retryAxiosReq,
|
getIdVideo, retryAxiosReq,
|
||||||
secondsToTime,
|
secondsToTime,
|
||||||
testProxy,
|
testProxy,
|
||||||
truncateString
|
truncateString, checkCommandExists
|
||||||
} 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";
|
||||||
@ -1011,17 +1011,7 @@ export class tools extends plugin {
|
|||||||
});
|
});
|
||||||
// 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||')
|
// 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||')
|
||||||
if (!isOversea || url == null) {
|
if (!isOversea || url == null) {
|
||||||
// 临时接口,title经过变换后搜索到的音乐质量提升
|
url = await this.musicTempApi(e, title, "网易云音乐");
|
||||||
const vipMusicData = await axios.get(NETEASE_TEMP_API.replace("{}", title.replace("-", " ")), {
|
|
||||||
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 messageTitle = title + "\nR插件检测到当前为VIP音乐,正在转换...";
|
|
||||||
url = vipMusicData.data.mp3;
|
|
||||||
const cover = vipMusicData.data.img;
|
|
||||||
e.reply([segment.image(cover), `识别:网易云音乐,${ messageTitle }`]);
|
|
||||||
} else {
|
} else {
|
||||||
// 不是VIP歌曲,直接识别完就下一步
|
// 不是VIP歌曲,直接识别完就下一步
|
||||||
e.reply(`识别:网易云音乐,${ title }`);
|
e.reply(`识别:网易云音乐,${ title }`);
|
||||||
@ -1044,6 +1034,22 @@ export class tools extends plugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 临时接口
|
||||||
|
async musicTempApi(e, title, musicType) {
|
||||||
|
// 临时接口,title经过变换后搜索到的音乐质量提升
|
||||||
|
const vipMusicData = await axios.get(NETEASE_TEMP_API.replace("{}", title.replace("-", " ")), {
|
||||||
|
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 messageTitle = title + "\nR插件检测到当前为VIP音乐,正在转换...";
|
||||||
|
const url = vipMusicData.data.mp3;
|
||||||
|
const cover = vipMusicData.data.img;
|
||||||
|
e.reply([segment.image(cover), `识别:${musicType},${ messageTitle }`]);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
// 微博解析
|
// 微博解析
|
||||||
async weibo(e) {
|
async weibo(e) {
|
||||||
let weiboId;
|
let weiboId;
|
||||||
@ -1475,28 +1481,42 @@ export class tools extends plugin {
|
|||||||
const currentWorkingDirectory = path.resolve(this.defaultPath);
|
const currentWorkingDirectory = path.resolve(this.defaultPath);
|
||||||
// 如果没有文件夹就创建一个
|
// 如果没有文件夹就创建一个
|
||||||
await mkdirIfNotExists(currentWorkingDirectory + "/am")
|
await mkdirIfNotExists(currentWorkingDirectory + "/am")
|
||||||
|
// 检测是否存在框架
|
||||||
|
const isExistFreyr = await checkCommandExists("freyr");
|
||||||
|
if (!isExistFreyr) {
|
||||||
|
e.reply(`检测到没有${freyrName}需要的环境,无法解析!${HELP_DOC}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 执行命令
|
// 执行命令
|
||||||
const result = await execSync(`freyr -d ${ currentWorkingDirectory + "/am/" } get ${ message }`);
|
const result = await execSync(`freyr -d ${ currentWorkingDirectory + "/am/" } get ${ message }`);
|
||||||
logger.info(result.toString());
|
logger.info(result.toString());
|
||||||
// 获取信息
|
// 获取信息
|
||||||
const { title, album, artist } = await this.parseFreyrLog(result.toString());
|
let { title, album, artist } = await this.parseFreyrLog(result.toString());
|
||||||
e.reply(`识别:${ freyrName },${ title }--${ artist }\n${ album }`);
|
// 兜底策略
|
||||||
|
if (freyrName === "Apple Music" && (title === "N/A" || album === "N/A" || artist === "N/A")) {
|
||||||
|
const data = await axios.get(`https://api.fabdl.com/apple-music/get?url=${message}`, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
|
||||||
|
"Referer": "https://apple-music-downloader.com/",
|
||||||
|
"Origin": "https://apple-music-downloader.com",
|
||||||
|
"Accept": "application/json, text/plain, */*",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const { name, artists } = data.data.result;
|
||||||
|
title = name;
|
||||||
|
artist = artists;
|
||||||
|
}
|
||||||
|
e.reply(`识别:${ freyrName },${ title }--${ artist }`);
|
||||||
// 判断是否是海外服务器
|
// 判断是否是海外服务器
|
||||||
const isOversea = await this.isOverseasServer();
|
const isOversea = await this.isOverseasServer();
|
||||||
// 国内服务器解决方案
|
// 国内服务器解决方案
|
||||||
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
|
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
|
||||||
// 临时接口
|
// 临时接口
|
||||||
const vipMusicData = await axios.get(NETEASE_TEMP_API.replace("{}", title), {
|
const url = await this.musicTempApi(e, `${title} ${artist}`, freyrName);
|
||||||
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 url = vipMusicData.data.mp3;
|
|
||||||
// 下载音乐
|
// 下载音乐
|
||||||
downloadAudio(url, this.getCurDownloadPath(e), title, 'follow').then(async path => {
|
downloadAudio(url, this.getCurDownloadPath(e), title, 'follow').then(async path => {
|
||||||
// 发送语音
|
// 发送语音
|
||||||
// e.reply(segment.record(path));
|
await e.reply(segment.record(path));
|
||||||
// 判断是不是icqq
|
// 判断是不是icqq
|
||||||
await this.uploadGroupFile(e, path);
|
await this.uploadGroupFile(e, path);
|
||||||
await checkAndRemoveFile(path);
|
await checkAndRemoveFile(path);
|
||||||
|
@ -6,6 +6,7 @@ import fs from "node:fs";
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { mkdirIfNotExists } from "./file.js";
|
import { mkdirIfNotExists } from "./file.js";
|
||||||
import { TEN_THOUSAND } from "../constants/constant.js";
|
import { TEN_THOUSAND } from "../constants/constant.js";
|
||||||
|
import { exec } from "child_process";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求模板
|
* 请求模板
|
||||||
@ -407,3 +408,22 @@ export function estimateReadingTime(text, wpm = 200) {
|
|||||||
words: wordCount
|
words: wordCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否存在某个命令
|
||||||
|
* @param command
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
export function checkCommandExists(command) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(`which ${command}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
// Command not found
|
||||||
|
resolve(false);
|
||||||
|
} else {
|
||||||
|
// Command found
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user