mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
add anitama (#1770)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'));
|
||||
|
||||
|
||||
55
lib/routes/anitama/channel.js
Normal file
55
lib/routes/anitama/channel.js
Normal 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user