add allnovel and lightnovelplus (#1485)
* add allnovel and lightnovelplus * different sites treat pages differently :madge:
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { CheerioAPI, load as parseHTML, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
@@ -6,13 +6,17 @@ import { NovelStatus } from '@libs/novelStatus';
|
||||
type ReadNovelFullOptions = {
|
||||
lang?: string;
|
||||
versionIncrements?: number;
|
||||
popularPage: string;
|
||||
latestPage: string;
|
||||
searchPage: string;
|
||||
ajaxChapterList?: boolean;
|
||||
};
|
||||
|
||||
export type ReadNovelFullMetadata = {
|
||||
id: string;
|
||||
sourceSite: string;
|
||||
sourceName: string;
|
||||
options?: ReadNovelFullOptions;
|
||||
options: ReadNovelFullOptions;
|
||||
filters?: any;
|
||||
};
|
||||
|
||||
@@ -22,7 +26,7 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
icon: string;
|
||||
site: string;
|
||||
version: string;
|
||||
options?: ReadNovelFullOptions;
|
||||
options: ReadNovelFullOptions;
|
||||
|
||||
constructor(metadata: ReadNovelFullMetadata) {
|
||||
this.id = metadata.id;
|
||||
@@ -48,12 +52,19 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
parseNovels($: CheerioAPI): Plugin.NovelItem[] {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
$('.list-novel > .row').each((i, elem) => {
|
||||
$('.list-novel > .row, .list-truyen > .row').each((i, elem) => {
|
||||
const novelName = $(elem).find('h3').text();
|
||||
const coverUrl = $(elem).find('img').attr('src');
|
||||
let coverUrl = $(elem).find('img').attr('src');
|
||||
const novelUrl = this.site + $(elem).find('a').attr('href');
|
||||
|
||||
if (novelUrl) {
|
||||
if (
|
||||
coverUrl &&
|
||||
!(coverUrl.includes('https://') || coverUrl.includes('http://'))
|
||||
) {
|
||||
coverUrl = this.site + coverUrl;
|
||||
}
|
||||
|
||||
if (novelUrl && novelName.trim()) {
|
||||
novels.push({
|
||||
name: novelName,
|
||||
cover: coverUrl,
|
||||
@@ -69,12 +80,18 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
pageNo: number,
|
||||
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site + '/novel-list/most-popular-novel?page=' + pageNo;
|
||||
let url =
|
||||
this.site +
|
||||
'/' +
|
||||
this.options.popularPage.replace('%%PAGE%%', pageNo.toString());
|
||||
|
||||
if (!filters) filters = {};
|
||||
|
||||
if (showLatestNovels) {
|
||||
url += this.site + '/novel-list/latest-release-novel?page=' + pageNo;
|
||||
url =
|
||||
this.site +
|
||||
'/' +
|
||||
this.options.latestPage.replace('%%PAGE%%', pageNo.toString());
|
||||
}
|
||||
|
||||
const $ = await this.getCheerio(url, false);
|
||||
@@ -85,22 +102,29 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
let $ = await this.getCheerio(this.site + novelPath, false);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
const novel: Plugin.SourceNovel & { totalPages?: number } = {
|
||||
path: novelPath.replace(this.site, ''),
|
||||
name: 'Untitled',
|
||||
};
|
||||
|
||||
novel.name = $('h3').text().trim();
|
||||
novel.name = $('h3.title').first().text().trim();
|
||||
novel.cover = $('.book > img').attr('src');
|
||||
if (
|
||||
novel.cover &&
|
||||
!(novel.cover.includes('https://') || novel.cover.includes('http://'))
|
||||
) {
|
||||
novel.cover = this.site + novel.cover;
|
||||
}
|
||||
|
||||
$('ul.info.info-meta > li').each(function () {
|
||||
$('ul.info.info-meta > li, .info > div').each(function () {
|
||||
const detailName = $(this)
|
||||
.find('h3')
|
||||
.first()
|
||||
.text()
|
||||
.toLowerCase()
|
||||
.replace(':', '');
|
||||
|
||||
const detail = $(this).text().split(':')[1].trim();
|
||||
const detail = $(this).text().split(':')[1].trim().toLowerCase();
|
||||
|
||||
switch (detailName) {
|
||||
case 'author':
|
||||
@@ -129,37 +153,72 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
});
|
||||
|
||||
novel.summary = $('.desc-text').text();
|
||||
|
||||
const novelId = $('#rating').attr('data-novel-id');
|
||||
const chaptersUrl = this.site + '/ajax/chapter-archive?novelId=' + novelId;
|
||||
|
||||
$ = await this.getCheerio(chaptersUrl, false);
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
|
||||
$('.panel-body')
|
||||
.find('li')
|
||||
.each(function () {
|
||||
const chapterName = $(this).find('a').attr('title') || '';
|
||||
const chapterUrl = $(this).find('a').attr('href') || '';
|
||||
const chapterNumber = Number(chapterName.match(/Chapter (\d*)/g)?.[1]);
|
||||
const novelId = $('#rating').attr('data-novel-id');
|
||||
if (this.options?.ajaxChapterList) {
|
||||
const chaptersUrl =
|
||||
this.site + '/ajax/chapter-archive?novelId=' + novelId;
|
||||
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl,
|
||||
chapterNumber,
|
||||
$ = await this.getCheerio(chaptersUrl, false);
|
||||
|
||||
$('.panel-body')
|
||||
.find('li')
|
||||
.each(function () {
|
||||
const chapterName = $(this).find('a').attr('title') || '';
|
||||
const chapterUrl = $(this).find('a').attr('href') || '';
|
||||
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl,
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
chapters.push(...this.parsePageChapters($));
|
||||
novel.totalPages = parseInt(
|
||||
($('ul.pagination > li.last > a').attr('data-page') ??
|
||||
$('ul.pagination > li.last > a')
|
||||
.attr('href')
|
||||
?.match(/\?page_num=(\d+)/)?.[1])!,
|
||||
);
|
||||
}
|
||||
|
||||
novel.chapters = chapters;
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
parsePageChapters($: CheerioAPI) {
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$('.list-chapter')
|
||||
.find('li')
|
||||
.each(function () {
|
||||
const chapterName = $(this).find('a').attr('title') || '';
|
||||
const chapterUrl = $(this).find('a').attr('href') || '';
|
||||
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl,
|
||||
});
|
||||
});
|
||||
return chapters;
|
||||
}
|
||||
|
||||
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
||||
const $ = await this.getCheerio(
|
||||
this.site + novelPath + '?page=' + page,
|
||||
false,
|
||||
);
|
||||
const chapters = this.parsePageChapters($);
|
||||
return {
|
||||
chapters,
|
||||
};
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath, false);
|
||||
|
||||
return $('#chr-content').html();
|
||||
return $('#chr-content, #chapter-content').html()!;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
@@ -167,7 +226,11 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
page: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const url =
|
||||
this.site + '/novel-list/search?keyword=' + searchTerm + '&page=' + page;
|
||||
this.site +
|
||||
'/' +
|
||||
this.options?.searchPage
|
||||
.replace('%%SEARCH%%', searchTerm)
|
||||
.replace('%%PAGE%%', page.toString());
|
||||
const $ = await this.getCheerio(url, true);
|
||||
|
||||
return this.parseNovels($);
|
||||
|
||||
Reference in New Issue
Block a user