From 483cbeab974e63269ed6bf2d4c6854eedd03d8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Krasie=C5=84ko?= <73482111+Hayanek@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:57:12 +0100 Subject: [PATCH] Feat: add Plugin Novelki (#813) * Novelki.pl last bug parseChapter. * Finish project :D * Small changes. --------- Co-authored-by: Hayanek --- icons/src/pl/novelki/icon.png | Bin 0 -> 543 bytes libs/languages.ts | 1 + plugins/polish/novelki.ts | 105 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 icons/src/pl/novelki/icon.png create mode 100644 plugins/polish/novelki.ts diff --git a/icons/src/pl/novelki/icon.png b/icons/src/pl/novelki/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3c6346868a184f18b19564b985c2e97015aa2c10 GIT binary patch literal 543 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaMM3p^r=85s1GL71^(seKtxFgd^{#MLLWP>sgmuWPy?&^m>ZAirP+UbbIf z)gHgl|L3#jc4N<0S5d|CgCVg}AJZ?LUNYZu#$V1~u0Xd-db&7%l_kYS_lSTVJG8zAw;b0pyL*(fE$gT2OE$3wxSAF<8b8+kHol}>szc4Li z@5HxjcDP6;sB)&nh96RGc#_1={4kWQVU~GM)yx-ChoqiOmwWhEF_z7w^rLlysLQVW zk9{-Nqr@b-AH|BN`-`{ws!_M{W%3{{4#7#`qOq*K5Z$4wY zQaq`^WdC!v2jP=0Ot&v$?Fy_>(r7;1Z_d!Wb+3?@S>Azg2L5#uy<9jKMCZHAn0Ap@ zu%kUV;`_9>LdiV)FPvuC_f@B3i}UQirWYby`7@$5msCGAF}cxfx3D6^w4!FV)sX`? siln83qL_K?`_z)=UXyh`x { + const body = await fetchApi(`${this.site}/projekty?page=${page}`).then((res) => res.text()); + const loadedCheerio = parseHTML(body); + + const novels: Plugin.NovelItem[] = loadedCheerio("#projects > div") + .map((index, element) => ({ + name: loadedCheerio(element).find(".card-title").attr('title') as string, + cover: this.site+loadedCheerio(element).find(".card-img-top").attr("src"), + path: loadedCheerio(element).find("a").attr("href") || "", + })) + .get() + .filter((novel) => novel.name && novel.path); + return novels; + } + + async parseNovel(novelPath: string): Promise { + const body = await fetchApi(this.site + novelPath).then((r) => r.text()); + const loadedCheerio = parseHTML(body); + + const novel: Plugin.SourceNovel = { + path: novelPath, + name: '' + }; + + loadedCheerio("p.h5").each((i, e) => { + const text = loadedCheerio(e).text().trim() + if(text.includes('Autor:')) novel.author = text.split(':')[1].trim() + if(text.includes("Status projektu:")) novel.status = text.split(':')[1].trim() + + }) + novel.name = loadedCheerio("div").find("h3").text().trim(); + novel.cover = this.site+loadedCheerio(".row").find("img").attr("src"); + + novel.genres = loadedCheerio("span.badge").map((i, e) => loadedCheerio(e).text()).get().join(", ") + + novel.summary = loadedCheerio("p > em").text().trim() + + let chapters: Plugin.ChapterItem[] = []; + + loadedCheerio(".chapters > .col-md-3 > div").get().reverse().forEach((e, i) => { + var pattern = /\/projekty\/([^\/]+)\/([^\/]+)/; + let urlChapters = loadedCheerio(e).find("a").attr("href") || ""; + let codeChapter = pattern.exec(urlChapters) || ""; + + const chapter: Plugin.ChapterItem = { + name: loadedCheerio(e).find("a")?.text().trim(), + path: codeChapter[2], + releaseTime: loadedCheerio(e).find(".card-footer > span").text().trim(), + chapterNumber: i+1, + }; + chapters.push(chapter); + }) + + novel.chapters = chapters; + return novel; + } + async parseChapter(chapterPath: string): Promise { + const body = await fetchApi(`${this.site}/api/reader/chapters/${chapterPath}`).then((res) => res.json()); + + const chapterText = body.data.content + return chapterText; + } + async searchNovels( + searchTerm: string, + page: number + ): Promise { + const body = await fetchApi(`${this.site}/projekty?filter=t&title=${searchTerm}+&page=${page}`).then((res) => res.text()); + const loadedCheerio = parseHTML(body); + + + let novels: Plugin.NovelItem[] = loadedCheerio("#projects > div") + .map((index, element) => ({ + name: loadedCheerio(element).find(".card-title").attr('title') as string, + cover: this.site+loadedCheerio(element).find(".card-img-top").attr("src"), + path: loadedCheerio(element).find("a").attr("href") || "", + })) + .get() + .filter((novel) => novel.name && novel.path) + + return novels; + } + async fetchImage(url: string): Promise { + // if your plugin has images and they won't load + // this is the function to fiddle with + return fetchFile(url); + } +} + +export default new NovelkiPL();