Skip to content

Commit

Permalink
feat: 风之动漫可全文输出漫画内容
Browse files Browse the repository at this point in the history
  • Loading branch information
zytomorrow committed Jan 11, 2021
1 parent 0747bfb commit 1076839
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pageClass: routes

### 风之动漫

<Route author="geeeeoff" path="/fzdm/manhua/:id" example="/fzdm/manhua/39" :paramsDesc="['漫画ID']"/>
<Route author="geeeeoff zytomorrow" path="/fzdm/manhua/:id/:nums?" example="/fzdm/manhua/39/2" :paramsDesc="['漫画ID', '最新的n话, 默认为最新1话']" anticrawler="1"/>

## 海猫吧

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
56 changes: 49 additions & 7 deletions lib/routes/fzdm/manhua.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += `<img src='http://www-mipengine-org.mipcdn.com/i/p5.manhuapan.com/${picurl[picurl.length - 1]}'/><br/>`;
} 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',
Expand All @@ -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,
})),
};
};

0 comments on commit 1076839

Please sign in to comment.