mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🦄 refactor: 重构波点音乐
This commit is contained in:
parent
6bbe9ca3ed
commit
ec6248150a
@ -11,12 +11,13 @@ import { mkdirsSync } from "../utils/file.js";
|
|||||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
||||||
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
||||||
import { transMap, douyinTypeMap, XHS_CK, TEN_THOUSAND } from "../utils/constant.js";
|
import { transMap, douyinTypeMap, XHS_CK, TEN_THOUSAND } from "../utils/constant.js";
|
||||||
import { getIdVideo, generateRandomStr, downloadMp3 } from "../utils/common.js";
|
import { getIdVideo, generateRandomStr } 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";
|
||||||
import { getXB } from "../utils/x-bogus.js";
|
import { getXB } from "../utils/x-bogus.js";
|
||||||
import { getVideoInfo } from "../utils/biliInfo.js";
|
import { getVideoInfo } from "../utils/biliInfo.js";
|
||||||
import { getBiliGptInputText } from "../utils/biliSummary.js";
|
import { getBiliGptInputText } from "../utils/biliSummary.js";
|
||||||
|
import {getBodianAudio, getBodianMv, getBodianMusicInfo} from "../utils/bodian.js";
|
||||||
import { ChatGPTClient } from "@waylaidwanderer/chatgpt-api";
|
import { ChatGPTClient } from "@waylaidwanderer/chatgpt-api";
|
||||||
|
|
||||||
export class tools extends plugin {
|
export class tools extends plugin {
|
||||||
@ -912,39 +913,30 @@ export class tools extends plugin {
|
|||||||
|
|
||||||
// 波点音乐解析
|
// 波点音乐解析
|
||||||
async bodianMusic(e) {
|
async bodianMusic(e) {
|
||||||
// 例子:https://h5app.kuwo.cn/m/bodian/playMusic.html?uid=3216773&musicId=192015898&opusId=&extendType=together
|
// 音频例子:https://h5app.kuwo.cn/m/bodian/playMusic.html?uid=3216773&musicId=192015898&opusId=&extendType=together
|
||||||
const id = /(?=musicId).*?(?=&)/.exec(e.msg.trim())[0].replace("musicId=", "");
|
// 视频例子:https://h5app.kuwo.cn/m/bodian/play.html?uid=3216773&mvId=118987&opusId=770096&extendType=together
|
||||||
const API = `https://bd-api.kuwo.cn/api/service/music/audioUrl/${id}?format=mp3&br=320kmp3&songType=&fromList=&weListenUid=&weListenDevId=`;
|
const id = /(?=musicId).*?(?=&)/.exec(e.msg.trim())?.[0].replace("musicId=", "")
|
||||||
const headers = {
|
|| /(?=mvId).*?(?=&)/.exec(e.msg.trim())?.[0].replace("mvId=", "");
|
||||||
"User-Agent": "bodian/106 CFNetwork/1399 Darwin/22.1.0",
|
const {name, album, artist, albumPic120, categorys} = await getBodianMusicInfo(id)
|
||||||
devId: `95289318-8847-43D5-8477-85296654785${String.fromCharCode(
|
e.reply([`识别:波点音乐,${name}-${album}-${artist}\n标签:${categorys.map(item=>item.name).join(" | ")}`, segment.image(albumPic120)])
|
||||||
65 + Math.floor(Math.random() * 26),
|
if (e.msg.includes("musicId")) {
|
||||||
)}`,
|
const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}`
|
||||||
Host: "bd-api.kuwo.cn",
|
await getBodianAudio(id, path).then(_ => {
|
||||||
plat: "ip",
|
|
||||||
ver: "3.1.0",
|
|
||||||
"Cache-Control": "no-cache",
|
|
||||||
channel: "appstore",
|
|
||||||
};
|
|
||||||
await axios
|
|
||||||
.get(API, {
|
|
||||||
headers,
|
|
||||||
})
|
|
||||||
.then(resp => {
|
|
||||||
const respJson = resp.data;
|
|
||||||
const audioUrl = respJson.data.audioUrl;
|
|
||||||
downloadMp3(audioUrl, `${this.defaultPath}${this.e.group_id || this.e.user_id}`)
|
|
||||||
.then(path => {
|
|
||||||
Bot.acquireGfs(e.group_id).upload(
|
Bot.acquireGfs(e.group_id).upload(
|
||||||
fs.readFileSync(path),
|
fs.readFileSync(path+"/temp.mp3"),
|
||||||
"/",
|
"/",
|
||||||
`${respJson.reqId}.mp3`,
|
`${name}-${album}-${artist}.mp3`,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
} else if (e.msg.includes("mvId")) {
|
||||||
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
await getBodianMv(id).then(res => {
|
||||||
});
|
// 下载 && 发送
|
||||||
|
const { coverUrl, highUrl, lowUrl, shortLowUrl } = res
|
||||||
|
this.downloadVideo(lowUrl).then(path => {
|
||||||
|
e.reply(segment.video(path + "/temp.mp4"));
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
97
utils/bodian.js
Normal file
97
utils/bodian.js
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import { downloadMp3, generateRandomStr } from "./common.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取音频
|
||||||
|
* @param id
|
||||||
|
* @param path
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
|
async function getBodianAudio(id, path) {
|
||||||
|
// 音乐数据
|
||||||
|
const API = `https://bd-api.kuwo.cn/api/service/music/audioUrl/${id}?format=mp3&br=320kmp3&songType=&fromList=&weListenUid=&weListenDevId=`;
|
||||||
|
const headers = {
|
||||||
|
"User-Agent": "bodian/106 CFNetwork/1399 Darwin/22.1.0",
|
||||||
|
devId: `95289318-8847-43D5-8477-85296654785${String.fromCharCode(
|
||||||
|
65 + Math.floor(Math.random() * 26),
|
||||||
|
)}`,
|
||||||
|
Host: "bd-api.kuwo.cn",
|
||||||
|
plat: "ip",
|
||||||
|
ver: "3.1.0",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
channel: "appstore",
|
||||||
|
};
|
||||||
|
return await axios
|
||||||
|
.get(API, {
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
.then(async resp => {
|
||||||
|
const respJson = resp.data;
|
||||||
|
const audioUrl = respJson.data.audioUrl;
|
||||||
|
await downloadMp3(audioUrl, path)
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
||||||
|
});
|
||||||
|
return respJson;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取MV地址
|
||||||
|
* @param id
|
||||||
|
* @returns {Promise<(fid: string, pid: string) => Promise<void>>}
|
||||||
|
*/
|
||||||
|
async function getBodianMv(id) {
|
||||||
|
// mv数据
|
||||||
|
const API = `https://bd-api.kuwo.cn/api/service/mv/info?musicId=${id}&wifi=1&noWifi=1&uid=-1&token=`
|
||||||
|
const headers = {
|
||||||
|
"User-Agent": "Dart/2.18 (dart:io)",
|
||||||
|
plat: "ar",
|
||||||
|
ver: "3.1.0",
|
||||||
|
host: "bd-api.kuwo.cn",
|
||||||
|
channel: "aliopen",
|
||||||
|
devId: generateRandomStr(16)
|
||||||
|
}
|
||||||
|
return await axios.get(API, {
|
||||||
|
headers
|
||||||
|
}).then(async resp => {
|
||||||
|
const res = resp.data;
|
||||||
|
// 如果没有,直接返回
|
||||||
|
if (res.data.lowUrl === null || res.data.highUrl === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 波点音乐信息
|
||||||
|
return res.data.mv;
|
||||||
|
}).catch(err => {
|
||||||
|
logger.error("波点音乐错误");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取音乐信息
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function getBodianMusicInfo(id) {
|
||||||
|
const API = `https://bd-api.kuwo.cn/api/service/music/info?musicId=${id}&uid=-1&token=`
|
||||||
|
const headers = {
|
||||||
|
"User-Agent": "Dart/2.18 (dart:io)",
|
||||||
|
plat: "ar",
|
||||||
|
ver: "3.1.0",
|
||||||
|
host: "bd-api.kuwo.cn",
|
||||||
|
channel: "aliopen",
|
||||||
|
devId: generateRandomStr(16)
|
||||||
|
}
|
||||||
|
return await axios.get(API, {
|
||||||
|
headers
|
||||||
|
}).then(async resp => {
|
||||||
|
return resp.data?.data;
|
||||||
|
}).catch(err => {
|
||||||
|
logger.error("波点音乐错误");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
getBodianAudio,
|
||||||
|
getBodianMv,
|
||||||
|
getBodianMusicInfo
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user