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:
+1
-1
@@ -57,7 +57,7 @@ const makeInit = async (init?: FetchInit) => {
|
|||||||
export async function fetchApi(url: string, init?: FetchInit) {
|
export async function fetchApi(url: string, init?: FetchInit) {
|
||||||
init = await makeInit(init);
|
init = await makeInit(init);
|
||||||
// console.log(init.headers);
|
// console.log(init.headers);
|
||||||
console.log(url, init);
|
// console.log(url, init);
|
||||||
return await fetch(url, init as RequestInit);
|
return await fetch(url, init as RequestInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ import { fetchApi, fetchFile } from "@libs/fetch";
|
|||||||
import { Plugin } from "@typings/plugin";
|
import { Plugin } from "@typings/plugin";
|
||||||
import { Filters } from "@libs/filterInputs";
|
import { Filters } from "@libs/filterInputs";
|
||||||
import { load as parseHTML } from "cheerio";
|
import { load as parseHTML } from "cheerio";
|
||||||
|
import { NovelStatus } from "@libs/novelStatus";
|
||||||
|
|
||||||
class NovelkiPL implements Plugin.PluginBase {
|
class NovelkiPL implements Plugin.PluginBase {
|
||||||
id = "novelki.pl";
|
id = "novelki.pl";
|
||||||
name = "Novelki";
|
name = "Novelki";
|
||||||
icon = "src/pl/novelki/icon.png";
|
icon = "src/pl/novelki/icon.png";
|
||||||
site = "https://novelki.pl";
|
site = "https://novelki.pl";
|
||||||
version = "1.0.1";
|
version = "1.0.2";
|
||||||
filters: Filters | undefined = undefined;
|
filters: Filters | undefined = undefined;
|
||||||
|
|
||||||
async popularNovels(
|
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 body = await fetchApi(`${this.site}/projekty?page=${page}`).then((res) => res.text());
|
||||||
const loadedCheerio = parseHTML(body);
|
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) => ({
|
.map((index, element) => ({
|
||||||
name: loadedCheerio(element).find(".card-title").attr('title') as string,
|
name: loadedCheerio(element).find(".card-title").attr('title') as string,
|
||||||
cover: this.site+loadedCheerio(element).find(".card-img-top").attr("src"),
|
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) => {
|
loadedCheerio("p.h5").each((i, e) => {
|
||||||
const text = loadedCheerio(e).text().trim()
|
const text = loadedCheerio(e).text().trim()
|
||||||
if(text.includes('Autor:')) novel.author = text.split(':')[1].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();
|
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.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[] = [];
|
let chapters: Plugin.ChapterItem[] = [];
|
||||||
|
|
||||||
@@ -57,11 +82,11 @@ class NovelkiPL implements Plugin.PluginBase {
|
|||||||
var pattern = /\/projekty\/([^\/]+)\/([^\/]+)/;
|
var pattern = /\/projekty\/([^\/]+)\/([^\/]+)/;
|
||||||
let urlChapters = loadedCheerio(e).find("a").attr("href") || "";
|
let urlChapters = loadedCheerio(e).find("a").attr("href") || "";
|
||||||
let codeChapter = pattern.exec(urlChapters) || "";
|
let codeChapter = pattern.exec(urlChapters) || "";
|
||||||
|
|
||||||
const chapter: Plugin.ChapterItem = {
|
const chapter: Plugin.ChapterItem = {
|
||||||
name: loadedCheerio(e).find("a")?.text().trim(),
|
name: loadedCheerio(e).find("a")?.text().trim(),
|
||||||
path: codeChapter[2],
|
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,
|
chapterNumber: i+1,
|
||||||
};
|
};
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
|
|||||||
Reference in New Issue
Block a user