feat(route): add bilibili watchlater (#13128)
* feat(route): add bilibili watchlater * docs(route): add docs for /bilibili/watchlater * Update lib/v2/bilibili/watchlater.js ---------
This commit is contained in:
parent
9993045270
commit
cbf016b76a
|
|
@ -40,5 +40,6 @@ module.exports = {
|
|||
'/video/page/:bvid/:disableEmbed?': ['sxzz'],
|
||||
'/video/reply/:bvid': ['Qixingchen'],
|
||||
'/vsearch/:kw/:order?/:disableEmbed?/:tid?': ['Symty'],
|
||||
'/watchlater/:uid/:disableEmbed?': ['JimenezLi'],
|
||||
'/weekly/:disableEmbed?': ['ttttmr'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,5 +40,6 @@ module.exports = (router) => {
|
|||
router.get('/video/page/:bvid/:disableEmbed?', require('./page'));
|
||||
router.get('/video/reply/:bvid', require('./reply'));
|
||||
router.get('/vsearch/:kw/:order?/:disableEmbed?/:tid?', require('./vsearch'));
|
||||
router.get('/watchlater/:uid/:disableEmbed?', require('./watchlater'));
|
||||
router.get('/weekly/:disableEmbed?', require('./weekly_recommend'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
const got = require('@/utils/got');
|
||||
const cache = require('./cache');
|
||||
const config = require('@/config').value;
|
||||
const utils = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uid = ctx.params.uid;
|
||||
const disableEmbed = ctx.params.disableEmbed;
|
||||
const name = await cache.getUsernameFromUID(ctx, uid);
|
||||
|
||||
const cookie = config.bilibili.cookies[uid];
|
||||
if (cookie === undefined) {
|
||||
throw Error('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值');
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.bilibili.com/x/v2/history/toview`,
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
if (response.data.code) {
|
||||
const message = response.data.code === -6 ? '对应 uid 的 Bilibili 用户的 Cookie 已过期' : response.data.message;
|
||||
throw Error(`Error code ${response.data.code}: ${message}`);
|
||||
}
|
||||
const list = response.data.data.list;
|
||||
|
||||
const out = list.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}<br><br><a href="https://www.bilibili.com/list/watchlater?bvid=${item.bvid}">在稍后再看列表中查看</a>${!disableEmbed ? `<br><br>${utils.iframe(item.aid)}` : ''}<br><img src="${item.pic}">`,
|
||||
pubDate: parseDate(item.add_at * 1000),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: item.owner.name,
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name} 稍后再看`,
|
||||
link: 'https://www.bilibili.com/watchlater#/list',
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
|
@ -298,6 +298,18 @@ UP 主关注用户现在需要 b 站登录后的 Cookie 值,所以只能自建
|
|||
|
||||
</Route>
|
||||
|
||||
### 用户稍后再看 {#bilibili-yong-hu-shao-hou-zai-kan}
|
||||
|
||||
<Route author="JimenezLi" example="/bilibili/watchlater/2267573" path="/bilibili/watchlater/:uid/:disableEmbed?" paramsDesc={['用户 id', '默认为开启内嵌视频, 任意值为关闭']} selfhost="1">
|
||||
|
||||
:::caution
|
||||
|
||||
用户稍后再看需要 b 站登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### 直播开播 {#bilibili-zhi-bo-kai-bo}
|
||||
|
||||
见 [#哔哩哔哩直播](/routes/live#bi-li-bi-li-zhi-bo)
|
||||
|
|
|
|||
Loading…
Reference in New Issue