Add TopLiba (#1003)

* test

* cleanup

deleted unused `fetchFile` import
replaced fetch with `fetchApi`

* eslint

* fix

* fix multi

* Hmm, what to do next.

* test URLSearchParams

* fix
This commit is contained in:
Rider21
2024-06-30 07:28:11 +03:00
committed by GitHub
parent 938e3b16a3
commit fae73534dd
121 changed files with 10534 additions and 8079 deletions
+18 -15
View File
@@ -1,5 +1,5 @@
import { load, load as loadCheerio } from 'cheerio';
import { fetchApi, fetchFile } from '@libs/fetch';
import { load as loadCheerio } from 'cheerio';
import { fetchApi } from '@libs/fetch';
import { Plugin } from '@typings/plugin';
import { defaultCover } from '@libs/defaultCover';
import { FilterTypes, Filters } from '@libs/filterInputs';
@@ -20,7 +20,7 @@ class Syosetu implements Plugin.PluginBase {
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
};
searchUrl = (pagenum?: number, order?: string) => {
return `https://yomou.syosetu.com/search.php?order=${order || 'hyoka'}${
return `${this.site}search.php?order=${order || 'hyoka'}${
pagenum !== undefined
? `&p=${pagenum <= 1 || pagenum > 100 ? '1' : pagenum}` // check if pagenum is between 1 and 100
: '' // if isn't don't set ?p
@@ -71,15 +71,15 @@ class Syosetu implements Plugin.PluginBase {
return novels;
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
let chapters: Plugin.ChapterItem[] = [];
const result = await fetch(this.novelPrefix + novelPath, {
const chapters: Plugin.ChapterItem[] = [];
const result = await fetchApi(this.novelPrefix + novelPath, {
headers: this.headers,
});
const body = await result.text();
const loadedCheerio = loadCheerio(body, { decodeEntities: false });
// create novel object
let novel: Plugin.SourceNovel = {
const novel: Plugin.SourceNovel = {
path: novelPath,
name: loadedCheerio('.novel_title').text(),
author: loadedCheerio('.novel_writername').text().replace('作者:', ''),
@@ -93,7 +93,7 @@ class Syosetu implements Plugin.PluginBase {
novel.summary = loadedCheerio('#novel_ex')
.text()
.replace(/<\s*br.*?>/g, '\n');
cqGetChapters.each(function (i, e) {
cqGetChapters.each(() => {
const chapterA = loadedCheerio(this).find('a');
const [chapterName, releaseDate, chapterUrl] = [
// set the variables
@@ -121,9 +121,12 @@ class Syosetu implements Plugin.PluginBase {
*/
// get summary for oneshot chapter
const nameResult = await fetch(this.searchUrl() + `&word=${novel.name}`, {
headers: this.headers,
});
const nameResult = await fetchApi(
this.searchUrl() + `&word=${novel.name}`,
{
headers: this.headers,
},
);
const nameBody = await nameResult.text();
const summaryQuery = loadCheerio(nameBody, {
decodeEntities: false,
@@ -148,7 +151,7 @@ class Syosetu implements Plugin.PluginBase {
return novel;
}
async parseChapter(chapterPath: string): Promise<string> {
const result = await fetch(this.novelPrefix + chapterPath, {
const result = await fetchApi(this.novelPrefix + chapterPath, {
headers: this.headers,
});
const body = await result.text();
@@ -158,7 +161,7 @@ class Syosetu implements Plugin.PluginBase {
decodeEntities: false,
});
let chapterText =
const chapterText =
cheerioQuery('#novel_honbun') // get chapter text
.html() || '';
return chapterText;
@@ -173,12 +176,12 @@ class Syosetu implements Plugin.PluginBase {
const getNovelsFromPage = async (pagenumber: number) => {
// load page
const url = this.searchUrl(pagenumber) + `&word=${searchTerm}`;
const result = await fetch(url, { headers: this.headers });
const result = await fetchApi(url, { headers: this.headers });
const body = await result.text();
// Cheerio it!
const cheerioQuery = loadCheerio(body, { decodeEntities: false });
let pageNovels: Plugin.NovelItem[] = [];
const pageNovels: Plugin.NovelItem[] = [];
// find class=searchkekka_box
cheerioQuery('.searchkekka_box').each((i, e) => {
// get div with link and name
@@ -218,7 +221,7 @@ class Syosetu implements Plugin.PluginBase {
return novels;
}
resolveUrl(path: string, isNovel?: boolean | undefined): string {
resolveUrl(path: string): string {
return this.novelPrefix + path;
}
filters = {