add allnovel and lightnovelplus (#1485)

* add allnovel and lightnovelplus

* different sites treat pages differently :madge:
This commit is contained in:
Adam Kemish
2025-02-01 10:11:26 +08:00
committed by GitHub
parent 73ee4ffe62
commit dc73aaf655
4 changed files with 119 additions and 32 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

+25 -1
View File
@@ -4,7 +4,31 @@
"sourceSite": "https://readnovelfull.com", "sourceSite": "https://readnovelfull.com",
"sourceName": "ReadNovelFull", "sourceName": "ReadNovelFull",
"options": { "options": {
"versionIncrements": 1 "versionIncrements": 1,
"popularPage": "novel-list/most-popular-novel?page=%%PAGE%%",
"latestPage": "novel-list/latest-release-novel?page=%%PAGE%%",
"searchPage": "novel-list/search?keyword=%%SEARCH%%&page=%%PAGE%%",
"ajax-chapter-list": true
}
},
{
"id": "allnovel",
"sourceSite": "https://allnovel.org",
"sourceName": "AllNovel",
"options": {
"popularPage": "most-popular?page=%%PAGE%%",
"latestPage": "latest-release-novel?page=%%PAGE%%",
"searchPage": "search?keyword=%%SEARCH%%&page=%%PAGE%%"
}
},
{
"id": "lightnovelplus",
"sourceSite": "https://lightnovelplus.com",
"sourceName": "LightNovelPlus",
"options": {
"popularPage": "book/bookclass.html?type=hot_novel&language=en&page_num=%%PAGE%%",
"latestPage": "book/bookclass.html?type=last_release&language=en&page_num=%%PAGE%%",
"searchPage": "book/search.html?keyword=%%SEARCH%%&page_num=%%PAGE%%&language=en"
} }
} }
] ]
+94 -31
View File
@@ -1,4 +1,4 @@
import { CheerioAPI, load } from 'cheerio'; import { CheerioAPI, load as parseHTML, load } from 'cheerio';
import { fetchApi } from '@libs/fetch'; import { fetchApi } from '@libs/fetch';
import { Plugin } from '@typings/plugin'; import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus'; import { NovelStatus } from '@libs/novelStatus';
@@ -6,13 +6,17 @@ import { NovelStatus } from '@libs/novelStatus';
type ReadNovelFullOptions = { type ReadNovelFullOptions = {
lang?: string; lang?: string;
versionIncrements?: number; versionIncrements?: number;
popularPage: string;
latestPage: string;
searchPage: string;
ajaxChapterList?: boolean;
}; };
export type ReadNovelFullMetadata = { export type ReadNovelFullMetadata = {
id: string; id: string;
sourceSite: string; sourceSite: string;
sourceName: string; sourceName: string;
options?: ReadNovelFullOptions; options: ReadNovelFullOptions;
filters?: any; filters?: any;
}; };
@@ -22,7 +26,7 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
icon: string; icon: string;
site: string; site: string;
version: string; version: string;
options?: ReadNovelFullOptions; options: ReadNovelFullOptions;
constructor(metadata: ReadNovelFullMetadata) { constructor(metadata: ReadNovelFullMetadata) {
this.id = metadata.id; this.id = metadata.id;
@@ -48,12 +52,19 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
parseNovels($: CheerioAPI): Plugin.NovelItem[] { parseNovels($: CheerioAPI): Plugin.NovelItem[] {
const novels: 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 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'); 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({ novels.push({
name: novelName, name: novelName,
cover: coverUrl, cover: coverUrl,
@@ -69,12 +80,18 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
pageNo: number, pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions, { filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> { ): 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 (!filters) filters = {};
if (showLatestNovels) { 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); const $ = await this.getCheerio(url, false);
@@ -85,22 +102,29 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> { async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
let $ = await this.getCheerio(this.site + novelPath, false); let $ = await this.getCheerio(this.site + novelPath, false);
const novel: Plugin.SourceNovel = { const novel: Plugin.SourceNovel & { totalPages?: number } = {
path: novelPath.replace(this.site, ''), path: novelPath.replace(this.site, ''),
name: 'Untitled', name: 'Untitled',
}; };
novel.name = $('h3').text().trim(); novel.name = $('h3.title').first().text().trim();
novel.cover = $('.book > img').attr('src'); 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) const detailName = $(this)
.find('h3') .find('h3')
.first()
.text() .text()
.toLowerCase() .toLowerCase()
.replace(':', ''); .replace(':', '');
const detail = $(this).text().split(':')[1].trim(); const detail = $(this).text().split(':')[1].trim().toLowerCase();
switch (detailName) { switch (detailName) {
case 'author': case 'author':
@@ -129,37 +153,72 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
}); });
novel.summary = $('.desc-text').text(); 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[] = []; const chapters: Plugin.ChapterItem[] = [];
$('.panel-body') const novelId = $('#rating').attr('data-novel-id');
.find('li') if (this.options?.ajaxChapterList) {
.each(function () { const chaptersUrl =
const chapterName = $(this).find('a').attr('title') || ''; this.site + '/ajax/chapter-archive?novelId=' + novelId;
const chapterUrl = $(this).find('a').attr('href') || '';
const chapterNumber = Number(chapterName.match(/Chapter (\d*)/g)?.[1]);
chapters.push({ $ = await this.getCheerio(chaptersUrl, false);
name: chapterName,
path: chapterUrl, $('.panel-body')
chapterNumber, .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; novel.chapters = chapters;
return novel; 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> { async parseChapter(chapterPath: string): Promise<string> {
const $ = await this.getCheerio(this.site + chapterPath, false); const $ = await this.getCheerio(this.site + chapterPath, false);
return $('#chr-content').html(); return $('#chr-content, #chapter-content').html()!;
} }
async searchNovels( async searchNovels(
@@ -167,7 +226,11 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
page: number, page: number,
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
const url = 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); const $ = await this.getCheerio(url, true);
return this.parseNovels($); return this.parseNovels($);