mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-13 16:49:31 +08:00
feat: add AEON & SA 60-Second Science (#3213)
This commit is contained in:
48
lib/routes/60s-science/transcript.js
Normal file
48
lib/routes/60s-science/transcript.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `https://www.scientificamerican.com/podcast/60-second-science/`;
|
||||
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $('.underlined_text.t_small').get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $(item).attr('aria-label');
|
||||
const address = $(item).attr('href');
|
||||
const cache = await ctx.cache.get(address);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await got.get(address);
|
||||
const capture = cheerio.load(res.data);
|
||||
|
||||
const tStr = '.article-header__divider > ul > li > span:nth-child(2)';
|
||||
const time = capture(tStr).text();
|
||||
const aStr = '.article-header__divider > ul > li > span:nth-child(1) > span';
|
||||
const author = capture(aStr).text();
|
||||
|
||||
capture('.transcript__close').remove();
|
||||
const intro = capture('.article-media__object').html() + '<br><br>';
|
||||
const contents = intro + capture('.transcript__inner').html();
|
||||
const single = {
|
||||
title,
|
||||
description: contents,
|
||||
link: address,
|
||||
guid: address,
|
||||
author: author,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(address, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: 'Transcripts of SA 60-Second Science',
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user