/
podcasts.ts
94 lines (82 loc) 路 2.7 KB
/
podcasts.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/podcasts',
categories: ['new-media'],
example: '/supchina/podcasts',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['supchina.com/podcasts', 'supchina.com/'],
},
],
name: 'Podcasts',
maintainers: ['nczitzk'],
handler,
url: 'supchina.com/podcasts',
};
async function handler(ctx) {
const rootUrl = 'https://supchina.com';
const currentUrl = `${rootUrl}/feed/podcast`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
let items = $('item')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50)
.toArray()
.map((item) => {
item = $(item);
return {
link: item.find('guid').text(),
author: item.find(String.raw`itunes\:author`).text(),
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const episodeResponse = await got({
method: 'get',
url: `https://rss.art19.com/episodes/${detailResponse.data.match(/data-episode-id="(.*?)"/)[1]}`,
headers: {
accept: 'application/json',
},
});
const data = episodeResponse.data;
item.title = data.content.episode_title;
item.itunes_item_image = data.content.cover_image;
item.itunes_duration = data.content.duration;
item.enclosure_url = data.content.media.mp3.url;
item.enclosure_type = data.content.media.mp3.content_type;
item.description = data.content.episode_description;
item.pubDate = parseDate(data.performed_at);
return item;
})
)
);
return {
title: 'SupChina - Podcasts',
link: `${rootUrl}/podcasts`,
itunes_author: $(String.raw`channel itunes\:author`)
.first()
.text(),
image: $(String.raw`itunes\:image`).attr('href'),
item: items,
};
}