diff --git a/docs/README.md b/docs/README.md index f81d948646..f0331fad7d 100755 --- a/docs/README.md +++ b/docs/README.md @@ -1305,6 +1305,10 @@ GitHub 官方也提供了一些 RSS: +### Anitama + + + ## 程序更新 ### RSSHub diff --git a/lib/router.js b/lib/router.js index 9ebbc5483c..7bb76564a6 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1163,6 +1163,9 @@ router.get('/vgtime/release', require('./routes/vgtime/release')); // MP4吧 router.get('/mp4ba/:param', require('./routes/mp4ba')); +// anitama +router.get('/anitama/:channel?', require('./routes/anitama/channel')); + // 親子王國 router.get('/babykingdom/:id/:order?', require('./routes/babykingdom')); diff --git a/lib/routes/anitama/channel.js b/lib/routes/anitama/channel.js new file mode 100644 index 0000000000..31fd44685a --- /dev/null +++ b/lib/routes/anitama/channel.js @@ -0,0 +1,55 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const baseUrl = 'http://www.anitama.cn'; + const url = 'http://www.anitama.cn/channel/' + (ctx.params.channel ? ctx.params.channel : ''); + + const response = await axios({ + method: 'get', + url: url, + }); + + const $ = cheerio.load(response.data); + const channel_name = $('#area-article-channel .bar') + .text() + .slice(0, -5); + const list = $('#area-article-channel div.inner a') + .slice(0, 10) + .map((i, e) => ({ + link: baseUrl + $(e).attr('href'), + })) + .get(); + + const out = await Promise.all( + list.map(async (item) => { + const { link } = item; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(link); + + const $ = cheerio.load(response.data); + const single = { + pubDate: $('.time').text(), + author: $('.author').text(), + link: link, + title: $('h1').text() + '-' + $('h2').text(), + description: $('#area-content-article').text(), + }; + + ctx.cache.set(link, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: 'Anitama-' + channel_name, + link: url, + description: 'Anitama-' + channel_name, + item: out, + }; +};