Fix: Novelki Date, Status, Summary, Error (#817)

* Fix Date, Status, Summary

* Add show error

---------

Co-authored-by: Hayanek <kontakt@wolfek.xyz>
This commit is contained in:
Cezary Krasieńko
2024-03-03 04:11:23 +01:00
committed by GitHub
parent 483cbeab97
commit e10e69f90a
2 changed files with 32 additions and 7 deletions
+1 -1
View File
@@ -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);
}
+30 -5
View File
@@ -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[] = [];
@@ -61,7 +86,7 @@ class NovelkiPL implements Plugin.PluginBase {
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);