diff --git a/docs/anime.md b/docs/anime.md index bcc037374d..cf25578ecb 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -288,7 +288,7 @@ pageClass: routes ### 风之动漫 - + ## 海猫吧 diff --git a/lib/router.js b/lib/router.js index 2da4052374..caf0600ea3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2931,7 +2931,7 @@ router.get('/grubstreet', require('./routes/grubstreet/index')); router.get('/manhuadui/manhua/:name/:serial?', require('./routes/manhuadui/manhua')); // 风之漫画 -router.get('/fzdm/manhua/:id', require('./routes/fzdm/manhua')); +router.get('/fzdm/manhua/:id/:nums?', require('./routes/fzdm/manhua')); // Aljazeera 半岛网 router.get('/aljazeera/news', require('./routes/aljazeera/news')); diff --git a/lib/routes/fzdm/manhua.js b/lib/routes/fzdm/manhua.js index 8d47d5fe83..949b8f2ae8 100644 --- a/lib/routes/fzdm/manhua.js +++ b/lib/routes/fzdm/manhua.js @@ -2,8 +2,42 @@ const got = require('@/utils/got'); const host = 'https://manhua.fzdm.com'; const cheerio = require('cheerio'); +const get_pic = (id, chapert, caches) => { + const picUrlPattern = RegExp(/var (mhurl1|mhurl)="(.*?)";/); + return caches.tryGet(`${host}/${id}/${chapert}/`, async () => { + let is_last_page = false; + let index = 0; + let pic_content = ''; + while (!is_last_page) { + // eslint-disable-next-line no-await-in-loop + const response = await got.get(`${host}/${id}/${chapert}/index_${index}.html`, { + headers: { + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36', + Host: 'manhua.fzdm.com', + 'Accept-Encoding': 'gzip, deflate, br', + Connection: 'keep-alive', + }, + }); + const data = response.data; + if (response.data !== undefined) { + const picurl = data.match(picUrlPattern); + pic_content += `
`; + } else { + pic_content += ''; + is_last_page = true; + } + if (data.match('最后一页了') !== null) { + is_last_page = true; + } + index += 1; + } + return pic_content; + }); +}; + module.exports = async (ctx) => { const id = ctx.params.id; + const nums = ctx.params.nums || 1; const comicPage = host + `/${id}/`; const response = await got({ method: 'get', @@ -13,16 +47,24 @@ module.exports = async (ctx) => { const $ = cheerio.load(data); const list = $('div#content > li > a'); const comicTitle = $('div#content > img').attr('alt').replace(/漫画/, ''); + const chapter_detail = await Promise.all( + list.splice(0, nums).map(async (item) => { + const pic_content = await get_pic(id, $(item).attr('href').replace('/', ''), ctx.cache); + return { + title: $(item).text().trim(), + description: pic_content, + link: item.link, + }; + }) + ); ctx.state.data = { title: '风之动漫 - ' + comicTitle, link: comicPage, description: '风之动漫', - item: list - .map((i, item) => ({ - title: $(item).text().trim(), - description: $(item).text().trim(), - link: comicPage + $(item).attr('href'), - })) - .get(), + item: chapter_detail.map((item) => ({ + title: item.title, + description: item.description, + link: item.link, + })), }; };