add anitama (#1770)

This commit is contained in:
RANPOX
2019-03-18 15:25:09 +08:00
committed by DIYgod
parent f83a3c8bf9
commit 2271dc72a8
3 changed files with 62 additions and 0 deletions

View File

@@ -1305,6 +1305,10 @@ GitHub 官方也提供了一些 RSS:
<route name="ebb" author="Tsuki" example="/ebb" path="/ebb"/>
### Anitama
<route name="Anitama Channel" author="ranpox" path="/anitama/:channel?" example="/anitama" :paramsDesc="['频道id从频道的地址栏中查看']"/>
## 程序更新
### RSSHub

View File

@@ -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'));

View File

@@ -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,
};
};