feat(route): also support podcast id in xiaoyuzhou
This commit is contained in:
@@ -8,7 +8,7 @@ export const route: Route = {
|
||||
categories: ['multimedia', 'popular'],
|
||||
view: ViewType.Audios,
|
||||
example: '/xiaoyuzhou/podcast/6021f949a789fca4eff4492c',
|
||||
parameters: { id: '播客id,可以在小宇宙播客的 URL 中找到' },
|
||||
parameters: { id: '播客 id 或单集 id,可以在小宇宙播客的 URL 中找到' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -19,25 +19,53 @@ export const route: Route = {
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['xiaoyuzhoufm.com/podcast/:id'],
|
||||
source: ['xiaoyuzhoufm.com/podcast/:id', 'xiaoyuzhoufm.com/episode/:id'],
|
||||
},
|
||||
],
|
||||
name: '播客',
|
||||
maintainers: ['hondajojo', 'jtsang4'],
|
||||
maintainers: ['hondajojo', 'jtsang4', 'pseudoyu'],
|
||||
handler,
|
||||
url: 'xiaoyuzhoufm.com/',
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const link = `https://www.xiaoyuzhoufm.com/podcast/${ctx.req.param('id')}`;
|
||||
const response = await got({
|
||||
const id = ctx.req.param('id');
|
||||
let link = `https://www.xiaoyuzhoufm.com/podcast/${id}`;
|
||||
let response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const $ = load(response.data);
|
||||
let $ = load(response.data);
|
||||
let page_data = JSON.parse($('#__NEXT_DATA__')[0].children[0].data);
|
||||
|
||||
const page_data = JSON.parse($('#__NEXT_DATA__')[0].children[0].data);
|
||||
if (!page_data.props.pageProps.podcast?.episodes) {
|
||||
// If episodes are not found, it might be an episode page
|
||||
// Try to get the podcast id from the episode page
|
||||
link = `https://www.xiaoyuzhoufm.com/episode/${id}`;
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
$ = load(response.data);
|
||||
const podcastLink = $('.jsx-605929003.podcast-title .jsx-605929003.name').attr('href');
|
||||
if (podcastLink) {
|
||||
const podcastId = podcastLink.split('/').pop();
|
||||
link = `https://www.xiaoyuzhoufm.com/podcast/${podcastId}`;
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
$ = load(response.data);
|
||||
page_data = JSON.parse($('#__NEXT_DATA__')[0].children[0].data);
|
||||
}
|
||||
}
|
||||
|
||||
if (!page_data.props.pageProps.podcast?.episodes) {
|
||||
throw new Error('Failed to fetch podcast episodes');
|
||||
}
|
||||
|
||||
const episodes = page_data.props.pageProps.podcast.episodes.map((item) => ({
|
||||
title: item.title,
|
||||
|
||||
Reference in New Issue
Block a user