mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 23:59:56 +08:00
feat: bilibili bvid /video/danamku
This commit is contained in:
@@ -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 公告
|
### link 公告
|
||||||
|
|
||||||
|
|||||||
@@ -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/bangumi/media/:mediaid', require('./routes/bilibili/bangumi'));
|
||||||
router.get('/bilibili/video/page/:bvid/:disableEmbed?', require('./routes/bilibili/page'));
|
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/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/link/news/:product', require('./routes/bilibili/linkNews'));
|
||||||
router.get('/bilibili/live/room/:roomID', require('./routes/bilibili/liveRoom'));
|
router.get('/bilibili/live/room/:roomID', require('./routes/bilibili/liveRoom'));
|
||||||
router.get('/bilibili/live/search/:key/:order', require('./routes/bilibili/liveSearch'));
|
router.get('/bilibili/live/search/:key/:order', require('./routes/bilibili/liveSearch'));
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module.exports = {
|
|||||||
return name;
|
return name;
|
||||||
},
|
},
|
||||||
getVideoNameFromId: async (ctx, aid, bvid) => {
|
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);
|
let name = await ctx.cache.get(key);
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@@ -73,15 +73,15 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
},
|
},
|
||||||
getCidFromAid: async (ctx, aid, pid) => {
|
getCidFromId: async (ctx, aid, pid, bvid) => {
|
||||||
const key = `bili-Cid-from-Aid-${aid}-${pid}`;
|
const key = `bili-cid-from-id-${bvid || aid}-${pid}`;
|
||||||
let cid = await ctx.cache.get(key);
|
let cid = await ctx.cache.get(key);
|
||||||
if (!cid) {
|
if (!cid) {
|
||||||
const cidResponse = await got({
|
const cidResponse = await got({
|
||||||
method: 'get',
|
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: {
|
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;
|
cid = cidResponse.data.data.pages[pid - 1].cid;
|
||||||
|
|||||||
@@ -4,16 +4,25 @@ const got = require('@/utils/got');
|
|||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
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 pid = Number(ctx.params.pid || 1);
|
||||||
const limit = 50;
|
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`, {
|
const danmakuResponse = await got.get(`https://comment.bilibili.com/${cid}.xml`, {
|
||||||
decompress: false,
|
decompress: false,
|
||||||
responseType: 'buffer',
|
responseType: 'buffer',
|
||||||
|
headers: {
|
||||||
|
Referer: link,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let danmakuText = danmakuResponse.body;
|
let danmakuText = danmakuResponse.body;
|
||||||
@@ -34,14 +43,14 @@ module.exports = async (ctx) => {
|
|||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: `${videoName} 的 弹幕动态`,
|
title: `${videoName} 的 弹幕动态`,
|
||||||
link: `https://www.bilibili.com/video/av${aid}`,
|
link: link,
|
||||||
description: `${videoName} 的 弹幕动态`,
|
description: `${videoName} 的 弹幕动态`,
|
||||||
item: danmakuList.map((item) => ({
|
item: danmakuList.map((item) => ({
|
||||||
title: item.text,
|
title: item.text,
|
||||||
description: item.text,
|
description: item.text,
|
||||||
pubDate: new Date(item.p.split(',')[4] * 1000).toUTCString(),
|
pubDate: new Date(item.p.split(',')[4] * 1000).toUTCString(),
|
||||||
guid: `${cid}-${item.p.split(',')[4]}-${item.p.split(',')[7]}`,
|
guid: `${cid}-${item.p.split(',')[4]}-${item.p.split(',')[7]}`,
|
||||||
link: `https://www.bilibili.com/video/av${aid}`,
|
link: link,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ module.exports = async (ctx) => {
|
|||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: `${name} 的 评论`,
|
title: `${name} 的 评论`,
|
||||||
link: `https://www.bilibili.com/video/av${aid}`,
|
link: link,
|
||||||
description: `${name} 的评论`,
|
description: `${name} 的评论`,
|
||||||
item: data.map((item) => ({
|
item: data.map((item) => ({
|
||||||
title: `${item.member.uname} : ${item.content.message}`,
|
title: `${item.member.uname} : ${item.content.message}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user