Skip to content

Commit

Permalink
fix(bilibili)!: update article api (DIYgod#17586)
Browse files Browse the repository at this point in the history
* fix(bilibili): update article api

* fix(bilibili): use default ua

---------
  • Loading branch information
hyoban authored Nov 15, 2024
1 parent adbe01d commit 682d954
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions lib/routes/bilibili/article.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Route } from '@/types';
import got from '@/utils/got';
import cache from './cache';

import cacheGeneral from '@/utils/cache';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/user/article/:uid',
categories: ['social-media'],
Expand All @@ -21,8 +23,8 @@ export const route: Route = {
source: ['space.bilibili.com/:uid'],
},
],
name: 'UP 主专栏',
maintainers: ['lengthmin', 'Qixingchen'],
name: 'UP 主图文',
maintainers: ['lengthmin', 'Qixingchen', 'hyoban'],
handler,
};

Expand All @@ -31,24 +33,45 @@ async function handler(ctx) {
const name = await cache.getUsernameFromUID(uid);
const response = await got({
method: 'get',
url: `https://api.bilibili.com/x/space/article?mid=${uid}&pn=1&ps=10&sort=publish_time&jsonp=jsonp`,
url: `https://api.bilibili.com/x/polymer/web-dynamic/v1/opus/feed/space?host_mid=${uid}`,
headers: {
Referer: `https://space.bilibili.com/${uid}/`,
Referer: `https://space.bilibili.com/${uid}/article`,
},
});
const data = response.data.data;
const title = `${name} 的 bilibili 专栏`;
const title = `${name} 的 bilibili 图文`;
const link = `https://space.bilibili.com/${uid}/article`;
const description = `${name} 的 bilibili 专栏`;
const description = `${name} 的 bilibili 图文`;
const cookie = await cache.getCookie();

const item = await Promise.all(
data.articles.map(async (item) => {
const { url: art_url, description: eDescription } = await cache.getArticleDataFromCvid(item.id, uid);
const publishDate = parseDate(item.publish_time * 1000);
data.items.map(async (item) => {
const link = 'https:' + item.jump_url;
const data = await cacheGeneral.tryGet(
link,
async () =>
(
await got({
method: 'get',
url: link,
headers: {
Referer: `https://space.bilibili.com/${uid}/article`,
Cookie: cookie,
},
})
).data
);

const $ = load(data as string);
const description = $('.opus-module-content').html();
const pubDate = $('.opus-module-author__pub__text').text().replace('编辑于 ', '');

const single = {
title: item.title,
link: art_url,
description: eDescription,
pubDate: publishDate,
title: item.content,
link,
description: description || item.content,
// 2019年11月11日 08:50
pubDate: pubDate ? parseDate(pubDate, 'YYYY年MM月DD日 HH:mm') : undefined,
};
return single;
})
Expand Down

0 comments on commit 682d954

Please sign in to comment.