Fix: lightnovelpub + lightnovelworld replaced ; with + (#818)

* replaced ; with +

* changed version
This commit is contained in:
Patrick Loser
2024-03-03 04:12:20 +01:00
committed by GitHub
parent e10e69f90a
commit aa129fdfed
2 changed files with 66 additions and 64 deletions
+33 -32
View File
@@ -7,7 +7,7 @@ import dayjs from "dayjs";
class LightNovelPub implements Plugin.PagePlugin { class LightNovelPub implements Plugin.PagePlugin {
id = "lightnovelpub"; id = "lightnovelpub";
name = "LightNovelPub"; name = "LightNovelPub";
version = "1.0.0"; version = "1.0.1";
icon = "src/en/lightnovelpub/icon.png"; icon = "src/en/lightnovelpub/icon.png";
site = "https://www.lightnovelpub.com/"; site = "https://www.lightnovelpub.com/";
headers = { headers = {
@@ -16,7 +16,7 @@ class LightNovelPub implements Plugin.PagePlugin {
}; };
async popularNovels( async popularNovels(
page: number, page: number,
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters> { filters }: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
let link = `${this.site}browse/`; let link = `${this.site}browse/`;
@@ -26,13 +26,13 @@ class LightNovelPub implements Plugin.PagePlugin {
link += page; link += page;
const body = await fetchApi(link).then((r) => r.text()); const body = await fetchApi(link).then((r) => r.text());
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = []; const novels: Plugin.NovelItem[] = [];
loadedCheerio(".novel-item.ads").remove(); loadedCheerio(".novel-item.ads").remove();
loadedCheerio(".novel-item").each((idx, ele) => { loadedCheerio(".novel-item").each((idx, ele) => {
const novelName = loadedCheerio(ele) const novelName = loadedCheerio(ele)
.find(".novel-title") .find(".novel-title")
@@ -44,39 +44,39 @@ class LightNovelPub implements Plugin.PagePlugin {
.find(".novel-title > a") .find(".novel-title > a")
.attr("href") .attr("href")
?.substring(1); ?.substring(1);
if (!novelUrl) return; if (!novelUrl) return;
const novel = { const novel = {
name: novelName, name: novelName,
cover: novelCover, cover: novelCover,
path: novelUrl, path: novelUrl,
}; };
novels.push(novel); novels.push(novel);
}); });
return novels; return novels;
} }
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel & {totalPages: number}> { async parseNovel(novelPath: string): Promise<Plugin.SourceNovel & { totalPages: number }> {
const body = await fetchApi(this.site + novelPath).then((r) => r.text()); const body = await fetchApi(this.site + novelPath).then((r) => r.text());
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);
const totalChapters = parseInt(loadedCheerio(".header-stats span:first strong").text(), 10); const totalChapters = parseInt(loadedCheerio(".header-stats span:first strong").text(), 10);
const novel: Plugin.SourceNovel & {totalPages: number}= { const novel: Plugin.SourceNovel & { totalPages: number } = {
path: novelPath, path: novelPath,
name: loadedCheerio("h1.novel-title").text().trim() || "Untitled", name: loadedCheerio("h1.novel-title").text().trim() || "Untitled",
cover: loadedCheerio("figure.cover > img").attr("data-src"), cover: loadedCheerio("figure.cover > img").attr("data-src"),
author: loadedCheerio(".author > a > span").text(), author: loadedCheerio(".author > a > span").text(),
summary: loadedCheerio(".summary > .content").text().trim(), summary: loadedCheerio(".summary > .content").text().trim(),
status: loadedCheerio(".header-stats span:last strong").text(), status: loadedCheerio(".header-stats span:last strong").text(),
totalPages: Math.ceil(totalChapters/100), totalPages: Math.ceil(totalChapters / 100),
chapters: [], chapters: [],
}; };
novel.genres = loadedCheerio('.categories ul li') novel.genres = loadedCheerio('.categories ul li')
.map((a,ex) => loadedCheerio(ex).text().trim()) .map((a, ex) => loadedCheerio(ex).text().trim())
.toArray() .toArray()
.join(','); .join(',');
@@ -90,15 +90,15 @@ class LightNovelPub implements Plugin.PagePlugin {
const chapter: Plugin.ChapterItem[] = []; const chapter: Plugin.ChapterItem[] = [];
loadedCheerio('.chapter-list li').each(function () { loadedCheerio('.chapter-list li').each(function () {
const chapterName = const chapterName =
'Chapter ' + 'Chapter ' +
loadedCheerio(this).find('.chapter-no').text().trim() + loadedCheerio(this).find('.chapter-no').text().trim() +
' - '; ' - ' +
loadedCheerio(this).find('.chapter-title').text().trim(); loadedCheerio(this).find('.chapter-title').text().trim();
const releaseDate = loadedCheerio(this) const releaseDate = loadedCheerio(this)
.find('.chapter-update') .find('.chapter-update')
.attr('datetime'); .attr('datetime');
const chapterUrl = loadedCheerio(this).find('a').attr('href')?.substring(1); const chapterUrl = loadedCheerio(this).find('a').attr('href')?.substring(1);
if (!chapterUrl) return; if (!chapterUrl) return;
@@ -106,9 +106,10 @@ class LightNovelPub implements Plugin.PagePlugin {
name: chapterName, name: chapterName,
path: chapterUrl, path: chapterUrl,
releaseTime: dayjs(releaseDate).toISOString(), releaseTime: dayjs(releaseDate).toISOString(),
})}); })
});
const chapters = chapter; const chapters = chapter;
return {chapters}; return { chapters };
} }
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
@@ -127,10 +128,10 @@ class LightNovelPub implements Plugin.PagePlugin {
const response = await fetchApi(link).then((r) => r.text()); const response = await fetchApi(link).then((r) => r.text());
const token = parseHTML(response); const token = parseHTML(response);
let verifytoken = token("#novelSearchForm > input").attr("value"); let verifytoken = token("#novelSearchForm > input").attr("value");
let formData = new FormData(); let formData = new FormData();
formData.append("inputContent", searchTerm); formData.append("inputContent", searchTerm);
const body = await fetchApi( const body = await fetchApi(
url, url,
{ {
@@ -139,15 +140,15 @@ class LightNovelPub implements Plugin.PagePlugin {
body: formData, body: formData,
}, },
).then((r) => r.text()); ).then((r) => r.text());
let loadedCheerio = parseHTML(body); let loadedCheerio = parseHTML(body);
let novels: Plugin.NovelItem[] = []; let novels: Plugin.NovelItem[] = [];
let results = JSON.parse(loadedCheerio("body").text()); let results = JSON.parse(loadedCheerio("body").text());
loadedCheerio = parseHTML(results.resultview); loadedCheerio = parseHTML(results.resultview);
loadedCheerio(".novel-item").each((idx, ele) => { loadedCheerio(".novel-item").each((idx, ele) => {
const novelName = loadedCheerio(ele) const novelName = loadedCheerio(ele)
.find("h4.novel-title") .find("h4.novel-title")
@@ -162,12 +163,12 @@ class LightNovelPub implements Plugin.PagePlugin {
cover: novelCover, cover: novelCover,
}); });
}); });
return novels; return novels;
} }
async fetchImage(url: string): Promise<string | undefined> { async fetchImage(url: string): Promise<string | undefined> {
return fetchFile(url, {headers: this.headers}); return fetchFile(url, { headers: this.headers });
} }
filters = { filters = {
+33 -32
View File
@@ -8,7 +8,7 @@ class LightNovelWorld implements Plugin.PagePlugin {
id = "lightnovelworld"; id = "lightnovelworld";
name = "LightNovelWorld"; name = "LightNovelWorld";
site = "https://www.webnovelworld.org/"; site = "https://www.webnovelworld.org/";
version = "1.0.0"; version = "1.0.1";
icon = "src/en/lightnovelworld/icon.png"; icon = "src/en/lightnovelworld/icon.png";
headers = { headers = {
Accept: "application/json", Accept: "application/json",
@@ -16,7 +16,7 @@ class LightNovelWorld implements Plugin.PagePlugin {
}; };
async popularNovels( async popularNovels(
page: number, page: number,
{ filters }: Plugin.PopularNovelsOptions<typeof this.filters> { filters }: Plugin.PopularNovelsOptions<typeof this.filters>
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
let link = `${this.site}browse/`; let link = `${this.site}browse/`;
@@ -26,13 +26,13 @@ class LightNovelWorld implements Plugin.PagePlugin {
link += page; link += page;
const body = await fetchApi(link).then((r) => r.text()); const body = await fetchApi(link).then((r) => r.text());
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);
const novels: Plugin.NovelItem[] = []; const novels: Plugin.NovelItem[] = [];
loadedCheerio(".novel-item.ads").remove(); loadedCheerio(".novel-item.ads").remove();
loadedCheerio(".novel-item").each((idx, ele) => { loadedCheerio(".novel-item").each((idx, ele) => {
const novelName = loadedCheerio(ele) const novelName = loadedCheerio(ele)
.find(".novel-title") .find(".novel-title")
@@ -44,39 +44,39 @@ class LightNovelWorld implements Plugin.PagePlugin {
.find(".novel-title > a") .find(".novel-title > a")
.attr("href") .attr("href")
?.substring(1); ?.substring(1);
if (!novelUrl) return; if (!novelUrl) return;
const novel = { const novel = {
name: novelName, name: novelName,
cover: novelCover, cover: novelCover,
path: novelUrl, path: novelUrl,
}; };
novels.push(novel); novels.push(novel);
}); });
return novels; return novels;
} }
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel & {totalPages: number}> { async parseNovel(novelPath: string): Promise<Plugin.SourceNovel & { totalPages: number }> {
const body = await fetchApi(this.site + novelPath).then((r) => r.text()); const body = await fetchApi(this.site + novelPath).then((r) => r.text());
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);
const totalChapters = parseInt(loadedCheerio(".header-stats span:first strong").text(), 10); const totalChapters = parseInt(loadedCheerio(".header-stats span:first strong").text(), 10);
const novel: Plugin.SourceNovel & {totalPages: number}= { const novel: Plugin.SourceNovel & { totalPages: number } = {
path: novelPath, path: novelPath,
name: loadedCheerio("h1.novel-title").text().trim() || "Untitled", name: loadedCheerio("h1.novel-title").text().trim() || "Untitled",
cover: loadedCheerio("figure.cover > img").attr("data-src"), cover: loadedCheerio("figure.cover > img").attr("data-src"),
author: loadedCheerio(".author > a > span").text(), author: loadedCheerio(".author > a > span").text(),
summary: loadedCheerio(".summary > .content").text().trim(), summary: loadedCheerio(".summary > .content").text().trim(),
status: loadedCheerio(".header-stats span:last strong").text(), status: loadedCheerio(".header-stats span:last strong").text(),
totalPages: Math.ceil(totalChapters/100), totalPages: Math.ceil(totalChapters / 100),
chapters: [], chapters: [],
}; };
novel.genres = loadedCheerio('.categories ul li') novel.genres = loadedCheerio('.categories ul li')
.map((a,ex) => loadedCheerio(ex).text().trim()) .map((a, ex) => loadedCheerio(ex).text().trim())
.toArray() .toArray()
.join(','); .join(',');
@@ -90,15 +90,15 @@ class LightNovelWorld implements Plugin.PagePlugin {
const chapter: Plugin.ChapterItem[] = []; const chapter: Plugin.ChapterItem[] = [];
loadedCheerio('.chapter-list li').each(function () { loadedCheerio('.chapter-list li').each(function () {
const chapterName = const chapterName =
'Chapter ' + 'Chapter ' +
loadedCheerio(this).find('.chapter-no').text().trim() + loadedCheerio(this).find('.chapter-no').text().trim() +
' - '; ' - ' +
loadedCheerio(this).find('.chapter-title').text().trim(); loadedCheerio(this).find('.chapter-title').text().trim();
const releaseDate = loadedCheerio(this) const releaseDate = loadedCheerio(this)
.find('.chapter-update') .find('.chapter-update')
.attr('datetime'); .attr('datetime');
const chapterUrl = loadedCheerio(this).find('a').attr('href')?.substring(1); const chapterUrl = loadedCheerio(this).find('a').attr('href')?.substring(1);
if (!chapterUrl) return; if (!chapterUrl) return;
@@ -106,9 +106,10 @@ class LightNovelWorld implements Plugin.PagePlugin {
name: chapterName, name: chapterName,
path: chapterUrl, path: chapterUrl,
releaseTime: dayjs(releaseDate).toISOString(), releaseTime: dayjs(releaseDate).toISOString(),
})}); })
});
const chapters = chapter; const chapters = chapter;
return {chapters}; return { chapters };
} }
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
@@ -127,10 +128,10 @@ class LightNovelWorld implements Plugin.PagePlugin {
const response = await fetchApi(link).then((r) => r.text()); const response = await fetchApi(link).then((r) => r.text());
const token = parseHTML(response); const token = parseHTML(response);
let verifytoken = token("#novelSearchForm > input").attr("value"); let verifytoken = token("#novelSearchForm > input").attr("value");
let formData = new FormData(); let formData = new FormData();
formData.append("inputContent", searchTerm); formData.append("inputContent", searchTerm);
const body = await fetchApi( const body = await fetchApi(
url, url,
{ {
@@ -139,15 +140,15 @@ class LightNovelWorld implements Plugin.PagePlugin {
body: formData, body: formData,
}, },
).then((r) => r.text()); ).then((r) => r.text());
let loadedCheerio = parseHTML(body); let loadedCheerio = parseHTML(body);
let novels: Plugin.NovelItem[] = []; let novels: Plugin.NovelItem[] = [];
let results = JSON.parse(loadedCheerio("body").text()); let results = JSON.parse(loadedCheerio("body").text());
loadedCheerio = parseHTML(results.resultview); loadedCheerio = parseHTML(results.resultview);
loadedCheerio(".novel-item").each((idx, ele) => { loadedCheerio(".novel-item").each((idx, ele) => {
const novelName = loadedCheerio(ele) const novelName = loadedCheerio(ele)
.find("h4.novel-title") .find("h4.novel-title")
@@ -162,12 +163,12 @@ class LightNovelWorld implements Plugin.PagePlugin {
cover: novelCover, cover: novelCover,
}); });
}); });
return novels; return novels;
} }
async fetchImage(url: string): Promise<string | undefined> { async fetchImage(url: string): Promise<string | undefined> {
return fetchFile(url, {headers: this.headers}); return fetchFile(url, { headers: this.headers });
} }
filters = { filters = {