/
partion-ranking.ts
76 lines (67 loc) · 2.76 KB
/
partion-ranking.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Route } from '@/types';
import got from '@/utils/got';
import utils from './utils';
const got_ins = got.extend({
headers: {
Referer: 'https://www.bilibili.com/',
},
});
function formatDate(now) {
const year = now.getFullYear();
const month = now.getMonth() + 1;
const date = now.getDate();
const dateTime = year + '' + (month >= 10 ? month : '0' + month) + '' + (date >= 10 ? date : '0' + date);
return dateTime;
}
export const route: Route = {
path: '/partion/ranking/:tid/:days?/:disableEmbed?',
categories: ['social-media'],
example: '/bilibili/partion/ranking/171/3',
parameters: { tid: '分区 id, 见上方表格', days: '缺省为 7, 指最近多少天内的热度排序', disableEmbed: '默认为开启内嵌视频, 任意值为关闭' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '分区视频排行榜',
maintainers: ['lengthmin'],
handler,
};
async function handler(ctx) {
const tid = ctx.req.param('tid');
const days = ctx.req.param('days') ?? 7;
const disableEmbed = ctx.req.param('disableEmbed');
const responseApi = `https://api.bilibili.com/x/web-interface/newlist?ps=15&rid=${tid}&_=${Date.now()}`;
const response = await got_ins.get(responseApi);
const items = [];
let name = '未知';
let list = {};
list = response.data.data.archives;
if (list && list[0] && list[0].tname) {
name = list[0].tname;
}
const time_from = formatDate(new Date(Date.now() - 1000 * 60 * 60 * 24 * days)); // n天前的日期
const time_to = formatDate(new Date()); // 今天的日期
const HotRankResponseApi = `https://s.search.bilibili.com/cate/search?main_ver=v3&search_type=video&view_type=hot_rank&cate_id=${tid}&time_from=${time_from}&time_to=${time_to}&_=${Date.now()}`;
const HotRankResponse = await got_ins.get(HotRankResponseApi);
const hotlist = HotRankResponse.data.result;
for (let item of hotlist) {
item = {
title: item.title,
description: `${item.description}${disableEmbed ? '' : `<br><br>${utils.iframe(item.id)}`}<br><img src="https:${item.pic}"><br/>Tags:${item.tag}`,
pubDate: new Date(item.pubdate).toUTCString(),
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
author: item.author,
};
items.push(item);
}
return {
title: `bilibili ${name} 最热视频`,
link: 'https://www.bilibili.com',
description: `bilibili ${name}分区 最热视频`,
item: items,
};
}