fix(french): update French sources, add J-Garden/Trad-Index/LightNovelVF, drop Phenix Scans (#2428)
Co-authored-by: Balrog57 <193098123+Balrog57@users.noreply.github.com>
This commit is contained in:
@@ -5,21 +5,46 @@ import { NovelStatus } from '@libs/novelStatus';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
|
||||
const challengeTitles = new Set([
|
||||
'bot verification',
|
||||
'you are being redirected...',
|
||||
'un instant...',
|
||||
'just a moment...',
|
||||
'redirecting...',
|
||||
]);
|
||||
|
||||
async function fetchCheckedHtml(
|
||||
url: string,
|
||||
init?: Parameters<typeof fetchApi>[1],
|
||||
): Promise<string> {
|
||||
const response = await fetchApi(url, init);
|
||||
if (!response.ok)
|
||||
throw new Error(`HTTP ${response.status} while loading ${url}`);
|
||||
const html = await response.text();
|
||||
const title = html
|
||||
.match(/<title[^>]*>(.*?)<\/title>/is)?.[1]
|
||||
?.replace(/<[^>]+>/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (title && challengeTitles.has(title))
|
||||
throw new Error(`Bot challenge while loading ${url}`);
|
||||
return html;
|
||||
}
|
||||
|
||||
class NovelDeGlacePlugin implements Plugin.PluginBase {
|
||||
id = 'noveldeglace';
|
||||
name = 'NovelDeGlace';
|
||||
icon = 'src/fr/noveldeglace/icon.png';
|
||||
site = 'https://noveldeglace.com/';
|
||||
version = '1.0.5';
|
||||
version = '1.0.8';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI | undefined> {
|
||||
const r = await fetchApi(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
});
|
||||
if (!r.ok) return undefined;
|
||||
const body = await r.text();
|
||||
const loadedCheerio = load(body);
|
||||
return loadedCheerio;
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
return load(
|
||||
await fetchCheckedHtml(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
parseNovels(
|
||||
@@ -76,14 +101,11 @@ class NovelDeGlacePlugin implements Plugin.PluginBase {
|
||||
}
|
||||
url += '/page/' + pageNo;
|
||||
const $ = await this.getCheerio(url);
|
||||
if (!$) return [];
|
||||
return this.parseNovels($, showLatestNovels);
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
if (!$) throw new Error('Failed to load page (open in web view)');
|
||||
|
||||
const novel: Plugin.SourceNovel = { path: novelPath, name: 'Untitled' };
|
||||
|
||||
novel.name = $('span.current').text().trim();
|
||||
@@ -214,19 +236,26 @@ class NovelDeGlacePlugin implements Plugin.PluginBase {
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = novelChapters;
|
||||
novel.chapters = novelChapters.map((chapter, index) => ({
|
||||
...chapter,
|
||||
chapterNumber: index,
|
||||
}));
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
if (!$) throw new Error('Failed to load page (open in web view)');
|
||||
|
||||
$('.mistape_caption').remove();
|
||||
const chapterText =
|
||||
$('.chapter-content').html() || $('.entry-content').html() || '';
|
||||
return chapterText;
|
||||
const chapter = $('.chapter-content').first().length
|
||||
? $('.chapter-content').first()
|
||||
: $('.entry-content').first();
|
||||
chapter.find('script, style, ins, iframe, .ads, .mistape_caption').remove();
|
||||
if (
|
||||
chapter.text().replace(/\s+/g, ' ').trim().length < 200 &&
|
||||
!chapter.find('img').length
|
||||
)
|
||||
throw new Error('No readable chapter content found');
|
||||
return chapter.html() || '';
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
@@ -236,8 +265,6 @@ class NovelDeGlacePlugin implements Plugin.PluginBase {
|
||||
if (num !== 1) return []; // only 1 page of results
|
||||
const url = this.site + 'roman';
|
||||
const $ = await this.getCheerio(url);
|
||||
if (!$) throw new Error('Failed to load page (open in web view)');
|
||||
|
||||
let novels = this.parseNovels($, false);
|
||||
|
||||
novels = novels.filter(novel =>
|
||||
|
||||
Reference in New Issue
Block a user