Skip to content

Commit

Permalink
completed asurascans
Browse files Browse the repository at this point in the history
  • Loading branch information
zcrossoverz committed Jun 29, 2023
1 parent fa0fa06 commit 53ef351
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The manga-lib currently supports the following manga websites (updating):

- blogtruyen

- asurascans (in progress)
- asurascans

## Contributing

Expand Down
1 change: 0 additions & 1 deletion dist/src/hooks/getDataChapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const useGetDataChapter = (params) => __awaiter(void 0, void 0, void 0, function
.$eval(nextChapterSelector, (el) => {
return {
url_chapter: el.getAttribute('href'),
t: el.outerHTML,
};
})
.catch(() => null);
Expand Down
6 changes: 4 additions & 2 deletions dist/src/hooks/getListLatest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const useGetDataItemsManga = (params) => __awaiter(void 0, void 0, void 0, funct
else {
const wrapItems = yield puppeteer.$$(wrapSelector);
data = yield Promise.all(wrapItems.map((e, i) => __awaiter(void 0, void 0, void 0, function* () {
const image_thumbnail = yield e.$eval(thumbnailSelector, (el) => el.getAttribute(`${thumbnailAttr}`));
const image_thumbnail = yield (yield e.$(thumbnailSelector)).evaluate((el, thumbnailAttr) => {
return el.getAttribute(thumbnailAttr);
}, thumbnailAttr);
const { href } = yield e.$eval(hrefSelector, (el) => {
return {
href: el.getAttribute('href'),
Expand All @@ -41,7 +43,7 @@ const useGetDataItemsManga = (params) => __awaiter(void 0, void 0, void 0, funct
});
return {
_id: i,
title: (0, validate_1.not_null)(title),
title: (0, validate_1.not_null)(title).trim().replace(/\n/, ''),
href: (0, validate_1.not_null)(href),
image_thumbnail: image_thumbnail.startsWith('//')
? `https:${image_thumbnail}`
Expand Down
3 changes: 1 addition & 2 deletions dist/src/lib/asurascans.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Browser } from 'puppeteer';
import { AbstractMangaFactory, chapter, genre, responseChapter, responseDetailManga, responseListManga } from '../types/type';
import { NETTRUYEN_SORT_FILTER, NETTRUYEN_STATUS_FILTER } from '../constants/filter';
export declare class AsuraScans implements AbstractMangaFactory {
baseUrl: string;
all_genres: genre[];
browser: Promise<Browser>;
constructor(baseUrl: string);
search(keyword: string, page?: number): Promise<responseListManga>;
getListByGenre(genre: genre, page?: number, status?: NETTRUYEN_STATUS_FILTER, sort?: NETTRUYEN_SORT_FILTER): Promise<responseListManga>;
getListByGenre(genre: genre, page?: number, status?: any, sort?: any): Promise<responseListManga>;
getDataChapter(url_chapter: string, url?: string, path?: string, prev_chapter?: chapter, next_chapter?: chapter): Promise<responseChapter>;
getDetailManga(url: string): Promise<responseDetailManga>;
getListLatestUpdate(page?: number): Promise<responseListManga>;
Expand Down
120 changes: 58 additions & 62 deletions dist/src/lib/asurascans.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,94 +35,74 @@ class AsuraScans {
else
req.continue();
});
yield _page.goto(`${this.baseUrl}/tim-truyen?keyword=${keyword}${page > 1 ? `&page=${page}` : ``}`);
const element = yield _page.$$('#ctl00_divCenter > div.Module.Module-170 > div > div.items > div > div.item > figure');
const is_multipage = yield _page
.$eval('#ctl00_mainContent_ctl01_divPager', () => true)
yield _page.goto(`${this.baseUrl}${page > 1 ? `/page/${page}` : ``}/?s=${keyword}`);
const paramsSelector = {
puppeteer: _page,
wrapSelector: 'div.listupd > div.bs > div.bsx',
titleSelector: 'a > div.bigor > div.tt',
thumbnailSelector: 'a > div.limit > img',
thumbnailAttr: 'src',
hrefSelector: 'a',
};
const data = yield (0, getListLatest_1.useGetDataItemsManga)(paramsSelector);
const canNext = yield _page
.$eval('div.pagination > a.next.page-numbers', () => true)
.catch(() => false);
const canNext = is_multipage
? yield _page
.$eval('#ctl00_mainContent_ctl01_divPager > ul > li > a.next-page', () => true)
.catch(() => false)
: false;
const canPrev = is_multipage
? yield _page
.$eval('#ctl00_mainContent_ctl01_divPager > ul > li > a.prev-page', () => true)
.catch(() => false)
: false;
const totalPage = is_multipage
? parseInt((0, validate_1.not_null)(yield _page.$eval('#ctl00_mainContent_ctl01_divPager > ul > li:last-child > a', (el) => el.getAttribute('href'))).split('page=')[1])
const canPrev = yield _page
.$eval('div.pagination > a.prev.page-numbers', () => true)
.catch(() => false);
const totalPages = yield _page.$$('div.pagination > a.page-numbers:not(.prev):not(.next)');
const totalPage = totalPages !== undefined
? Number(yield totalPages[totalPages.length - 1].evaluate((el) => el.textContent))
: 0;
return {
totalData: element.length,
totalData: data.length,
totalPage,
currentPage: page !== undefined ? page : 1,
canNext,
canPrev,
data: yield Promise.all(element.map((e, i) => __awaiter(this, void 0, void 0, function* () {
const href = (0, validate_1.not_null)(yield e.$eval('div.image > a', (el) => el.getAttribute('href')));
const title = (0, validate_1.not_null)(yield e.$eval('figcaption > h3 > a', (el) => el.textContent));
const image_thumbnail = (0, validate_1.not_null)(yield e.$eval('div.image > a > img', (el) => el.getAttribute('data-original')));
return {
_id: i,
title,
image_thumbnail: image_thumbnail.startsWith('//')
? `https:${image_thumbnail}`
: image_thumbnail,
href,
};
}))),
data,
};
});
}
getListByGenre(genre, page, status, sort) {
return __awaiter(this, void 0, void 0, function* () {
const _page = yield (yield this.browser).newPage();
let path = genre.path;
if (sort !== undefined) {
path += `?sort=${sort}${status !== undefined ? `&status=${status}` : '&status=-1'}${page !== undefined ? `&page=${page}` : ''}`;
}
else if (status !== undefined) {
path += `?status=${status}${page !== undefined ? `&page=${page}` : ''}`;
}
else if (page !== undefined) {
path += `?page=${page}`;
}
const url = `${this.baseUrl}${genre.path}${page !== undefined && page > 1 ? `/page/${page}` : ``}`;
yield _page.setRequestInterception(true);
_page.on('request', (req) => {
if (req.resourceType() !== 'document')
req.abort();
else
req.continue();
});
yield _page.goto(`${this.baseUrl}${path}`);
const element = yield _page.$$('#ctl00_divCenter > div.Module.Module-170 > div > div.items > div > div.item > figure');
yield _page.goto(url);
const paramsSelector = {
puppeteer: _page,
wrapSelector: 'div.listupd > div.bs > div.bsx',
titleSelector: 'a > div.bigor > div.tt',
thumbnailSelector: 'a > div.limit > img',
thumbnailAttr: 'src',
hrefSelector: 'a',
};
const data = yield (0, getListLatest_1.useGetDataItemsManga)(paramsSelector);
const canNext = yield _page
.$eval('#ctl00_mainContent_ctl01_divPager > ul > li > a.next-page', () => true)
.$eval('div.pagination > a.next.page-numbers', () => true)
.catch(() => false);
const canPrev = yield _page
.$eval('#ctl00_mainContent_ctl01_divPager > ul > li > a.prev-page', () => true)
.$eval('div.pagination > a.prev.page-numbers', () => true)
.catch(() => false);
const totalPage = parseInt((0, validate_1.not_null)(yield _page.$eval('#ctl00_mainContent_ctl01_divPager > ul > li:last-child > a', (el) => el.getAttribute('href'))).split('page=')[1]);
const totalPages = yield _page.$$('div.pagination > a.page-numbers:not(.prev):not(.next)');
const totalPage = totalPages !== undefined
? Number(yield totalPages[totalPages.length - 1].evaluate((el) => el.textContent))
: 0;
return {
totalData: element.length,
totalData: data.length,
totalPage,
currentPage: page !== undefined ? page : 1,
canNext,
canPrev,
data: yield Promise.all(element.map((e, i) => __awaiter(this, void 0, void 0, function* () {
const href = (0, validate_1.not_null)(yield e.$eval('div.image > a', (el) => el.getAttribute('href')));
const title = (0, validate_1.not_null)(yield e.$eval('figcaption > h3 > a', (el) => el.textContent));
const image_thumbnail = (0, validate_1.not_null)(yield e.$eval('div.image > a > img', (el) => el.getAttribute('data-original')));
return {
_id: i,
title,
image_thumbnail: image_thumbnail.startsWith('//')
? `https:${image_thumbnail}`
: image_thumbnail,
href,
};
}))),
data,
};
});
}
Expand All @@ -143,13 +123,29 @@ class AsuraScans {
titleSelector: 'div.headpost > h1',
imageSelectorAll: 'div#readerarea > p > img',
originImageAttr: 'src',
prevChapterSelector: '.amob > .npv.r > div.nextprev > a.ch-prev-btn',
nextChapterSelector: '.amob > .npv.r > div.nextprev > a.ch-next-btn',
prevChapterSelector: '.navlef > .npv.r > div.nextprev > a.ch-prev-btn',
nextChapterSelector: '.navlef > .npv.r > div.nextprev > a.ch-next-btn',
baseUrl: this.baseUrl,
url: url_chapter,
};
const data = yield (0, getDataChapter_1.useGetDataChapter)(paramsSelector);
return Object.assign(Object.assign(Object.assign({}, (url !== undefined ? { url } : {})), (path !== undefined ? { path } : {})), data);
const scripts = yield _page.$$('script');
const script = yield scripts[18].evaluate((e) => {
return JSON.parse(e.textContent.split('ts_reader.run(')[1].split(');')[0]);
});
return Object.assign(Object.assign(Object.assign(Object.assign({}, (url !== undefined ? { url } : {})), (path !== undefined ? { path } : {})), data), { next_chapter: script.nextUrl !== ''
? {
url: script.nextUrl,
parent_href: url !== undefined ? url : '',
path: script.nextUrl.substring(`${this.baseUrl}`.length),
}
: null, prev_chapter: script.prevUrl !== ''
? {
url: script.prevUrl,
parent_href: url !== undefined ? url : '',
path: script.prevUrl.substring(`${this.baseUrl}`.length),
}
: null });
});
}
getDetailManga(url) {
Expand Down
1 change: 1 addition & 0 deletions dist/src/utils/validate.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export declare const not_null: (params: string | null | undefined) => string;
export declare const splitString: (str: string, start: string, end: string) => string;
8 changes: 6 additions & 2 deletions dist/src/utils/validate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.not_null = void 0;
exports.splitString = exports.not_null = void 0;
const not_null = (params) => {
return params !== null && params !== undefined ? params : "";
return params !== null && params !== undefined ? params : '';
};
exports.not_null = not_null;
const splitString = (str, start, end) => {
return str.split(start)[1].split(end)[0];
};
exports.splitString = splitString;
4 changes: 2 additions & 2 deletions dist/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("./src");
const t = new src_1.Manga().build(src_1.MangaType.BLOGTRUYEN);
const t = new src_1.Manga().build(src_1.MangaType.ASURASCANS);
void (() => __awaiter(void 0, void 0, void 0, function* () {
console.log(yield t.getListLatestUpdate());
console.log(yield t.getListByGenre({ path: '/genres/action', name: 'action' }));
}))();

0 comments on commit 53ef351

Please sign in to comment.