From 494da8eeb30f30199372a021480aa281bfd97c47 Mon Sep 17 00:00:00 2001 From: Huang Kan Date: Tue, 22 Jan 2019 14:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1=E5=8B=95?= =?UTF-8?q?=E6=BC=AB=E7=8B=82|add=20router=20for=20(https://www.cartoonmad?= =?UTF-8?q?.com)=20(#1442)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加路由動漫狂|add router for (https://www.cartoonmad.com) 测试通过: 1.别当欧尼酱了(https://www.cartoonmad.com/comic/5827) 2.第一次的Gal(https://www.cartoonmad.com/comic/5107) --- docs/README.md | 4 +++ lib/router.js | 2 ++ lib/routes/cartoonmad/comic.js | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/routes/cartoonmad/comic.js 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), + }; +};