mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 11:07:54 +08:00
feat: add b站用户动态up视频投稿 (#2088)
* feat: add b站用户关注的所有up主的最新投稿 * feat: 使用cookie获取动态数据 * fix some problem * change router
This commit is contained in:
@@ -379,6 +379,10 @@ $ docker run -d --name rsshub -p 1200:1200 rsshub:arm32v7
|
||||
|
||||
- `GITHUB_ACCESS_TOKEN`: GitHub Access Token
|
||||
|
||||
- `bilibili`: 控制台执行 document.cookie
|
||||
|
||||
- `BILIBILI_COOKIE_{uid}`: 对应 uid 的 b 站用户登录后的 Cookie 值
|
||||
|
||||
### 访问控制
|
||||
|
||||
可以通过修改 `middleware/access-control.js` 或者设置环境变量来配置黑名单和白名单.
|
||||
|
||||
@@ -134,6 +134,14 @@
|
||||
|
||||
<Route name="视频搜索" author="Symty" example="/bilibili/vsearch/藤原千花" path="/bilibili/vsearch/:kw/:order?" :paramsDesc="['检索关键字', '排序方式, 综合:totalrank 最多点击:click 最新发布:pubdate(缺省) 最多弹幕:dm 最多收藏:stow']"/>
|
||||
|
||||
<Route name="用户关注视频动态" author="LogicJake" example="/bilibili/followings/video/2267573" path="/bilibili/followings/video/:uid" :paramsDesc="['用户 id']">
|
||||
::: warning 注意
|
||||
|
||||
用户动态需要 b 站登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
|
||||
|
||||
:::
|
||||
</Route>
|
||||
|
||||
### 直播开播 <Author uid="Qixingchen"/>
|
||||
|
||||
见 [#哔哩哔哩直播](/live.html#哔哩哔哩直播)
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
const bilibili_cookies = {};
|
||||
const envs = process.env;
|
||||
for (const name in envs) {
|
||||
if (name.startsWith('BILIBILI_COOKIE_')) {
|
||||
const uid = name.slice(16);
|
||||
bilibili_cookies[uid] = envs[name];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
connect: {
|
||||
port: process.env.PORT || 1200, // 监听端口
|
||||
@@ -52,6 +61,10 @@ module.exports = {
|
||||
name: process.env.HTTP_BASIC_AUTH_NAME || 'usernam3',
|
||||
pass: process.env.HTTP_BASIC_AUTH_PASS || 'passw0rd',
|
||||
},
|
||||
bilibili: {
|
||||
cookies: bilibili_cookies,
|
||||
},
|
||||
|
||||
puppeteerWSEndpoint: process.env.PUPPETEER_WS_ENDPOINT,
|
||||
loggerLevel: process.env.LOGGER_LEVEL || 'info',
|
||||
proxy: {
|
||||
|
||||
@@ -120,6 +120,7 @@ router.get('/bilibili/user/channel/:uid/:cid', require('./routes/bilibili/userCh
|
||||
router.get('/bilibili/topic/:topic', require('./routes/bilibili/topic'));
|
||||
router.get('/bilibili/audio/:id', require('./routes/bilibili/audio'));
|
||||
router.get('/bilibili/vsearch/:kw/:order?', require('./routes/bilibili/vsearch'));
|
||||
router.get('/bilibili/followings/video/:uid', require('./routes/bilibili/followings_video'));
|
||||
|
||||
// bangumi
|
||||
router.get('/bangumi/calendar/today', require('./routes/bangumi/calendar/today'));
|
||||
|
||||
43
lib/routes/bilibili/followings_video.js
Normal file
43
lib/routes/bilibili/followings_video.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cache = require('./cache');
|
||||
const config = require('../../config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uid = String(ctx.params.uid);
|
||||
const name = await cache.getUsernameFromUID(ctx, uid);
|
||||
|
||||
const cookie = config.bilibili.cookies[uid];
|
||||
if (cookie === undefined) {
|
||||
throw Error('缺少对应uid的b站用户登录后的Cookie值');
|
||||
}
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${uid}&type=8`,
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const cards = response.data.data.cards;
|
||||
|
||||
const out = await Promise.all(
|
||||
cards.map(async (card) => {
|
||||
const card_data = JSON.parse(card.card);
|
||||
|
||||
const item = {
|
||||
title: card_data.title,
|
||||
description: `${card_data.desc}<br><img referrerpolicy="no-referrer" src="${card_data.pic}">`,
|
||||
pubDate: new Date(card_data.pubdate * 1000).toUTCString(),
|
||||
link: `https://www.bilibili.com/video/av${card_data.aid}`,
|
||||
};
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name} 关注视频动态`,
|
||||
link: `https://t.bilibili.com/?tab=8`,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user