mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): 修复 Bilibili 频道链接,并支持 ctype=1 (#7913)
This commit is contained in:
@@ -46,7 +46,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
|
||||
|
||||
### UP 主频道
|
||||
|
||||
<Route author="HenryQW" example="/bilibili/user/channel/142821407/49017" path="/bilibili/user/channel/:uid/:cid/:disableEmbed?" :paramsDesc="['用户 id, 可在 UP 主主页中找到', '频道 id, 可在频道的 URL 中找到', '默认为开启内嵌视频, 任意值为关闭']" anticrawler="1" radar="1" rssbud="1"/>
|
||||
<Route author="HenryQW" example="/bilibili/user/channel/142821407/49017" path="/bilibili/user/channel/:uid/:cid/:disableEmbed?" :paramsDesc="['用户 id, 可在 UP 主主页中找到', '频道 id, 可在频道的 URL 中找到', '默认为开启内嵌视频, 任意值为关闭']" anticrawler="1"/>
|
||||
|
||||
### UP 主默认收藏夹
|
||||
|
||||
|
||||
@@ -3,17 +3,35 @@ const cache = require('./cache');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cid = ctx.params.cid;
|
||||
const uid = ctx.params.uid;
|
||||
const uid = Number.parseInt(ctx.params.uid);
|
||||
const cid = Number.parseInt(ctx.params.cid);
|
||||
const disableEmbed = ctx.params.disableEmbed;
|
||||
|
||||
// 获取频道的 ctype
|
||||
const channelsLink = `https://api.bilibili.com/x/space/channel/list?mid=${uid}`;
|
||||
const channelsResponse = await ctx.cache.tryGet(channelsLink, async () => {
|
||||
const response = await got.get(channelsLink, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
});
|
||||
const channelInfo = channelsResponse.data.list.find((channel) => channel.cid === cid);
|
||||
if (!channelInfo) {
|
||||
throw new Error('无法获取该频道信息,请报告这个问题');
|
||||
}
|
||||
const ctype = channelInfo.is_live_playback ? 1 : 0;
|
||||
|
||||
const link = `https://space.bilibili.com/${uid}/detail?cid=${cid}&ctype=${ctype}`;
|
||||
const userName = await cache.getUsernameFromUID(ctx, uid);
|
||||
const host = `https://api.bilibili.com/x/space/channel/video?mid=${uid}&cid=${cid}&pn=1&ps=10&order=0`;
|
||||
const host = `https://api.bilibili.com/x/space/channel/video?mid=${uid}&cid=${cid}&pn=1&ps=10&order=0&ctype=${ctype}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: host,
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -31,15 +49,25 @@ module.exports = async (ctx) => {
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${userName} 的 bilibili 频道 ${channelName}`,
|
||||
link: `https://space.bilibili.com/${uid}/#/channel/detail?cid=${cid}`,
|
||||
link,
|
||||
description: data.name,
|
||||
|
||||
item: data.archives.map((item) => ({
|
||||
title: item.title,
|
||||
description: `${item.desc}${!disableEmbed ? `<br><br>${utils.iframe(item.aid)}` : ''}<br><img src="${item.pic}">`,
|
||||
pubDate: new Date(item.pubdate * 1000).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
})),
|
||||
item: data.archives.map((item) => {
|
||||
const descList = [];
|
||||
if (item.desc) {
|
||||
descList.push(item.desc);
|
||||
}
|
||||
if (!disableEmbed) {
|
||||
descList.push(`${item.desc ? '<br>' : ''}${utils.iframe(item.aid)}`);
|
||||
}
|
||||
descList.push(`<img src="${item.pic}">`);
|
||||
return {
|
||||
title: item.title,
|
||||
description: descList.join('<br>'),
|
||||
pubDate: new Date(item.pubdate * 1000),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
|
||||
author: userName,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user