d96843da3b
* fix: novel hall search * bump novel hall version * fix: storyseeding * bumps StorySeedling version * fix: ltnovel, fans mtl, fannovel domain * fix: types * added wuxiaV
135 lines
3.7 KiB
TypeScript
135 lines
3.7 KiB
TypeScript
import { load, load as parseHTML } from 'cheerio';
|
||
import { fetchApi, fetchFile } from '@libs/fetch';
|
||
import { Plugin } from '@typings/plugin';
|
||
import { Filters } from '@libs/filterInputs';
|
||
import { defaultCover } from '@libs/defaultCover';
|
||
|
||
class NovelHall implements Plugin.PluginBase {
|
||
id = 'novelhall';
|
||
name = 'Novel Hall';
|
||
version = '1.0.1';
|
||
icon = 'src/en/novelhall/icon.png';
|
||
filters?: Filters | undefined; //TODO: Filters Requires hideOnSelect
|
||
site = 'https://novelhall.com/';
|
||
|
||
async popularNovels(
|
||
page: number,
|
||
options: Plugin.PopularNovelsOptions<Filters>,
|
||
): Promise<Plugin.NovelItem[]> {
|
||
const url = `${this.site}all2022-${page}.html`;
|
||
|
||
const body = await fetchApi(url).then(r => r.text());
|
||
|
||
const loadedCheerio = parseHTML(body);
|
||
|
||
const novels: Plugin.NovelItem[] = [];
|
||
|
||
loadedCheerio('li.btm').each((idx, ele) => {
|
||
const novelName = loadedCheerio(ele).text().trim();
|
||
const novelUrl = loadedCheerio(ele).find('a').attr('href');
|
||
if (!novelUrl) return;
|
||
|
||
const novel = {
|
||
name: novelName,
|
||
cover: defaultCover,
|
||
path: novelUrl,
|
||
};
|
||
|
||
novels.push(novel);
|
||
});
|
||
|
||
return novels;
|
||
}
|
||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||
const body = await fetchApi(this.site + novelPath).then(r => r.text());
|
||
|
||
const loadedCheerio = parseHTML(body);
|
||
|
||
const novel: Plugin.SourceNovel = {
|
||
path: novelPath,
|
||
name: loadedCheerio('.book-info > h1').text() || 'Untitled',
|
||
cover: loadedCheerio('meta[property="og:image"]').attr('content'),
|
||
summary: loadedCheerio('.intro').text().trim(),
|
||
chapters: [],
|
||
};
|
||
|
||
loadedCheerio('.total').find('p').remove();
|
||
novel.author = loadedCheerio('.total span:contains("Author")')
|
||
.text()
|
||
.replace('Author:', '')
|
||
.trim();
|
||
|
||
novel.status = loadedCheerio('.total span:contains("Status")')
|
||
.text()
|
||
.replace('Status:', '')
|
||
.replace('Active', 'Ongoing')
|
||
.trim();
|
||
|
||
novel.genres = loadedCheerio('.total a')
|
||
.map((a, ex) => loadedCheerio(ex).text())
|
||
.toArray()
|
||
.join(',');
|
||
|
||
const chapter: Plugin.ChapterItem[] = [];
|
||
|
||
loadedCheerio('#morelist ul > li').each((idx, ele) => {
|
||
const chapterName = loadedCheerio(ele).find('a').text().trim();
|
||
const chapterUrl = loadedCheerio(ele).find('a').attr('href');
|
||
if (!chapterUrl) return;
|
||
|
||
chapter.push({
|
||
name: chapterName,
|
||
path: chapterUrl,
|
||
});
|
||
});
|
||
|
||
novel.chapters = chapter;
|
||
return novel;
|
||
}
|
||
|
||
async parseChapter(chapterPath: string): Promise<string> {
|
||
const body = await fetchApi(this.site + chapterPath).then(r => r.text());
|
||
const loadedCheerio = parseHTML(body);
|
||
const chapterText = loadedCheerio('.content').html() || '';
|
||
return chapterText;
|
||
}
|
||
|
||
async searchNovels(
|
||
searchTerm: string,
|
||
pageNo: number,
|
||
): Promise<Plugin.NovelItem[]> {
|
||
const url = `${this.site}index.php?s=so&module=book&keyword=${searchTerm}`;
|
||
const body = await fetchApi(url).then(r => r.text());
|
||
const loadedCheerio = parseHTML(body);
|
||
|
||
const novels: Plugin.NovelItem[] = [];
|
||
|
||
loadedCheerio('table tr').each((idx, ele) => {
|
||
const novelName = loadedCheerio(ele)
|
||
.find('td:nth-child(2)')
|
||
.text()
|
||
.replace(/\t+/g, '')
|
||
.replace(/\n/g, ' ');
|
||
const novelUrl = loadedCheerio(ele)
|
||
.find('td:nth-child(2) a')
|
||
.attr('href');
|
||
if (!novelUrl) return;
|
||
|
||
const novel = {
|
||
name: novelName,
|
||
cover: defaultCover,
|
||
path: novelUrl,
|
||
};
|
||
|
||
novels.push(novel);
|
||
});
|
||
|
||
return novels;
|
||
}
|
||
async fetchImage(url: string): Promise<string | undefined> {
|
||
return fetchFile(url);
|
||
}
|
||
}
|
||
|
||
export default new NovelHall();
|