rsshub
Version:
Make RSS Great Again!
86 lines (84 loc) • 2.73 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import "./md5-C8GRvctM.mjs";
import "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import "./render-BQo6B4tL.mjs";
import "./proxy-Db7uGcYb.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import "./puppeteer-DGmvuGvT.mjs";
import "./utils-XRYoJEu4.mjs";
import { t as cache_default } from "./cache-COvn8_4R.mjs";
import y from "node:zlib";
import { load } from "cheerio";
//#region lib/routes/bilibili/danmaku.ts
const processFloatTime = (time) => {
const totalSeconds = Number.parseInt(time);
const seconds = totalSeconds % 60;
const minutes = (totalSeconds - seconds) / 60 % 60;
return `${(totalSeconds - seconds - 60 * minutes) / 3600}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
};
const route = {
path: "/video/danmaku/:bvid/:pid?",
categories: ["social-media"],
example: "/bilibili/video/danmaku/BV1vA411b7ip/1",
parameters: {
bvid: "视频AV号,可在视频页 URL 中找到",
pid: "分P号,不填默认为1"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "视频弹幕",
maintainers: ["Qixingchen"],
handler
};
async function handler(ctx) {
let bvid = ctx.req.param("bvid");
let aid;
if (!bvid.startsWith("BV")) {
aid = bvid;
bvid = null;
}
const pid = Number(ctx.req.param("pid") || 1);
const limit = 50;
const cid = await cache_default.getCidFromId(aid, pid, bvid);
const videoName = await cache_default.getVideoNameFromId(aid, bvid);
const link = `https://www.bilibili.com/video/${bvid || `av${aid}`}`;
let danmakuText = (await got_default.get(`https://comment.bilibili.com/${cid}.xml`, {
decompress: false,
responseType: "buffer",
headers: { Referer: link }
})).body;
danmakuText = await ((danmakuText[0] & 15) === 8 ? y.inflateSync(danmakuText) : y.inflateRawSync(danmakuText));
let danmakuList = [];
const $ = load(danmakuText, { xmlMode: true });
$("d").each((index, item) => {
danmakuList.push({
p: $(item).attr("p"),
text: $(item).text()
});
});
danmakuList = danmakuList.toReversed().slice(0, limit);
return {
title: `${videoName} 的 弹幕动态`,
link,
description: `${videoName} 的 弹幕动态`,
item: danmakuList.map((item) => ({
title: `[${processFloatTime(item.p.split(",")[0])}] ${item.text}`,
pubDate: (/* @__PURE__ */ new Date(item.p.split(",")[4] * 1e3)).toUTCString(),
guid: `${cid}-${item.p.split(",")[4]}-${item.p.split(",")[7]}`,
link
}))
};
}
//#endregion
export { route };