/
user.ts
69 lines (62 loc) · 2.1 KB
/
user.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
import { Route } from '@/types';
import got from '@/utils/got';
import { JSDOM } from 'jsdom';
import cache from './cache';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/kg/:userId',
categories: ['social-media'],
example: '/qq/kg/639a9a86272c308e33',
parameters: { userId: '用户 ID, 可在对应页面的 URL 中找到' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: true,
supportScihub: false,
},
name: '用户作品列表',
maintainers: ['zhangxiang012'],
handler,
};
async function handler(ctx) {
const userId = ctx.req.param('userId');
const url = `https://node.kg.qq.com/personal?uid=${userId}`;
const response = await got(url);
const { window } = new JSDOM(response.data, {
runScripts: 'dangerously',
});
const data = window.__DATA__;
const author = data.data.nickname;
const authorimg = data.data.head_img_url;
const ugcList = data.data.ugclist;
const items = await Promise.all(
ugcList.map(async (item) => {
const link = `https://node.kg.qq.com/play?s=${item.shareid}`;
const item_info = await cache.getPlayInfo(ctx, item.shareid, item.ksong_mid);
const single = {
title: item.title || '',
description: item_info.description,
link,
guid: `ksong:${item.ksong_mid}`,
author,
pubDate: parseDate(item_info.ctime * 1000) || parseDate(item.ctime, 'X'),
itunes_item_image: item_info.itunes_item_image || item.avatar,
enclosure_url: item_info.enclosure_url,
enclosure_type: 'audio/x-m4a',
};
return single;
})
);
return {
title: `${author} - 全民K歌`,
link: url,
description: data.share.content,
allowEmpty: true,
item: items,
image: authorimg,
itunes_author: author,
itunes_category: '全民K歌',
};
}