Skip to content

Commit

Permalink
fix(bilibili): vsearch, close DIYgod#15105
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 7, 2024
1 parent b26a704 commit d7c23dc
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions lib/routes/bilibili/vsearch.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import { config } from '@/config';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import utils from './utils';
import { CookieJar } from 'tough-cookie';
const cookieJar = new CookieJar();
import { queryToBoolean } from '@/utils/readable-social';
import cacheIn from './cache';

export const route: Route = {
path: '/vsearch/:kw/:order?/:disableEmbed?/:tid?',
categories: ['social-media'],
example: '/bilibili/vsearch/RSSHub',
parameters: { kw: '检索关键字', order: '排序方式, 综合:totalrank 最多点击:click 最新发布:pubdate(缺省) 最多弹幕:dm 最多收藏:stow', disableEmbed: '默认为开启内嵌视频, 任意值为关闭', tid: '分区 id' },
features: {
requireConfig: false,
requireConfig: [
{
name: 'BILIBILI_COOKIE_*',
optional: true,
description: `如果没有此配置,那么必须开启 puppeteer 支持;BILIBILI_COOKIE_{uid}: 用于用户关注动态系列路由,对应 uid 的 b 站用户登录后的 Cookie 值,\`{uid}\` 替换为 uid,如 \`BILIBILI_COOKIE_2267573\`,获取方式:
1. 打开 [https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=0&type=8](https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=0&type=8)
2. 打开控制台,切换到 Network 面板,刷新
3. 点击 dynamic_new 请求,找到 Cookie
4. 视频和专栏,UP 主粉丝及关注只要求 \`SESSDATA\` 字段,动态需复制整段 Cookie`,
},
],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '视频搜索',
maintainers: ['Symty'],
maintainers: ['Symty', 'DIYgod'],
handler,
description: `分区 id 的取值请参考下表:
Expand All @@ -37,32 +44,22 @@ async function handler(ctx) {
const disableEmbed = queryToBoolean(ctx.req.param('disableEmbed'));
const kw_url = encodeURIComponent(kw);
const tids = ctx.req.param('tid') ?? 0;
const cookie = await cacheIn.getCookie();

const data = await cache.tryGet(
`bilibili:vsearch:${tids}:${kw}:${order}`,
async () => {
await got('https://passport.bilibili.com/login', {
cookieJar,
});

const response = await got('https://api.bilibili.com/x/web-interface/search/type', {
headers: {
Referer: `https://search.bilibili.com/all?keyword=${kw_url}`,
},
cookieJar,
searchParams: {
search_type: 'video',
highlight: 1,
keyword: kw,
order,
tids,
},
});
return response.data.data.result;
const response = await got('https://api.bilibili.com/x/web-interface/search/type', {
headers: {
Referer: `https://search.bilibili.com/all?keyword=${kw_url}`,
Cookie: cookie,
},
searchParams: {
search_type: 'video',
highlight: 1,
keyword: kw,
order,
tids,
},
config.cache.routeExpire,
false
);
});
const data = response.data.data.result;

return {
title: `${kw} - bilibili`,
Expand Down

0 comments on commit d7c23dc

Please sign in to comment.