diff --git a/README.md b/README.md index 0f743b5a8..63e239b28 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 会员购新品上架 - 会员购作品 - 排行榜 + - 话题(频道/标签) - 微博 - 博主 - 关键词 diff --git a/docs/README.md b/docs/README.md index b8521aaac..f00b78227 100644 --- a/docs/README.md +++ b/docs/README.md @@ -232,7 +232,7 @@ fid,收藏夹 ID,可在收藏夹的 URL 中找到,默认收藏夹建议使用 参数: uid,用户 id,可在 UP 主主页中找到 -### UP 主粉丝 +### UP 主粉丝 举例: [https://rsshub.app/bilibili/user/followers/2267573](https://rsshub.app/bilibili/user/followers/2267573) @@ -240,7 +240,7 @@ fid,收藏夹 ID,可在收藏夹的 URL 中找到,默认收藏夹建议使用 参数: uid,用户 id,可在 UP 主主页中找到 -### UP 主关注用户 +### UP 主关注用户 举例: [https://rsshub.app/bilibili/user/followings/2267573](https://rsshub.app/bilibili/user/followings/2267573) @@ -352,7 +352,7 @@ fid,收藏夹 ID,可在收藏夹的 URL 中找到,默认收藏夹建议使用 | ---- | ------ | ------ | | 11 | 185 | 187 | -### 视频评论 +### 视频评论 举例: [https://rsshub.app/bilibili/video/reply/21669336](https://rsshub.app/bilibili/video/reply/21669336) @@ -442,6 +442,14 @@ rid: 排行榜分区 id,默认 0 | ---- | ---- | -------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | | 0 | 1 | 168 | 3 | 129 | 4 | 36 | 160 | 119 | 155 | 5 | 181 | +### 话题(频道/标签) + +举例: [https://rsshub.app/bilibili/topic/2233](https://rsshub.app/bilibili/topic/2233) + +路由: `/bilibili/topic/:topic` + +参数: topic 话题名(又称频道名或标签) 例如 2233 或 COSPLAY + ## bangumi ### 放送列表 diff --git a/router.js b/router.js index fecdb211a..5d3f3f1d3 100755 --- a/router.js +++ b/router.js @@ -105,6 +105,7 @@ router.get('/bilibili/mall/new', require('./routes/bilibili/mallNew')); router.get('/bilibili/mall/ip/:id', require('./routes/bilibili/mallIP')); router.get('/bilibili/ranking/:rid?/:day?', require('./routes/bilibili/ranking')); router.get('/bilibili/channel/:uid/:cid', require('./routes/bilibili/userChannel')); +router.get('/bilibili/topic/:topic', require('./routes/bilibili/topic')); // bangumi router.get('/bangumi/calendar/today', require('./routes/bangumi/calendar/today')); diff --git a/routes/bilibili/topic.js b/routes/bilibili/topic.js new file mode 100644 index 000000000..00eb1c570 --- /dev/null +++ b/routes/bilibili/topic.js @@ -0,0 +1,63 @@ +const axios = require('../../utils/axios'); +const JSONbig = require('json-bigint'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const topic = ctx.params.topic; + const urlEncodedTopic = encodeURIComponent(topic); + + const response = await axios({ + method: 'get', + url: `https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new?topic_name=${urlEncodedTopic}`, + headers: { + 'User-Agent': config.ua, + Referer: `https://www.bilibili.com/tag/${urlEncodedTopic}/feed`, + }, + transformResponse: [(data) => data], + }); + const data = JSONbig.parse(response.data).data.cards; + + ctx.state.data = { + title: `${topic} 的全部话题`, + link: `https://www.bilibili.com/tag/${topic}/feed`, + description: `https://www.bilibili.com/tag/${topic}/feed`, + item: data.map((item) => { + const parsed = JSONbig.parse(item.card); + const data = parsed.item || parsed; + + // img + let imgHTML = ''; + if (data.pictures) { + for (let i = 0; i < data.pictures.length; i++) { + imgHTML += ``; + } + } + if (data.pic) { + imgHTML += ``; + } + + // link + let link = ''; + if (data.dynamic_id) { + link = `https://t.bilibili.com/${data.dynamic_id}`; + } else if (data.aid) { + link = `https://www.bilibili.com/video/av${data.aid}`; + } else if (data.video_playurl) { + link = `https://vc.bilibili.com/video/${data.id}`; + } else if (data.id) { + link = `https://h.bilibili.com/${data.id}`; + } else if (data.rp_id && item.desc && item.desc.dynamic_id) { + link = `https://t.bilibili.com/${item.desc.dynamic_id}`; + } else if (data.sketch && data.sketch.sketch_id && item.desc && item.desc.dynamic_id) { + link = `https://t.bilibili.com/${item.desc.dynamic_id}`; + } + + return { + title: data.title || data.description || data.content || (data.vest && data.vest.content), + description: `${data.desc || data.description || data.content || data.summary || (data.vest && data.vest.content) + (data.sketch && data.sketch.title)}${imgHTML} `, + pubDate: new Date(item.desc.timestamp * 1000).toUTCString(), + link: link, + }; + }), + }; +};