diff --git a/docs/README.md b/docs/README.md index d3e408344..396b23a22 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1113,6 +1113,10 @@ GitHub 官方也提供了一些 RSS: +### 動畫狂 + + + ### Anime1 diff --git a/lib/router.js b/lib/router.js index 18acedf3f..841424ba1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -876,6 +876,8 @@ router.get('/tencentvideo/playlist/:id', require('./routes/tencent/video/playlis // 看漫画 router.get('/manhuagui/comic/:id', require('./routes/manhuagui/comic')); +// 動漫狂 +router.get('/cartoonmad/comic/:id', require('./routes/cartoonmad/comic')); // Tits Guru router.get('/tits-guru/home', require('./routes/titsguru/home')); diff --git a/lib/routes/cartoonmad/comic.js b/lib/routes/cartoonmad/comic.js new file mode 100644 index 000000000..4a480b4b9 --- /dev/null +++ b/lib/routes/cartoonmad/comic.js @@ -0,0 +1,58 @@ +const { resolve } = require('url'); +const cheerio = require('cheerio'); +const axios = require('../../utils/axios'); +const iconv = require('iconv-lite'); + +const getChapters = ($) => + $('#info') + .eq(1) + .find('a') + .map((_, ele) => { + const a = $(ele); + return { + link: resolve('https://www.cartoonmad.com/', a.attr('href')), + title: a.text(), + num: a + .parent() + .find('font') + .text(), + }; + }) + .toArray(); + +module.exports = async (ctx) => { + const { id } = ctx.params; + + const { data } = await axios.get(`https://www.cartoonmad.com/comic/${id}`, { responseType: 'arraybuffer' }); + const content = iconv.decode(new Buffer.from(data), 'big5'); + const $ = cheerio.load(content); + + const bookTitle = $('title') + .text() + .match(/\S+/)[0]; + const bookIntro = $('#info') + .eq(0) + .find('td') + .text() + .trim(); + const coverImgSrc = $('.cover') + .parent() + .find('img') + .attr('src'); + const chapters = getChapters($); + + const genResult = (chapter) => ({ + link: chapter.link, + title: chapter.title, + description: ` +

${chapter.num}

+ + `.trim(), + }); + ctx.state.data = { + title: `動漫狂 - ${bookTitle}`, + link: `https://www.cartoonmad.com/comic/${id}`, + description: bookIntro, + item: chapters.map(genResult), + }; +};