From e10e69f90a362bd0589eb8122f5f18d8f3966255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Krasie=C5=84ko?= <73482111+Hayanek@users.noreply.github.com> Date: Sun, 3 Mar 2024 04:11:23 +0100 Subject: [PATCH] Fix: Novelki Date, Status, Summary, Error (#817) * Fix Date, Status, Summary * Add show error --------- Co-authored-by: Hayanek --- libs/fetch.ts | 2 +- plugins/polish/novelki.ts | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/libs/fetch.ts b/libs/fetch.ts index 55480a4..2fbbd10 100644 --- a/libs/fetch.ts +++ b/libs/fetch.ts @@ -57,7 +57,7 @@ const makeInit = async (init?: FetchInit) => { export async function fetchApi(url: string, init?: FetchInit) { init = await makeInit(init); // console.log(init.headers); - console.log(url, init); + // console.log(url, init); return await fetch(url, init as RequestInit); } diff --git a/plugins/polish/novelki.ts b/plugins/polish/novelki.ts index 7218c41..bcc3a6c 100644 --- a/plugins/polish/novelki.ts +++ b/plugins/polish/novelki.ts @@ -2,13 +2,14 @@ import { fetchApi, fetchFile } from "@libs/fetch"; import { Plugin } from "@typings/plugin"; import { Filters } from "@libs/filterInputs"; import { load as parseHTML } from "cheerio"; +import { NovelStatus } from "@libs/novelStatus"; class NovelkiPL implements Plugin.PluginBase { id = "novelki.pl"; name = "Novelki"; icon = "src/pl/novelki/icon.png"; site = "https://novelki.pl"; - version = "1.0.1"; + version = "1.0.2"; filters: Filters | undefined = undefined; async popularNovels( @@ -18,7 +19,10 @@ class NovelkiPL implements Plugin.PluginBase { const body = await fetchApi(`${this.site}/projekty?page=${page}`).then((res) => res.text()); const loadedCheerio = parseHTML(body); - const novels: Plugin.NovelItem[] = loadedCheerio("#projects > div") + const load = loadedCheerio("#projects > div") + if(load.length == 0) throw new Error("Failed to load page (open in web view and login)"); + + const novels: Plugin.NovelItem[] = load .map((index, element) => ({ name: loadedCheerio(element).find(".card-title").attr('title') as string, cover: this.site+loadedCheerio(element).find(".card-img-top").attr("src"), @@ -41,7 +45,28 @@ class NovelkiPL implements Plugin.PluginBase { 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() + if(text.includes("Status projektu:")) { + switch (`${text.split(':')[1].trim()}`.toLowerCase()) { + case "wstrzymany": + novel.status = NovelStatus.OnHiatus; + break; + case "zakończony": + novel.status = NovelStatus.Completed; + break; + case "aktywny": + novel.status = NovelStatus.Ongoing; + break; + case "porzucony": + novel.status = NovelStatus.Cancelled; + break; + case "zlicencjonowany": + novel.status = NovelStatus.Licensed; + break; + default: + novel.status = NovelStatus.Unknown; + break; + } + } }) novel.name = loadedCheerio("div").find("h3").text().trim(); @@ -49,7 +74,7 @@ class NovelkiPL implements Plugin.PluginBase { novel.genres = loadedCheerio("span.badge").map((i, e) => loadedCheerio(e).text()).get().join(", ") - novel.summary = loadedCheerio("p > em").text().trim() + novel.summary = loadedCheerio('.h5:contains("Opis:")').next("p").next("p").text().trim() let chapters: Plugin.ChapterItem[] = []; @@ -57,11 +82,11 @@ class NovelkiPL implements Plugin.PluginBase { 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(), + releaseTime: loadedCheerio(e).find(".card-footer > span").text().trim().split('-').reverse().join('-'), chapterNumber: i+1, }; chapters.push(chapter);