feat: Bilibii 关注专栏 (#2260)
* 增加Bilibili专栏 * Docs: Bilibili 关注专栏 * 使用 axios * 使用 axios
This commit is contained in:
@@ -182,6 +182,16 @@ pageClass: routes
|
||||
:::
|
||||
</Route>
|
||||
|
||||
### 用户关注专栏
|
||||
|
||||
<route author="woshiluo" example="/bilibili/followings/article/99800931" path="/bilibili/followings/article/:uid" :paramsdesc="['用户 id']">
|
||||
::: warning 注意
|
||||
|
||||
用户动态需要 b 站登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
|
||||
|
||||
:::
|
||||
</Route>
|
||||
|
||||
### 直播开播
|
||||
|
||||
见 [#哔哩哔哩直播](/live.html#哔哩哔哩直播)
|
||||
|
||||
@@ -41,6 +41,7 @@ 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'));
|
||||
router.get('/bilibili/followings/article/:uid', require('./routes/bilibili/followings_article'));
|
||||
|
||||
// bangumi
|
||||
router.get('/bangumi/calendar/today', require('./routes/bangumi/calendar/today'));
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const axios = require('@/utils/axios');
|
||||
const cache = require('./cache');
|
||||
const config = require('@/config');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
async function get_bilibili_article_contain(url) {
|
||||
const result = await axios.get(url);
|
||||
|
||||
const $ = cheerio.load(result.data);
|
||||
$('img').each(function(i, e) {
|
||||
$(e).attr('src', $(e).attr('data-src'));
|
||||
});
|
||||
|
||||
return $('.article-holder').html();
|
||||
}
|
||||
|
||||
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=64`,
|
||||
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 link = `http://www.bilibili.com/read/cv${card_data.id}`;
|
||||
|
||||
const item = {
|
||||
title: card_data.title,
|
||||
description: await ctx.cache.tryGet(link, async () => await get_bilibili_article_contain(link)),
|
||||
pubDate: new Date(card_data.publish_time * 1000).toUTCString(),
|
||||
link: link,
|
||||
author: card.desc.user_profile.info.uname,
|
||||
};
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name} 关注专栏动态`,
|
||||
link: `https://t.bilibili.com/?tab=64`,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user