/
recommend.ts
80 lines (70 loc) · 1.96 KB
/
recommend.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { rootUrl, getCookie } from './utils';
export const route: Route = {
path: '/recommend',
categories: ['game'],
example: '/yxdown/recommend',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['yxdown.com/'],
},
],
name: '精彩推荐',
maintainers: ['nczitzk'],
handler,
url: 'yxdown.com/',
};
async function handler() {
const currentUrl = `${rootUrl}/news/`;
const cookie = await getCookie();
const response = await got(currentUrl, {
headers: {
cookie,
},
});
const $ = load(response.data);
const list = $('ul li a b')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.parent().attr('href'),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got(item.link, {
headers: {
cookie,
},
});
const content = load(detailResponse.data);
content('h1, .intro').remove();
item.description = content('.news').html();
item.pubDate = timezone(parseDate(content('meta[property="og:release_date"]').attr('content')), +8);
return item;
})
)
);
return {
title: '精彩推荐 - 游讯网',
link: currentUrl,
item: items,
};
}