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:
@@ -1,7 +1,6 @@
|
||||
import { load as parseHTML } from 'cheerio';
|
||||
import { fetchFile } from '@libs/fetch';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { Filters } from '@libs/filterInputs';
|
||||
|
||||
class HasulTL implements Plugin.PluginBase {
|
||||
id = 'HasuTL';
|
||||
@@ -10,24 +9,21 @@ class HasulTL implements Plugin.PluginBase {
|
||||
site = 'https://hasutl.wordpress.com/';
|
||||
version = '1.0.0';
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
options: Plugin.PopularNovelsOptions<Filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site + 'light-novels-activas/';
|
||||
async popularNovels(): Promise<Plugin.NovelItem[]> {
|
||||
const url = this.site + 'light-novels-activas/';
|
||||
|
||||
const result = await fetch(url);
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Plugin.NovelItem[] = [];
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio('div.wp-block-columns').each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele).find('.wp-block-button').text();
|
||||
const novelCover = loadedCheerio(ele).find('img').attr('src');
|
||||
|
||||
let novelUrl = loadedCheerio(ele)
|
||||
const novelUrl = loadedCheerio(ele)
|
||||
.find('.wp-block-button > a')
|
||||
.attr('href');
|
||||
|
||||
@@ -46,21 +42,21 @@ class HasulTL implements Plugin.PluginBase {
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const url = this.site + novelPath;
|
||||
|
||||
const result = await fetch(url);
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novel: Plugin.SourceNovel = {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: loadedCheerio('.post-header').text(),
|
||||
};
|
||||
novel.cover = loadedCheerio('.featured-media > img').attr('src');
|
||||
|
||||
let novelSummary = loadedCheerio('.post-content').find('p').html()!;
|
||||
const novelSummary = loadedCheerio('.post-content').find('p').html()!;
|
||||
novel.summary = novelSummary;
|
||||
|
||||
let novelChapters: Plugin.ChapterItem[] = [];
|
||||
const novelChapters: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio('.wp-block-media-text__content')
|
||||
.find('a')
|
||||
@@ -69,7 +65,7 @@ class HasulTL implements Plugin.PluginBase {
|
||||
|
||||
const releaseDate = null;
|
||||
|
||||
let chapterUrl = loadedCheerio(ele).attr('href');
|
||||
const chapterUrl = loadedCheerio(ele).attr('href');
|
||||
|
||||
if (!chapterUrl) return;
|
||||
|
||||
@@ -89,27 +85,24 @@ class HasulTL implements Plugin.PluginBase {
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const url = this.site + chapterPath;
|
||||
|
||||
const result = await fetch(url);
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let chapterText = loadedCheerio('.post-content').html() || '';
|
||||
const chapterText = loadedCheerio('.post-content').html() || '';
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
|
||||
const url = `${this.site}?s=${searchTerm}&post_type=wp-manga`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const result = await fetchApi(url);
|
||||
const body = await result.text();
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
let novels: Plugin.NovelItem[] = [];
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio('.post-container').each((idx, ele) => {
|
||||
const novelName = loadedCheerio(ele).find('.post-header').text();
|
||||
@@ -120,7 +113,7 @@ class HasulTL implements Plugin.PluginBase {
|
||||
) {
|
||||
const novelCover = loadedCheerio(ele).find('img').attr('src');
|
||||
|
||||
let novelUrl = loadedCheerio(ele).find('a').attr('href');
|
||||
const novelUrl = loadedCheerio(ele).find('a').attr('href');
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user