feat: bilibili bvid /video/danamku

This commit is contained in:
DIYgod
2020-04-28 15:23:22 +08:00
parent 67bd2786bc
commit 481f625a05
5 changed files with 22 additions and 13 deletions

View File

@@ -178,7 +178,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 视频弹幕
<Route author="Qixingchen" example="/bilibili/video/danmaku/21669336/1" path="/bilibili/video/danmaku/:aid/:pid?" :paramsDesc="['视频AV号,可在视频页 URL 中找到','分P号,不填默认为1']"/>
<Route author="Qixingchen" example="/bilibili/video/danmaku/BV1vA411b7ip/1" path="/bilibili/video/danmaku/:bvid/:pid?" :paramsDesc="['视频AV号,可在视频页 URL 中找到','分P号,不填默认为1']"/>
### link 公告

View File

@@ -58,7 +58,7 @@ router.get('/bilibili/bangumi/:seasonid', require('./routes/bilibili/bangumi'));
router.get('/bilibili/bangumi/media/:mediaid', require('./routes/bilibili/bangumi'));
router.get('/bilibili/video/page/:bvid/:disableEmbed?', require('./routes/bilibili/page'));
router.get('/bilibili/video/reply/:bvid', require('./routes/bilibili/reply'));
router.get('/bilibili/video/danmaku/:aid/:pid?', require('./routes/bilibili/danmaku'));
router.get('/bilibili/video/danmaku/:bvid/:pid?', require('./routes/bilibili/danmaku'));
router.get('/bilibili/link/news/:product', require('./routes/bilibili/linkNews'));
router.get('/bilibili/live/room/:roomID', require('./routes/bilibili/liveRoom'));
router.get('/bilibili/live/search/:key/:order', require('./routes/bilibili/liveSearch'));

View File

@@ -56,7 +56,7 @@ module.exports = {
return name;
},
getVideoNameFromId: async (ctx, aid, bvid) => {
const key = `bili-videoName-from-id-${bvid || aid}`;
const key = `bili-videoname-from-id-${bvid || aid}`;
let name = await ctx.cache.get(key);
if (!name) {
@@ -73,15 +73,15 @@ module.exports = {
}
return name;
},
getCidFromAid: async (ctx, aid, pid) => {
const key = `bili-Cid-from-Aid-${aid}-${pid}`;
getCidFromId: async (ctx, aid, pid, bvid) => {
const key = `bili-cid-from-id-${bvid || aid}-${pid}`;
let cid = await ctx.cache.get(key);
if (!cid) {
const cidResponse = await got({
method: 'get',
url: `https://api.bilibili.com/x/web-interface/view?aid=${aid}`,
url: `https://api.bilibili.com/x/web-interface/view?${bvid ? `bvid=${bvid}` : `aid=${aid}`}`,
headers: {
Referer: `https://www.bilibili.com/video/av${aid}`,
Referer: `https://www.bilibili.com/video/${bvid || `av${aid}`}`,
},
});
cid = cidResponse.data.data.pages[pid - 1].cid;

View File

@@ -4,16 +4,25 @@ const got = require('@/utils/got');
const zlib = require('zlib');
module.exports = async (ctx) => {
const aid = ctx.params.aid;
let bvid = ctx.params.bvid;
let aid;
if (!bvid.startsWith('BV')) {
aid = bvid;
bvid = null;
}
const pid = Number(ctx.params.pid || 1);
const limit = 50;
const cid = await cache.getCidFromAid(ctx, aid, pid);
const cid = await cache.getCidFromId(ctx, aid, pid, bvid);
const videoName = await cache.getVideoNameFromAid(ctx, aid);
const videoName = await cache.getVideoNameFromId(ctx, aid, bvid);
const link = `https://www.bilibili.com/video/${bvid || `av${aid}`}`;
const danmakuResponse = await got.get(`https://comment.bilibili.com/${cid}.xml`, {
decompress: false,
responseType: 'buffer',
headers: {
Referer: link,
},
});
let danmakuText = danmakuResponse.body;
@@ -34,14 +43,14 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `${videoName} 的 弹幕动态`,
link: `https://www.bilibili.com/video/av${aid}`,
link: link,
description: `${videoName} 的 弹幕动态`,
item: danmakuList.map((item) => ({
title: item.text,
description: item.text,
pubDate: new Date(item.p.split(',')[4] * 1000).toUTCString(),
guid: `${cid}-${item.p.split(',')[4]}-${item.p.split(',')[7]}`,
link: `https://www.bilibili.com/video/av${aid}`,
link: link,
})),
};
};

View File

@@ -26,7 +26,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `${name} 的 评论`,
link: `https://www.bilibili.com/video/av${aid}`,
link: link,
description: `${name} 的评论`,
item: data.map((item) => ({
title: `${item.member.uname} : ${item.content.message}`,