diff --git a/README.md b/README.md index 2e8c822ad..eb11c46f2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - UP 主投币视频 - UP 主粉丝 - UP 主关注用户 - - 分区视频 + - 分区视频(投稿时间排序) + - 分区视频(视频热度排序) - 视频评论 - link 公告 - 直播开播 diff --git a/docs/README.md b/docs/README.md index 1c8d34818..51f7ddee4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -464,7 +464,7 @@ fid,收藏夹 ID,可在收藏夹的 URL 中找到,默认收藏夹建议使用 参数: uid,用户 id,可在 UP 主主页中找到 -### 分区视频 +### 分区视频(投稿时间排序) 举例: [https://rsshub.app/bilibili/partion/33](https://rsshub.app/bilibili/partion/33) @@ -472,6 +472,18 @@ fid,收藏夹 ID,可在收藏夹的 URL 中找到,默认收藏夹建议使用 参数: tid,分区 id +### 分区视频(视频热度排序) + +举例: [https://rsshub.app/bilibili/partion/ranking/171/3](https://rsshub.app/bilibili/partion/ranking/171/3) + +路由: `/bilibili/partion/ranking/:tid/:days?` + +参数: + +tid,分区 id + +days, 可选, 缺省为 7, 指最近多少天内的热度排序 + 动画 | MAD·AMV | MMD·3D | 短片·手书·配音 | 综合 | diff --git a/router.js b/router.js index 16b975254..50bae064e 100755 --- a/router.js +++ b/router.js @@ -94,6 +94,7 @@ router.get('/bilibili/user/dynamic/:uid', require('./routes/bilibili/dynamic')); 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/partion/ranking/:tid/:days?', require('./routes/bilibili/partion-ranking')); router.get('/bilibili/bangumi/:seasonid', require('./routes/bilibili/bangumi')); router.get('/bilibili/video/reply/:aid', require('./routes/bilibili/reply')); router.get('/bilibili/link/news/:product', require('./routes/bilibili/linkNews')); diff --git a/routes/bilibili/partion-ranking.js b/routes/bilibili/partion-ranking.js new file mode 100644 index 000000000..37f5edf80 --- /dev/null +++ b/routes/bilibili/partion-ranking.js @@ -0,0 +1,56 @@ +const axios = require('../../utils/axios'); +const axios_ins = axios.create({ + headers: { + Referer: 'https://www.bilibili.com/', + }, +}); + +function formatDate(now) { + const year = now.getFullYear(); + const month = now.getMonth() + 1; + const date = now.getDate(); + const dateTime = year + '' + (month >= 10 ? month : '0' + month) + '' + (date >= 10 ? date : '0' + date); + return dateTime; +} + +module.exports = async (ctx) => { + const tid = ctx.params.tid; + const days = ctx.params.days ? ctx.params.days : 7; + + const responseApi = `https://api.bilibili.com/x/web-interface/newlist?ps=15&rid=${tid}&_=${+new Date()}`; + + const response = await axios_ins.get(responseApi); + const items = []; + let name = '未知'; + let list = {}; + + list = response.data.data.archives; + if (list && list[0] && list[0].tname) { + name = list[0].tname; + } + + const time_from = formatDate(new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * days)); // n天前的日期 + const time_to = formatDate(new Date()); // 今天的日期 + const HotRankResponseApi = `https://s.search.bilibili.com/cate/search?main_ver=v3&search_type=video&view_type=hot_rank&cate_id=${tid}&time_from=${time_from}&time_to=${time_to}&_=${+new Date()}`; + const HotRankResponse = await axios_ins.get(HotRankResponseApi); + const hotlist = HotRankResponse.data.result; + + for (let i = 0; i < hotlist.length; i++) { + let item = hotlist[i]; + + item = { + title: `${item.title} - ${item.author}`, + description: `${item.description}
Tags:${item.tag}`, + pubDate: new Date(item.pubdate).toUTCString(), + link: item.arcurl, + }; + items.push(item); + } + + ctx.state.data = { + title: `bilibili ${name} 最热视频`, + link: 'https://www.bilibili.com', + description: `bilibili ${name}分区 最热视频`, + item: items, + }; +};