From 75b9a49aabe6ddd382a7cc9a44be2674b1d09a4c Mon Sep 17 00:00:00 2001 From: marvolo666 Date: Sun, 23 Jan 2022 03:02:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8B=B7=E8=B4=9D=E6=BC=AB?= =?UTF-8?q?=E7=94=BB=E5=92=8C=E6=BC=AB=E7=94=BB=E6=9F=9C=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E9=87=8F=E6=8E=A7=E5=88=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E5=A4=8D=E6=BC=AB=E7=94=BB?= =?UTF-8?q?=E6=9F=9C=E4=B8=80=E4=BA=9Bbug=20(#8670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 12051825 --- assets/radar-rules.js | 5 +- docs/anime.md | 8 +-- lib/router.js | 8 ++- lib/routes/copymanga/comic.js | 5 +- lib/routes/manhuagui/comic.js | 102 +++++++++++++++++++++++--------- lib/routes/mhgui/comic.js | 102 +++++++++++++++++++++++--------- lib/routes/twmanhuagui/comic.js | 102 +++++++++++++++++++++++--------- 7 files changed, 237 insertions(+), 95 deletions(-) diff --git a/assets/radar-rules.js b/assets/radar-rules.js index 4110d95b3..01f701b6f 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -250,9 +250,10 @@ 'ishuhui.com': { _name: '鼠绘漫画', www: [{ title: '鼠绘漫画', docs: 'https://docs.rsshub.app/anime.html#shu-hui-man-hua', source: '/comics/anime/:id', target: '/shuhui/comics/:id' }] }, 'www.chicagotribune.com': { _name: 'Chicago Tribune', www: [{ title: 'Chicago Tribune', docs: 'https://docs.rsshub.app/traditional_media.html#chicago-tribune', source: '/' }] }, 'haimaoba.com': { _name: '海猫吧', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#hai-mao-ba', source: '/catalog/:id', target: '/haimaoba/:id' }] }, - 'manhuagui.com': { _name: '漫画柜', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kan-man-hua', source: '/comic/:id/', target: '/manhuagui/comic/:id' }] }, - 'mhgui.com': { _name: '漫画柜镜像站', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kan-man-hua-jing-xiang-zhan', source: '/comic/:id/', target: '/mhgui/comic/:id' }] }, + 'manhuagui.com': { _name: '漫画柜', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kan-man-hua', source: '/comic/:id/', target: '/manhuagui/comic/:id/5' }] }, + 'mhgui.com': { _name: '漫画柜镜像站', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kan-man-hua-jing-xiang-zhan', source: '/comic/:id/', target: '/mhgui/comic/:id/5' }] }, 'tw.manhuagui.com': { _name: '漫画柜台湾', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kan-man-hua-tai-wan', source: '/comic/:id/', target: '/twmanhuagui/comic/:id' }] }, + 'copymanga.com': { _name: '拷贝漫画', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#kao-bei-man-hua', source: '/comic/:id/', target: '/manhuagui/comic/:id/5' }] }, 'pgyer.com': { _name: '蒲公英应用分发', www: [{ title: 'app更新', docs: 'https://docs.rsshub.app/program-update.html#pu-gong-ying-ying-yong-fen-fa', source: '/:app', target: '/pgyer/:app' }] }, 'pianyuan.la': { _name: '片源网', '.': [{ title: '电影和剧集', docs: 'https://docs.rsshub.app/multimedia.html#pian-yuan', source: '/' }] }, 'sspai.com': { diff --git a/docs/anime.md b/docs/anime.md index c16af579c..633f64fbd 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -407,25 +407,25 @@ Sources ### 漫画更新 - + ## 看漫画镜像站 ### 漫画更新 - + ## 看漫画台湾 ### 漫画更新 - + ## 拷贝漫画 ### 漫画更新 - + ## 漫画 DB diff --git a/lib/router.js b/lib/router.js index 14961c33d..774a2b8eb 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1122,9 +1122,11 @@ router.get('/eeo/:column?/:category?', lazyloadRouteHandler('./routes/eeo/index' router.get('/tencentvideo/playlist/:id', lazyloadRouteHandler('./routes/tencent/video/playlist')); // 看漫画 -router.get('/manhuagui/comic/:id', lazyloadRouteHandler('./routes/manhuagui/comic')); -router.get('/mhgui/comic/:id', lazyloadRouteHandler('./routes/mhgui/comic')); -router.get('/twmanhuagui/comic/:id', lazyloadRouteHandler('./routes/twmanhuagui/comic')); +router.get('/manhuagui/comic/:id/:chapterCnt?', lazyloadRouteHandler('./routes/manhuagui/comic')); +router.get('/mhgui/comic/:id/:chapterCnt?', lazyloadRouteHandler('./routes/mhgui/comic')); +router.get('/twmanhuagui/comic/:id/:chapterCnt?', lazyloadRouteHandler('./routes/twmanhuagui/comic')); +// 拷贝漫画 +router.get('/copymanga/comic/:id/:chapterCnt?', lazyloadRouteHandler('./routes/copymanga/comic')); // 拷贝漫画 router.get('/copymanga/comic/:id', lazyloadRouteHandler('./routes/copymanga/comic')); diff --git a/lib/routes/copymanga/comic.js b/lib/routes/copymanga/comic.js index c5697f8ff..846180c55 100644 --- a/lib/routes/copymanga/comic.js +++ b/lib/routes/copymanga/comic.js @@ -4,7 +4,8 @@ const got = require('@/utils/got'); // 直接调用拷贝漫画的接口 module.exports = async (ctx) => { const { id } = ctx.params; - + // 用于控制返回的章节数量 + const chapterCnt = Number(ctx.params.chapterCnt || 0); // 获取漫画列表 let bHasNextPage = false; const iReqLimit = (ctx.queries && ctx.queries.limit) || 100; @@ -62,6 +63,6 @@ module.exports = async (ctx) => { title: `拷贝漫画 - ${bookTitle}`, link: `https://copymanga.com/comic/${id}`, description: bookIntro, - item: chapterArray.map(genResult), + item: chapterArray.map(genResult).slice(0, chapterCnt), }; }; diff --git a/lib/routes/manhuagui/comic.js b/lib/routes/manhuagui/comic.js index 5fef23310..f7698b750 100644 --- a/lib/routes/manhuagui/comic.js +++ b/lib/routes/manhuagui/comic.js @@ -3,23 +3,47 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); const LZString = require('lz-string'); -const getChapters = ($) => - $('.chapter-list > ul') +const getChapters = ($) => { + let time_mark = 100; + // 用于一次更新多个新章节的排序 + let new_time_mark = 0; + return $('h4') .toArray() - .reverse() - .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) .map((ele) => { - const a = $(ele).children('a'); - return { - link: resolve('https://www.manhuagui.com/', a.attr('href')), - title: a.attr('title'), - num: a.find('i').text(), - }; - }); - + const categoryName = $(ele).text(); + while (!$(ele.next).hasClass('chapter-list')) { + ele = ele.next; + } + ele = ele.next; + return $(ele) + .children('ul') + .toArray() + .reverse() + .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) + .map((ele) => { + const a = $(ele).children('a'); + // 通过操作发布时间来对章节进行排序,如果是刚刚更新的单行本或者番外,保留最新更新时间 + let pDate = new Date(new Date($.pubDate) - time_mark++ * 1000); + if (a.find('em').length > 0) { + // 对更新的章节也进行排序 + pDate = new Date(new Date($.pubDate) - new_time_mark++ * 1000); + $.newChapterCnt++; + } + return { + link: resolve('https://www.manhuagui.com/', a.attr('href')), + title: a.attr('title'), + pub_date: pDate, + num: a.find('i').text(), + guid: resolve('https://www.manhuagui.com/', a.attr('href')), + category: categoryName, + }; + }); + }) + .reduce((acc, curr) => acc.concat(curr)); +}; module.exports = async (ctx) => { const { id } = ctx.params; - + const chapterCnt = Number(ctx.params.chapterCnt || 0); const { data } = await got.get(`https://www.manhuagui.com/comic/${id}/`); const $ = cheerio.load(data); @@ -30,24 +54,46 @@ module.exports = async (ctx) => { $('#__VIEWSTATE').remove(); } } - const bookTitle = $('.book-title > h1').text(); const bookIntro = $('#intro-all').text(); const coverImgSrc = $('.book-cover img').attr('src'); - const chapters = getChapters($); - - const genResult = (chapter) => ({ - link: chapter.link, - title: chapter.title, - description: ` + // 对最新更新的章节增加了pubDate + const reg = new RegExp('最近于.+更新至'); + // 处理已下架的漫画 + if ($('.status > span').text().indexOf('已下架') > 0) { + ctx.state.data = { + title: `看漫画 - ${bookTitle} 已下架`, + link: `https://www.manhuagui.com/comic/${id}/`, + description: bookIntro, + item: [{ link: `https://www.manhuagui.com/comic/${id}/`, title: bookTitle, description: '已下架' }], + }; + } else { + const pub_date_str = $('.status > span').text().match(reg)[0].replace('最近于 [', '').replace('] 更新至', ''); + // 为了能在闭包内访问到这个日期而不是每次需要处理这个最近更新日期 + $.pubDate = new Date(pub_date_str).toUTCString(); + $.newChapterCnt = 0; + const chapters = getChapters($); + const genResult = (chapter) => ({ + link: chapter.link, + title: chapter.title, + pubDate: chapter.pub_date, + guid: chapter.guid, + category: chapter.category, + description: `

${chapter.num}

- + `.trim(), - }); - ctx.state.data = { - title: `看漫画 - ${bookTitle}`, - link: `https://www.manhuagui.com/comic/${id}/`, - description: bookIntro, - item: chapters.map(genResult), - }; + }); + const items = chapters.map(genResult); + let itemsLen = items.length; + if (chapterCnt > 0) { + itemsLen = (chapterCnt < $.newChapterCnt) ? $.newChapterCnt : chapterCnt; + } + ctx.state.data = { + title: `看漫画 - ${bookTitle}`, + link: `https://www.manhuagui.com/comic/${id}/`, + description: bookIntro, + item: items.slice(0, itemsLen), + }; + } }; diff --git a/lib/routes/mhgui/comic.js b/lib/routes/mhgui/comic.js index ae28a1859..3cfd056bd 100644 --- a/lib/routes/mhgui/comic.js +++ b/lib/routes/mhgui/comic.js @@ -3,23 +3,47 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); const LZString = require('lz-string'); -const getChapters = ($) => - $('.chapter-list > ul') +const getChapters = ($) => { + let time_mark = 0; + // 用于一次更新多个新章节的排序 + let new_time_mark = 0; + return $('h4') .toArray() - .reverse() - .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) .map((ele) => { - const a = $(ele).children('a'); - return { - link: resolve('https://www.mhgui.com/', a.attr('href')), - title: a.attr('title'), - num: a.find('i').text(), - }; - }); - + const categoryName = $(ele).text(); + while (!$(ele.next).hasClass('chapter-list')) { + ele = ele.next; + } + ele = ele.next; + return $(ele) + .children('ul') + .toArray() + .reverse() + .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) + .map((ele) => { + const a = $(ele).children('a'); + // 通过操作发布时间来对章节进行排序,如果是刚刚更新的单行本或者番外,保留最新更新时间 + let pDate = new Date(new Date($.pubDate) - time_mark++ * 1000); + if (a.find('em').length > 0) { + // 对更新的章节也进行排序 + pDate = new Date(new Date($.pubDate) - new_time_mark++ * 1000); + $.newChapterCnt++; + } + return { + link: resolve('https://www.mhgui.com/', a.attr('href')), + title: a.attr('title'), + pub_date: pDate, + num: a.find('i').text(), + guid: resolve('https://www.mhgui.com/', a.attr('href')), + category: categoryName, + }; + }); + }) + .reduce((acc, curr) => acc.concat(curr)); +}; module.exports = async (ctx) => { const { id } = ctx.params; - + const chapterCnt = Number(ctx.params.chapterCnt || 0); const { data } = await got.get(`https://www.mhgui.com/comic/${id}/`); const $ = cheerio.load(data); @@ -30,24 +54,46 @@ module.exports = async (ctx) => { $('#__VIEWSTATE').remove(); } } - const bookTitle = $('.book-title > h1').text(); const bookIntro = $('#intro-all').text(); const coverImgSrc = $('.book-cover img').attr('src'); - const chapters = getChapters($); - - const genResult = (chapter) => ({ - link: chapter.link, - title: chapter.title, - description: ` + // 对最新更新的章节增加了pubDate + const reg = new RegExp('最近于.+更新至'); + // 处理已下架的漫画 + if ($('.status > span').text().indexOf('已下架') > 0) { + ctx.state.data = { + title: `看漫画 - ${bookTitle} 已下架`, + link: `https://www.mhgui.com/comic/${id}/`, + description: bookIntro, + item: [{ link: `https://www.mhgui.com/comic/${id}/`, title: bookTitle, description: '已下架' }], + }; + } else { + const pub_date_str = $('.status > span').text().match(reg)[0].replace('最近于 [', '').replace('] 更新至', ''); + // 为了能在闭包内访问到这个日期而不是每次需要处理这个最近更新日期 + $.pubDate = new Date(pub_date_str).toUTCString(); + $.newChapterCnt = 0; + const chapters = getChapters($); + const genResult = (chapter) => ({ + link: chapter.link, + title: chapter.title, + pubDate: chapter.pub_date, + guid: chapter.guid, + category: chapter.category, + description: `

${chapter.num}

- + `.trim(), - }); - ctx.state.data = { - title: `看漫画 - ${bookTitle}`, - link: `https://www.mhgui.com/comic/${id}/`, - description: bookIntro, - item: chapters.map(genResult), - }; + }); + const items = chapters.map(genResult); + let itemsLen = items.length; + if (chapterCnt > 0) { + itemsLen = (chapterCnt < $.newChapterCnt) ? $.newChapterCnt : chapterCnt; + } + ctx.state.data = { + title: `看漫画 - ${bookTitle}`, + link: `https://www.mhgui.com/comic/${id}/`, + description: bookIntro, + item: items.slice(0, itemsLen), + }; + } }; diff --git a/lib/routes/twmanhuagui/comic.js b/lib/routes/twmanhuagui/comic.js index 090645acf..a303f0ce9 100644 --- a/lib/routes/twmanhuagui/comic.js +++ b/lib/routes/twmanhuagui/comic.js @@ -3,23 +3,47 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); const LZString = require('lz-string'); -const getChapters = ($) => - $('.chapter-list > ul') +const getChapters = ($) => { + let time_mark = 0; + // 用于一次更新多个新章节的排序 + let new_time_mark = 0; + return $('h4') .toArray() - .reverse() - .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) .map((ele) => { - const a = $(ele).children('a'); - return { - link: resolve('https://tw.manhuagui.com/', a.attr('href')), - title: a.attr('title'), - num: a.find('i').text(), - }; - }); - + const categoryName = $(ele).text(); + while (!$(ele.next).hasClass('chapter-list')) { + ele = ele.next; + } + ele = ele.next; + return $(ele) + .children('ul') + .toArray() + .reverse() + .reduce((acc, curr) => acc.concat($(curr).children('li').toArray()), []) + .map((ele) => { + const a = $(ele).children('a'); + // 通过操作发布时间来对章节进行排序,如果是刚刚更新的单行本或者番外,保留最新更新时间 + let pDate = new Date(new Date($.pubDate) - time_mark++ * 1000); + if (a.find('em').length > 0) { + // 对更新的章节也进行排序 + pDate = new Date(new Date($.pubDate) - new_time_mark++ * 1000); + $.newChapterCnt++; + } + return { + link: resolve('https://tw.manhuagui.com/', a.attr('href')), + title: a.attr('title'), + pub_date: pDate, + num: a.find('i').text(), + guid: resolve('https://tw.manhuagui.com/', a.attr('href')), + category: categoryName, + }; + }); + }) + .reduce((acc, curr) => acc.concat(curr)); +}; module.exports = async (ctx) => { const { id } = ctx.params; - + const chapterCnt = Number(ctx.params.chapterCnt || 0); const { data } = await got.get(`https://tw.manhuagui.com/comic/${id}/`); const $ = cheerio.load(data); @@ -30,24 +54,46 @@ module.exports = async (ctx) => { $('#__VIEWSTATE').remove(); } } - const bookTitle = $('.book-title > h1').text(); const bookIntro = $('#intro-all').text(); const coverImgSrc = $('.book-cover img').attr('src'); - const chapters = getChapters($); - - const genResult = (chapter) => ({ - link: chapter.link, - title: chapter.title, - description: ` + // 对最新更新的章节增加了pubDate + const reg = new RegExp('最近於.+更新至'); + // 处理已下架的漫画 + if ($('.status > span').text().indexOf('已下架') > 0) { + ctx.state.data = { + title: `看漫画 - ${bookTitle} 已下架`, + link: `https://tw.manhuagui.com/comic/${id}/`, + description: bookIntro, + item: [{ link: `https://tw.manhuagui.com/comic/${id}/`, title: bookTitle, description: '已下架' }], + }; + } else { + const pub_date_str = $('.status > span').text().match(reg)[0].replace('最近於 [', '').replace('] 更新至', ''); + // 为了能在闭包内访问到这个日期而不是每次需要处理这个最近更新日期 + $.pubDate = new Date(pub_date_str).toUTCString(); + $.newChapterCnt = 0; + const chapters = getChapters($); + const genResult = (chapter) => ({ + link: chapter.link, + title: chapter.title, + pubDate: chapter.pub_date, + guid: chapter.guid, + category: chapter.category, + description: `

${chapter.num}

- + `.trim(), - }); - ctx.state.data = { - title: `看漫画 - ${bookTitle}`, - link: `https://tw.manhuagui.com/comic/${id}/`, - description: bookIntro, - item: chapters.map(genResult), - }; + }); + const items = chapters.map(genResult); + let itemsLen = items.length; + if (chapterCnt > 0) { + itemsLen = (chapterCnt < $.newChapterCnt) ? $.newChapterCnt : chapterCnt; + } + ctx.state.data = { + title: `看漫画 - ${bookTitle}`, + link: `https://tw.manhuagui.com/comic/${id}/`, + description: bookIntro, + item: items.slice(0, itemsLen), + }; + } };