/
ranking.ts
121 lines (109 loc) · 4.95 KB
/
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Route } from '@/types';
import cache from '@/utils/cache';
import { getToken } from './token';
import getRanking from './api/get-ranking';
import { config } from '@/config';
import pixivUtils from './utils';
import { parseDate } from '@/utils/parse-date';
import ConfigNotFoundError from '@/errors/types/config-not-found';
const titles = {
day: 'pixiv 日排行',
week: 'pixiv 周排行',
month: 'pixiv 月排行',
day_male: 'pixiv 受男性欢迎排行',
day_female: 'pixiv 受女性欢迎排行',
week_original: 'pixiv 原创作品排行',
week_rookie: 'pixiv 新人排行',
day_r18: 'pixiv R-18 日排行',
day_r18_ai: 'pixiv R-18 AI生成作品排行',
day_male_r18: 'pixiv R-18 受男性欢迎排行',
day_female_r18: 'pixiv R-18 受女性欢迎排行',
week_r18: 'pixiv R-18 周排行',
week_r18g: 'pixiv R-18G 排行',
day_ai: 'AI 生成作品排行榜',
};
const links = {
day: 'https://www.pixiv.net/ranking.php?mode=daily',
week: 'https://www.pixiv.net/ranking.php?mode=weekly',
month: 'https://www.pixiv.net/ranking.php?mode=monthly',
day_male: 'https://www.pixiv.net/ranking.php?mode=male',
day_female: 'https://www.pixiv.net/ranking.php?mode=female',
day_ai: 'https://www.pixiv.net/ranking.php?mode=daily_ai',
week_original: 'https://www.pixiv.net/ranking.php?mode=original',
week_rookie: 'https://www.pixiv.net/ranking.php?mode=rookie',
day_r18: 'https://www.pixiv.net/ranking.php?mode=daily_r18',
day_r18_ai: 'https://www.pixiv.net/ranking.php?mode=daily_r18_ai',
day_male_r18: 'https://www.pixiv.net/ranking.php?mode=male_r18',
day_female_r18: 'https://www.pixiv.net/ranking.php?mode=female_r18',
week_r18: 'https://www.pixiv.net/ranking.php?mode=weekly_r18',
week_r18g: 'https://www.pixiv.net/ranking.php?mode=r18g',
};
const alias = {
daily: 'day',
weekly: 'week',
monthly: 'month',
male: 'day_male',
female: 'day_female',
daily_ai: 'day_ai',
original: 'week_original',
rookie: 'week_rookie',
daily_r18: 'day_r18',
daily_r18_ai: 'day_r18_ai',
male_r18: 'day_male_r18',
female_r18: 'day_female_r18',
weekly_r18: 'week_r18',
r18g: 'week_r18g',
};
export const route: Route = {
path: '/ranking/:mode/:date?',
categories: ['social-media', 'popular'],
example: '/pixiv/ranking/week',
parameters: { mode: 'rank type', date: 'format: `2018-4-25`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'Rankings',
maintainers: ['EYHN'],
handler,
description: `| daily rank | weekly rank | monthly rank | male rank | female rank | AI-generated work Rankings | original rank | rookie user rank |
| ---------- | ----------- | ------------ | --------- | ----------- | -------------------------- | -------------- | ---------------- |
| day | week | month | day\_male | day\_female | day\_ai | week\_original | week\_rookie |
| R-18 daily rank | R-18 AI-generated work | R-18 male rank | R-18 female rank | R-18 weekly rank | R-18G rank |
| --------------- | ---------------------- | -------------- | ---------------- | ---------------- | ---------- |
| day\_r18 | day\_r18\_ai | day\_male\_r18 | day\_female\_r18 | week\_r18 | week\_r18g |`,
};
async function handler(ctx) {
if (!config.pixiv || !config.pixiv.refreshToken) {
throw new ConfigNotFoundError('pixiv RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}
const mode = alias[ctx.req.param('mode')] ?? ctx.req.param('mode');
const date = ctx.req.param('date') ? new Date(ctx.req.param('date')) : new Date();
const token = await getToken(cache.tryGet);
if (!token) {
throw new ConfigNotFoundError('pixiv not login');
}
const response = await getRanking(mode, ctx.req.param('date') && date, token);
const illusts = response.data.illusts;
const dateStr = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 `;
return {
title: (ctx.req.param('date') ? dateStr : '') + titles[mode],
link: links[mode],
description: dateStr + titles[mode],
item: illusts.map((illust, index) => {
const images = pixivUtils.getImgs(illust);
return {
title: `#${index + 1} ${illust.title}`,
pubDate: parseDate(illust.create_date),
description: `${illust.caption}<br><p>画师:${illust.user.name} - 阅览数:${illust.total_view} - 收藏数:${illust.total_bookmarks}</p><br>${images.join('')}`,
link: `https://www.pixiv.net/artworks/${illust.id}`,
author: illust.user.name,
category: illust.tags.map((tag) => tag.name),
};
}),
};
}