Skip to content

Commit

Permalink
[toonily] get data chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
zcrossoverz committed Jun 8, 2023
1 parent 0e8886e commit 7fba576
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
67 changes: 65 additions & 2 deletions src/lib/toonily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AbstractMangaFactory,
chapter,
genre,
image_chapter,
responseChapter,
responseDetailManga,
responseListManga,
Expand Down Expand Up @@ -149,14 +150,76 @@ export class Toonily implements AbstractMangaFactory {
chapters,
};
}
getDataChapter(
async getDataChapter(
url_chapter: string,
url?: string | undefined,
path?: string | undefined,
prev_chapter?: chapter | undefined,
next_chapter?: chapter | undefined
): Promise<responseChapter> {
throw new Error("Method not implemented.");
const $ = cheerio.load((await axios.get(url_chapter)).data);

const site_content = $("div.main-col-inner");
const title = site_content
.find("ol.breadcrumb > li:nth-child(3)")
.text()
.trim();

const chapter_data: image_chapter[] = [] as image_chapter[];
site_content
.find("div.entry-content div.reading-content > div.page-break > img")
.each((i, e) => {
chapter_data.push({
_id: i,
src_origin: $(e).attr("data-src")!.trim(),
alt: $(e).attr("alt")!,
});
});

const parent_href = site_content
.find("ol.breadcrumb > li:nth-child(3) > a")
.attr("href")!;

const next_chapter_data: chapter | null = site_content.find(
"div.nav-links > div.nav-next > a"
).length
? {
url: site_content
.find("div.nav-links > div.nav-next > a")
.attr("href")!,
path: site_content
.find("div.nav-links > div.nav-next > a")
.attr("href")!
.substring(this.baseUrl.length),
parent_href: parent_href,
title,
}
: null;

const prev_chapter_data: chapter | null = site_content.find(
"div.nav-links > div.nav-previous > a"
).length
? {
url: site_content
.find("div.nav-links > div.nav-previous > a")
.attr("href")!,
path: site_content
.find("div.nav-links > div.nav-previous > a")
.attr("href")!
.substring(this.baseUrl.length),
parent_href: parent_href,
title,
}
: null;

return {
url: url_chapter,
path: url_chapter.substring(this.baseUrl.length),
title,
chapter_data,
prev_chapter: prev_chapter !== undefined ? null : prev_chapter_data,
next_chapter: next_chapter !== undefined ? null : next_chapter_data,
};
}
getListByGenre(
genre: genre,
Expand Down
4 changes: 3 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const t = new Manga().build(MangaType.TOONILY);

void (async () => {
console.log(
await t.getDetailManga("https://toonily.com/webtoon/writer-sungs-life/")
await t.getDataChapter(
"https://toonily.com/webtoon/writer-sungs-life/chapter-8/"
)
);
})();

0 comments on commit 7fba576

Please sign in to comment.