mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
26 lines
792 B
JavaScript
26 lines
792 B
JavaScript
import fetch from "node-fetch";
|
|
|
|
async function getVideoInfo(url) {
|
|
const baseVideoInfo = "http://api.bilibili.com/x/web-interface/view";
|
|
const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1];
|
|
// 获取视频信息,然后发送
|
|
return fetch(
|
|
videoId.startsWith("BV")
|
|
? `${baseVideoInfo}?bvid=${videoId}`
|
|
: `${baseVideoInfo}?aid=${videoId}`,
|
|
).then(async resp => {
|
|
const respJson = await resp.json();
|
|
const respData = respJson.data;
|
|
return {
|
|
title: respData.title,
|
|
desc: respData.desc,
|
|
dynamic: respJson.data.dynamic,
|
|
stat: respData.stat,
|
|
aid: respData.aid,
|
|
cid: respData.pages?.[0].cid,
|
|
};
|
|
});
|
|
}
|
|
|
|
export { getVideoInfo };
|