From 07a9008be3dc40148ee9adc5117edbdc5190df05 Mon Sep 17 00:00:00 2001 From: qixingchen Date: Sun, 6 May 2018 16:49:01 +0800 Subject: [PATCH] add bilibili video reply --- README.md | 1 + docs/README.md | 7 ++++++ router.js | 1 + routes/bilibili/videoReply.js | 47 +++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 routes/bilibili/videoReply.js diff --git a/README.md b/README.md index bf89cb933..156486316 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - UP 主粉丝 - UP 主关注用户 - 分区视频 + - 视频评论 - 微博 - 博主 - 网易云音乐 diff --git a/docs/README.md b/docs/README.md index 9eedf1d23..b85f581a5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -152,6 +152,13 @@ s | ---- | ---- | ---- | ----- | ---- | | 182 | 183 | 85 | 184 | 86 | +### 视频评论 + +举例: https://rss.now.sh/bilibili/video/reply/7 + +路由: `/bilibili/video/reply/:avid` + +参数: avid,视频 AV 号(仅数字) ## 微博 diff --git a/router.js b/router.js index 4412ca68b..7db416ce4 100644 --- a/router.js +++ b/router.js @@ -19,6 +19,7 @@ router.get('/bilibili/user/followers/:uid', require('./routes/bilibili/followers router.get('/bilibili/user/followings/:uid', require('./routes/bilibili/followings')); router.get('/bilibili/partion/:tid', require('./routes/bilibili/partion')); router.get('/bilibili/bangumi/:seasonid', require('./routes/bilibili/bangumi')); +router.get('/bilibili/video/reply/:avid', require('./routes/bilibili/videoReply')); // // 微博 router.get('/weibo/user/:uid', require('./routes/weibo/user')); diff --git a/routes/bilibili/videoReply.js b/routes/bilibili/videoReply.js new file mode 100644 index 000000000..7ef076a6a --- /dev/null +++ b/routes/bilibili/videoReply.js @@ -0,0 +1,47 @@ +const axios = require('axios'); +const art = require('art-template'); +const path = require('path'); +const config = require('../../config'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const avid = ctx.params.avid; + + const nameResponse = await axios({ + method: 'get', + url: `https://www.bilibili.com/video/av${avid}`, + headers: { + 'User-Agent': config.ua, + }, + responseType: 'arraybuffer' + }); + const responseHtml = iconv.decode(nameResponse.data, 'UTF-8'); + const $ = cheerio.load(responseHtml); + let name = $("title").text(); + name = name.substr(0, name.indexOf("_哔哩哔哩")); + + const response = await axios({ + method: 'get', + url: `https://api.bilibili.com/x/v2/reply?type=1&oid=${avid}&sort=0`, + headers: { + 'User-Agent': config.ua, + 'Referer': `https://www.bilibili.com/video/av${avid}`, + } + }); + + const data = response.data.data.replies; + + ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), { + title: `${name} 的 评论`, + link: `https://www.bilibili.com/video/av${avid}`, + description: `${name} 的 评论`, + lastBuildDate: new Date().toUTCString(), + item: data.map((item) => ({ + title: `${item.member.uname} : ${item.content.message}`, + description: `#${item.floor}
${item.member.uname} : ${item.content.message}`, + pubDate: new Date(item.ctime * 1000).toUTCString(), + link: `https://www.bilibili.com/video/av${avid}/#reply${item.rpid}` + })), + }); +}; \ No newline at end of file