diff --git a/docs/anime.md b/docs/anime.md index 827716fbf3..03586e7de1 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -89,3 +89,7 @@ ## Anitama + +## 嘀哩嘀哩-dilidili + + diff --git a/lib/router.js b/lib/router.js index 228f6eaac4..df3a6eed7a 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1328,6 +1328,9 @@ router.get('/asahichinese-f/:category', require('./routes/asahichinese-f/index') // 7x24小时快讯 router.get('/fx678/kx', require('./routes/fx678/kx')); +// dilidili +router.get('/dilidili/fanju/:id', require('./routes/dilidili/fanju')); + // 且听风吟福利 router.get('/qtfyfl/:category', require('./routes/qtfyfl/category')); diff --git a/lib/routes/dilidili/fanju.js b/lib/routes/dilidili/fanju.js new file mode 100644 index 0000000000..8a4fcc9dcf --- /dev/null +++ b/lib/routes/dilidili/fanju.js @@ -0,0 +1,72 @@ +// 调用axios获取页面源码 +const axios = require('../../utils/axios'); +// 调用cheerio分析抓取到的html,利用类似jQuery的方法解析 +const cheerio = require('cheerio'); + +async function load(link, ctx) { + // 定义cache 存储通过link获取到的缓存内容 + const cache = await ctx.cache.get(link); + // 如果缓存已经存在,则直接返回,否则对其进行解析 + if (cache) { + return cache; + } + const response = await axios.get(link); + const $ = cheerio.load(response.data); + // 获取相关内容 + let introduce = $('#intro2 > p:nth-child(3)').text(); + // 将'简介'字段与内容分离,为了更优美的阅读界面 + introduce = introduce.replace('简介', '简介
'); + const image = ``; + const detailResult = `${introduce}
${image}`; + + // 定义description,并指定内容 + const description = detailResult; + await ctx.cache.set(link, description); + return { + description, + }; +} + +// 通过module.exports暴露给router +module.exports = async (ctx) => { + const id = ctx.params.id; + + // 使用get方法请求主页面,然后获取其返回的response + const response = await axios({ + method: 'get', + url: `http://www.dilidili.name/anime/${id}`, + }); + // 获取页面的html + const data = response.data; + // 将页面html交于cheerio处理成类似jQuery的节点 + const $ = cheerio.load(data); + // 获取番剧名称 + const animeName = $('body > div.container.clear > div.clear > div:nth-child(2) > div.detail.con24.clear > dl > dd > h1').text(); + + // @param {*} list 用于存储通过 " h4 > a "获取到的节点 + const list = $('body > div.container.clear > div.clear > div:nth-child(2) > div.con24.m-10.xf_news > div.time_pic.list > div:nth-child(1) > div.swiper-container.xfswiper1 > div > div > ul > li > a').get(); // 获取到剧集列表 + // 使用promise处理多个节点 + const process = await Promise.all( + // 在list变量上使用map方法,对其拥有的每一个元素均进行"匿名函数"的操作 + list.map(async (item) => { + // item为回调的参数 + // 定义itemUrl + const itemUrl = $(item).attr('href'); + // 定义导出到rss的单体对象,包含title,link,guid三个参数 + const single = { + title: $(item).text(), + link: itemUrl, + guid: itemUrl, + }; + // 调用load方法,获取到的是string对象{description} + const other = await load(itemUrl, ctx); + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + ctx.state.data = { + title: `${animeName} - 嘀哩嘀哩`, + link: `http://www.dilidili.name/anime/${id}`, + description: `${animeName}更新提醒`, + item: process, + }; +};