refactor: Overhaul Plugin Architecture & Playground UI (#1846)
* refactor: Move Plugins Out and Consolidate with Multisrc * feat: Overhaul Playground UI * feat: Add Filters to New UI * feat: Persist Selected Plugin * feat: Add Direct Parse Novel/Chapter Options and Feedback Toasts [skip ci] * feat: UX Improvements * chore: Update Plugin Path in Publish Workflow * fix: Add Backward Compatibility * chore: Update Plugin Publishing Script
This commit is contained in:
committed by
GitHub
parent
252beff0bf
commit
20c2b75b01
@@ -0,0 +1,339 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import dayjs from 'dayjs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
|
||||
class ChireadsPlugin implements Plugin.PluginBase {
|
||||
id = 'chireads';
|
||||
name = 'Chireads';
|
||||
icon = 'src/fr/chireads/icon.png';
|
||||
site = 'https://chireads.com';
|
||||
version = '1.0.2';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
});
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site;
|
||||
let tag = 'all';
|
||||
if (showLatestNovels) url += '/category/translatedtales/page/' + pageNo;
|
||||
else {
|
||||
if (
|
||||
filters &&
|
||||
typeof filters.tag.value === 'string' &&
|
||||
filters.tag.value !== 'all'
|
||||
)
|
||||
tag = filters.tag.value;
|
||||
if (tag !== 'all') url += '/tag/' + tag + '/page/' + pageNo;
|
||||
else if (pageNo > 1) return [];
|
||||
}
|
||||
let $ = await this.getCheerio(url);
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
|
||||
if (showLatestNovels || tag !== 'all') {
|
||||
let loop = 1;
|
||||
if (showLatestNovels) loop = 2;
|
||||
for (let i = 0; i < loop; i++) {
|
||||
if (i === 1)
|
||||
$ = await this.getCheerio(
|
||||
this.site + '/category/original/page/' + pageNo,
|
||||
);
|
||||
let romans = $('.romans-content li');
|
||||
if (!romans.length) romans = $('#content li');
|
||||
romans.each((i, elem) => {
|
||||
const novelName = $(elem)
|
||||
.contents()
|
||||
.find('div')
|
||||
.first()
|
||||
.text()
|
||||
.trim();
|
||||
const novelCover = $(elem)
|
||||
.find('div')
|
||||
.first()
|
||||
.find('img')
|
||||
.attr('src');
|
||||
const novelUrl = $(elem).find('div').first().find('a').attr('href');
|
||||
|
||||
if (novelUrl) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const populaire = $(':contains("Populaire")')
|
||||
.last()
|
||||
.parent()
|
||||
.next()
|
||||
.find('li > div');
|
||||
if (populaire.length === 12) {
|
||||
// pc
|
||||
let novelCover: string | undefined;
|
||||
let novelName: string | undefined;
|
||||
let novelUrl: string | undefined;
|
||||
populaire.each((i, elem) => {
|
||||
if (i % 2 === 0) novelCover = $(elem).find('img').attr('src');
|
||||
else {
|
||||
novelName = $(elem).text().trim();
|
||||
novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover || defaultCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
} // mobile
|
||||
else {
|
||||
const imgs = populaire.find('div.popular-list-img img');
|
||||
const txts = populaire.find('div.popular-list-name');
|
||||
|
||||
txts.each((i, elem) => {
|
||||
const novelName = $(elem).text().trim();
|
||||
const novelCover = $(imgs[i]).attr('src');
|
||||
const novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
if (novelUrl) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = { path: novelPath, name: 'Sans titre' };
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name =
|
||||
$('.inform-product-txt').first().text().trim() ||
|
||||
$('.inform-title').text().trim();
|
||||
novel.cover =
|
||||
$('.inform-product img').attr('src') ||
|
||||
$('.inform-product-img img').attr('src') ||
|
||||
defaultCover;
|
||||
novel.summary =
|
||||
$('.inform-inform-txt').text().trim() ||
|
||||
$('.inform-intr-txt').text().trim();
|
||||
|
||||
const infos =
|
||||
$('div.inform-product-txt > div.inform-intr-col').text().trim() ||
|
||||
$('div.inform-inform-data > h6').text().trim();
|
||||
if (infos.includes('Auteur : '))
|
||||
novel.author = infos
|
||||
.substring(
|
||||
infos.indexOf('Auteur : ') + 9,
|
||||
infos.indexOf('Statut de Parution : '),
|
||||
)
|
||||
.trim();
|
||||
else if (infos.includes('Fantrad : '))
|
||||
novel.author = infos
|
||||
.substring(
|
||||
infos.indexOf('Fantrad : ') + 10,
|
||||
infos.indexOf('Statut de Parution : '),
|
||||
)
|
||||
.trim();
|
||||
else novel.author = 'Inconnu';
|
||||
switch (
|
||||
infos.substring(infos.indexOf('Statut de Parution : ') + 21).toLowerCase()
|
||||
) {
|
||||
case 'en pause':
|
||||
novel.status = NovelStatus.OnHiatus;
|
||||
break;
|
||||
case 'complet':
|
||||
novel.status = NovelStatus.Completed;
|
||||
break;
|
||||
default:
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
break;
|
||||
}
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
|
||||
let chapterList = $('.chapitre-table a');
|
||||
if (!chapterList.length) {
|
||||
$('div.inform-annexe-list').first().remove();
|
||||
chapterList = $('.inform-annexe-list').find('a');
|
||||
}
|
||||
chapterList.each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
const releaseDate = dayjs(
|
||||
chapterUrl?.substring(chapterUrl.length - 11, chapterUrl.length - 1),
|
||||
).format('DD MMMM YYYY');
|
||||
|
||||
if (chapterUrl) {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
novel.chapters = chapters;
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterUrl: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterUrl);
|
||||
|
||||
const chapterText = $('#content').html() || '';
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
let novels: Plugin.NovelItem[] = [];
|
||||
|
||||
let i = 1;
|
||||
let finised = false;
|
||||
while (!finised) {
|
||||
await this.popularNovels(i, {
|
||||
showLatestNovels: true,
|
||||
filters: undefined,
|
||||
}).then(res => {
|
||||
if (res.length === 0) finised = true;
|
||||
novels.push(...res);
|
||||
});
|
||||
i++;
|
||||
}
|
||||
|
||||
novels = novels.filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, ''),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
filters = {
|
||||
tag: {
|
||||
type: FilterTypes.Picker,
|
||||
label: 'Tag',
|
||||
value: 'all',
|
||||
options: [
|
||||
{ label: 'Tous', value: 'all' },
|
||||
{ label: 'Arts martiaux', value: 'arts-martiaux' },
|
||||
{ label: 'De faible à fort', value: 'de-faible-a-fort' },
|
||||
{ label: 'Adapté en manhua', value: 'adapte-en-manhua' },
|
||||
{ label: 'Cultivation', value: 'cultivation' },
|
||||
{ label: 'Action', value: 'action' },
|
||||
{ label: 'Aventure', value: 'aventure' },
|
||||
{ label: 'Monstres', value: 'monstres' },
|
||||
{ label: 'Xuanhuan', value: 'xuanhuan' },
|
||||
{ label: 'Fantastique', value: 'fantastique' },
|
||||
{ label: 'Adapté en Animé', value: 'adapte-en-anime' },
|
||||
{ label: 'Alchimie', value: 'alchimie' },
|
||||
{ label: 'Éléments de jeux', value: 'elements-de-jeux' },
|
||||
{ label: 'Calme Protagoniste', value: 'calme-protagoniste' },
|
||||
{
|
||||
label: 'Protagoniste intelligent',
|
||||
value: 'protagoniste-intelligent',
|
||||
},
|
||||
{ label: 'Polygamie', value: 'polygamie' },
|
||||
{ label: 'Belle femelle Lea', value: 'belle-femelle-lea' },
|
||||
{ label: 'Personnages arrogants', value: 'personnages-arrogants' },
|
||||
{ label: 'Système de niveau', value: 'systeme-de-niveau' },
|
||||
{ label: 'Cheat', value: 'cheat' },
|
||||
{ label: 'Protagoniste génie', value: 'protagoniste-genie' },
|
||||
{ label: 'Comédie', value: 'comedie' },
|
||||
{ label: 'Gamer', value: 'gamer' },
|
||||
{ label: 'Mariage', value: 'mariage' },
|
||||
{ label: 'seeking Protag', value: 'seeking-protag' },
|
||||
{ label: 'Romance précoce', value: 'romance-precoce' },
|
||||
{ label: 'Croissance accélérée', value: 'croissance-acceleree' },
|
||||
{ label: 'Artefacts', value: 'artefacts' },
|
||||
{
|
||||
label: 'Intelligence artificielle',
|
||||
value: 'intelligence-artificielle',
|
||||
},
|
||||
{ label: 'Mariage arrangé', value: 'mariage-arrange' },
|
||||
{ label: 'Mature', value: 'mature' },
|
||||
{ label: 'Adulte', value: 'adulte' },
|
||||
{
|
||||
label: 'Administrateur de système',
|
||||
value: 'administrateur-de-systeme',
|
||||
},
|
||||
{ label: 'Beau protagoniste', value: 'beau-protagoniste' },
|
||||
{
|
||||
label: 'Protagoniste charismatique',
|
||||
value: 'protagoniste-charismatique',
|
||||
},
|
||||
{ label: 'Protagoniste masculin', value: 'protagoniste-masculin' },
|
||||
{ label: 'Démons', value: 'demons' },
|
||||
{ label: 'Reincarnation', value: 'reincarnation' },
|
||||
{ label: 'Académie', value: 'academie' },
|
||||
{
|
||||
label: 'Cacher les vraies capacités',
|
||||
value: 'cacher-les-vraies-capacites',
|
||||
},
|
||||
{
|
||||
label: 'Protagoniste surpuissant',
|
||||
value: 'protagoniste-surpuissant',
|
||||
},
|
||||
{ label: 'Joueur', value: 'joueur' },
|
||||
{
|
||||
label: 'Protagoniste fort dès le départ',
|
||||
value: 'protagoniste-fort-des-le-depart',
|
||||
},
|
||||
{ label: 'Immortels', value: 'immortels' },
|
||||
{ label: 'Cultivation rapide', value: 'cultivation-rapide' },
|
||||
{ label: 'Harem', value: 'harem' },
|
||||
{ label: 'Assasins', value: 'assasins' },
|
||||
{ label: 'De pauvre à riche', value: 'de-pauvre-a-riche' },
|
||||
{
|
||||
label: 'Système de classement de jeux',
|
||||
value: 'systeme-de-classement-de-jeux',
|
||||
},
|
||||
{ label: 'Capacités spéciales', value: 'capacites-speciales' },
|
||||
{ label: 'Vengeance', value: 'vengeance' },
|
||||
],
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new ChireadsPlugin();
|
||||
@@ -0,0 +1,166 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
class HarkenEliwoodPlugin implements Plugin.PluginBase {
|
||||
id = 'harkeneliwood';
|
||||
name = 'HarkenEliwood';
|
||||
icon = 'src/fr/harkeneliwood/icon.png';
|
||||
site = 'https://harkeneliwood.wordpress.com';
|
||||
version = '1.0.0';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
});
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 1) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
const url = this.site;
|
||||
const $ = await this.getCheerio(url + '/projets/');
|
||||
$('#content .entry-content [href]')
|
||||
// We don't collect items for Facebook and Twitter.
|
||||
.not('[rel="nofollow noopener noreferrer"]')
|
||||
.each((i, elem) => {
|
||||
const novelName = $(elem).text().trim();
|
||||
const novelUrl = $(elem).attr('href');
|
||||
if (novelUrl && novelName) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: defaultCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
novel.name = $('#content h1.entry-title').text().trim();
|
||||
novel.cover =
|
||||
$('#content .entry-content p img').first().attr('src') || defaultCover;
|
||||
novel.summary = this.getSummary($('#content .entry-content').text());
|
||||
novel.author = this.getAuthor($('#content .entry-content').text());
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$('#content .entry-content p a').each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
// Check if the chapter URL exists and contains the site name.
|
||||
if (chapterUrl && chapterUrl.includes(this.site) && chapterName) {
|
||||
const releaseDate = dayjs(
|
||||
chapterUrl?.substring(this.site.length + 1, this.site.length + 11),
|
||||
).format('DD MMMM YYYY');
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
}
|
||||
});
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
|
||||
getSummary(text: string) {
|
||||
let resume = '';
|
||||
const regexResume1 = /Synopsis :([\s\S]*)Traduction anglaise/i;
|
||||
const regexResume2 = /Synopsis :([\s\S]*)Raw :/i;
|
||||
const regexResume3 = /Synopsis 1 :([\s\S]*)Synopsis 2 :([\s\S]*)Raw :/i;
|
||||
const regexResume4 = /Synopsis :([\s\S]*)Prélude/i;
|
||||
const regexResume5 = /Synospis :([\s\S]*)Original /i;
|
||||
const regexResume6 = /([\s\S]*)Raw :/i;
|
||||
|
||||
const match1: RegExpExecArray | null = regexResume1.exec(text);
|
||||
const match2: RegExpExecArray | null = regexResume2.exec(text);
|
||||
const match3: RegExpExecArray | null = regexResume3.exec(text);
|
||||
const match4: RegExpExecArray | null = regexResume4.exec(text);
|
||||
const match5: RegExpExecArray | null = regexResume5.exec(text);
|
||||
|
||||
if (match1 !== null) {
|
||||
resume = match1[1];
|
||||
} else if (match2 !== null) {
|
||||
resume = match2[1];
|
||||
} else if (match3 !== null) {
|
||||
resume = match3[1] + match3[2];
|
||||
} else if (match4 !== null) {
|
||||
resume = match4[1];
|
||||
} else if (match5 !== null) {
|
||||
resume = match5[1];
|
||||
} else {
|
||||
resume = text;
|
||||
}
|
||||
|
||||
if (regexResume6.test(resume)) {
|
||||
const match6: RegExpExecArray | null = regexResume6.exec(resume);
|
||||
if (match6 !== null) {
|
||||
resume = match6[1];
|
||||
}
|
||||
}
|
||||
|
||||
return resume.trim();
|
||||
}
|
||||
|
||||
getAuthor(text: string) {
|
||||
const regexAuteur = /Auteur\s*:\s*(.*?)\s*(?:\r?\n|$)/i;
|
||||
const match = regexAuteur.exec(text);
|
||||
|
||||
if (match !== null && match[1].trim() !== '') {
|
||||
return match[1].trim();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
const title = $('h1.entry-title');
|
||||
const chapter = $('div.entry-content');
|
||||
return (title.html() || '') + (chapter.html() || '');
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
}
|
||||
|
||||
export default new HarkenEliwoodPlugin();
|
||||
@@ -0,0 +1,240 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
|
||||
class KissWoodPlugin implements Plugin.PluginBase {
|
||||
id = 'kisswood';
|
||||
name = 'KissWood';
|
||||
icon = 'src/fr/kisswood/icon.png';
|
||||
site = 'https://kisswood.eu';
|
||||
version = '1.0.0';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url);
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async getNovelsCovers(
|
||||
novels: Plugin.NovelItem[],
|
||||
listUrlCover: string[],
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
await Promise.all(
|
||||
novels.map(async (novel, index) => {
|
||||
const urlCover = listUrlCover[index];
|
||||
if (urlCover) {
|
||||
novel.cover = this.findCoverImage(await this.getCheerio(urlCover));
|
||||
}
|
||||
}),
|
||||
);
|
||||
return novels;
|
||||
}
|
||||
|
||||
regexAuthors = [/Auteur :([^\n]*)/, /Auteur\u00A0:([^\n]*)/];
|
||||
|
||||
async getNovelInfo(
|
||||
novel: Plugin.SourceNovel,
|
||||
url: string,
|
||||
): Promise<Plugin.SourceNovel> {
|
||||
const $ = await this.getCheerio(url);
|
||||
|
||||
const textArray: string[] = $('.entry-content p')
|
||||
.map((_, element) => $(element).text().trim())
|
||||
.get()
|
||||
.join('\n')
|
||||
.split('\n');
|
||||
|
||||
const index = textArray.findIndex(element =>
|
||||
[
|
||||
'Traducteur Anglais- Français',
|
||||
'Titre en français',
|
||||
'———',
|
||||
'Titre :',
|
||||
'Lien vers le premier chapitre',
|
||||
'____________',
|
||||
'Auteur : ',
|
||||
].some(marker => element.includes(marker)),
|
||||
);
|
||||
|
||||
novel.summary = (index !== -1 ? textArray.slice(0, index) : textArray)
|
||||
.join('\n')
|
||||
.replace('Synopsis :', '');
|
||||
novel.author = this.extractInfo(textArray.join('\n'), this.regexAuthors);
|
||||
novel.cover = this.findCoverImage($);
|
||||
return novel;
|
||||
}
|
||||
|
||||
findCoverImage($: CheerioAPI): string {
|
||||
return (
|
||||
$('div p img').first().attr('src') ||
|
||||
$('figure a img').first().attr('src') ||
|
||||
$('figure img').first().attr('src') ||
|
||||
defaultCover
|
||||
);
|
||||
}
|
||||
|
||||
extractInfo(text: string, regexes: RegExp[]): string {
|
||||
for (const regex of regexes) {
|
||||
const match = regex.exec(text);
|
||||
if (match !== null) {
|
||||
return match[1].trim();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 1) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
const $ = await this.getCheerio(this.site);
|
||||
const listUrlCover: string[] = [];
|
||||
$('nav div div ul li ul li').each((i, elem) => {
|
||||
if ($(elem).text().trim() === 'Sommaire') {
|
||||
const novelName = $(elem)
|
||||
.closest('ul')
|
||||
.siblings('a')
|
||||
.first()
|
||||
.text()
|
||||
.trim();
|
||||
const novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
if (novelUrl && novelName) {
|
||||
const urlCover = $(elem).parent().find('a').attr('href');
|
||||
if (urlCover) {
|
||||
listUrlCover.push(urlCover);
|
||||
} else {
|
||||
listUrlCover.push('');
|
||||
}
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
cover: defaultCover,
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
}
|
||||
});
|
||||
return await this.getNovelsCovers(novels, listUrlCover);
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
let novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
status: NovelStatus.Ongoing,
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
let novelUrl = null;
|
||||
|
||||
$('nav div div ul li ul li').each((i, elem) => {
|
||||
if ($(elem).find('a').attr('href') === this.site + novelPath) {
|
||||
novelUrl = $(elem).parent().find('a').first().attr('href');
|
||||
novel.name = $(elem).closest('ul').siblings('a').first().text().trim();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
if (novelUrl) {
|
||||
novel = await this.getNovelInfo(novel, novelUrl);
|
||||
}
|
||||
|
||||
const chapterSelectors = [
|
||||
'.entry-content ul li a',
|
||||
'.entry-content ul li ul li a',
|
||||
'.entry-content p a',
|
||||
'.entry-content li a',
|
||||
'.entry-content blockquote a',
|
||||
].join(', ');
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$(chapterSelectors).each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href')?.replace('http://', 'https://');
|
||||
if (
|
||||
chapterUrl &&
|
||||
chapterName &&
|
||||
chapterUrl.includes(this.site) &&
|
||||
// We remove the unnecessary links to Facebook, X, and the homepage from the chapters.
|
||||
!chapterUrl.includes('share=facebook') &&
|
||||
!chapterUrl.includes('share=x') &&
|
||||
!chapterUrl.includes('/category/traductions/') &&
|
||||
!chapterUrl.includes('/category/tour-des-mondes/') &&
|
||||
// Removal of duplicates
|
||||
!chapters.some(chapter => this.site + chapter.path === chapterUrl)
|
||||
) {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
});
|
||||
}
|
||||
});
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
|
||||
const elements: string[] = $('.entry-content')
|
||||
.contents()
|
||||
.map((_, el) => $.html(el))
|
||||
.get();
|
||||
|
||||
let hrIndexes: number[] = elements
|
||||
.map((elem, index) => (elem.includes('<hr>') ? index : -1))
|
||||
.filter(index => index !== -1);
|
||||
|
||||
if (hrIndexes.length === 0) {
|
||||
hrIndexes = [
|
||||
0,
|
||||
elements.findIndex(
|
||||
element =>
|
||||
element.includes('https://fr.tipeee.com/kisswood/') ||
|
||||
element.includes('>Sommaire</a>') ||
|
||||
element.includes('>Chapitre Suivant</a>') ||
|
||||
element.includes('———————————————————————————-') ||
|
||||
element.includes('share=facebook'),
|
||||
),
|
||||
];
|
||||
} else if (hrIndexes.length === 1) {
|
||||
hrIndexes.unshift(0);
|
||||
} else {
|
||||
hrIndexes[0] += 1;
|
||||
}
|
||||
return elements.slice(hrIndexes[0], hrIndexes[1]).join('\n');
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
}
|
||||
|
||||
export default new KissWoodPlugin();
|
||||
@@ -0,0 +1,316 @@
|
||||
import { load, CheerioAPI } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
|
||||
class NovelDeGlacePlugin implements Plugin.PluginBase {
|
||||
id = 'noveldeglace';
|
||||
name = 'NovelDeGlace';
|
||||
icon = 'src/fr/noveldeglace/icon.png';
|
||||
site = 'https://noveldeglace.com/';
|
||||
version = '1.0.4';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
parseNovels(
|
||||
$: CheerioAPI,
|
||||
showLatestNovels: boolean | undefined,
|
||||
): Plugin.NovelItem[] {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
$('article').each((i, el) => {
|
||||
const cheerio = $(el);
|
||||
const novelName = cheerio.find('h2').text().trim();
|
||||
const novelCover = cheerio.find('img').attr('src');
|
||||
let novelUrl: string | undefined;
|
||||
if (showLatestNovels)
|
||||
novelUrl = cheerio.find('span.Roman > a').attr('href');
|
||||
else novelUrl = cheerio.find('h2 > a').attr('href');
|
||||
|
||||
if (novelUrl) {
|
||||
const novel: Plugin.NovelItem = {
|
||||
name: novelName,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
cover: novelCover,
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{
|
||||
filters,
|
||||
showLatestNovels,
|
||||
}: Plugin.PopularNovelsOptions<typeof this.filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site;
|
||||
if (showLatestNovels) url += 'chapitre';
|
||||
else {
|
||||
let cat_gen = 'all';
|
||||
if (filters && typeof filters.categorie_genre.value == 'string')
|
||||
cat_gen = filters.categorie_genre.value;
|
||||
if (
|
||||
cat_gen != 'all' &&
|
||||
cat_gen != 'categorie_roman' &&
|
||||
cat_gen != 'genre'
|
||||
) {
|
||||
if (cat_gen[0] == 'c') url += 'categorie_roman/' + cat_gen.substring(2);
|
||||
else if (cat_gen[0] == 'g') url += 'genre/' + cat_gen.substring(2);
|
||||
} else if (pageNo > 1)
|
||||
return []; // when asking for all novels, there is only 1 page
|
||||
else url += 'roman';
|
||||
}
|
||||
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 =
|
||||
(
|
||||
$('div.entry-content > div > strong')[0].nextSibling as string | null
|
||||
)?.nodeValue?.trim() || 'Untitled';
|
||||
|
||||
novel.cover = $('.su-row > div > div > img').attr('src') || defaultCover;
|
||||
|
||||
const novelInfos = $('div[data-title=Tomes] >').toArray();
|
||||
novelInfos.pop();
|
||||
novelInfos.shift();
|
||||
novel.summary =
|
||||
$('div[data-title=Synopsis]').text().trim() +
|
||||
'\n\n' +
|
||||
novelInfos
|
||||
.map(el => $(el).text())
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
novel.author = $("strong:contains('Auteur :')")
|
||||
.parent()
|
||||
.text()
|
||||
.replace('Auteur : ', '')
|
||||
.trim();
|
||||
|
||||
novel.artist = $("strong:contains('Illustrateur :')")
|
||||
.parent()
|
||||
.text()
|
||||
.replace('Illustrateur :', '')
|
||||
.trim();
|
||||
|
||||
const categorie = $('.categorie').text().replace('Catégorie :', '').trim();
|
||||
const genres = $('.genre')
|
||||
.text()
|
||||
.replace('Genre :', '')
|
||||
.replace(/, /g, ',')
|
||||
.trim();
|
||||
if (categorie && categorie != 'Autre') novel.genres = categorie;
|
||||
if (genres)
|
||||
novel.genres = novel.genres ? novel.genres + ',' + genres : genres;
|
||||
|
||||
const status = $("strong:contains('Statut :')").parent().attr('class');
|
||||
switch (status) {
|
||||
case 'type etat0':
|
||||
case 'type etat1':
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
break;
|
||||
case 'type etat4':
|
||||
novel.status = NovelStatus.OnHiatus;
|
||||
break;
|
||||
case 'type etat5':
|
||||
novel.status = NovelStatus.Completed;
|
||||
break;
|
||||
case 'type etat6':
|
||||
novel.status = NovelStatus.Cancelled;
|
||||
break;
|
||||
default:
|
||||
novel.status = NovelStatus.Unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
const novelChapters: Plugin.ChapterItem[] = [];
|
||||
|
||||
const volumes = $('div[data-title=Tomes] > div').last().contents();
|
||||
const hasMultipleVolumes = volumes.length > 1;
|
||||
|
||||
let chapterName = '';
|
||||
const site = this.site;
|
||||
volumes.each((volumeIndex: number, el) => {
|
||||
if (hasMultipleVolumes) chapterName = 'T.' + (volumeIndex + 1) + ' ';
|
||||
$(el)
|
||||
.find('.chpt')
|
||||
.each((chapterIndex: number, el) => {
|
||||
const cheerio = $(el);
|
||||
const newChapterName =
|
||||
chapterName + cheerio.find('a').first().text().trim() || '';
|
||||
if (!cheerio.find('i.fa').length) {
|
||||
// no parts
|
||||
const dateHtml =
|
||||
cheerio.html()?.substring(cheerio.html()?.indexOf('</a>') || 0) ||
|
||||
'';
|
||||
const releaseDate =
|
||||
dateHtml?.substring(
|
||||
dateHtml.indexOf('(') + 1,
|
||||
dateHtml.indexOf(')'),
|
||||
) || undefined;
|
||||
const chapterUrl = cheerio.find('a').attr('href');
|
||||
if (chapterUrl) {
|
||||
const chapter: Plugin.ChapterItem = {
|
||||
name: newChapterName,
|
||||
releaseTime: releaseDate,
|
||||
path: chapterUrl.replace(site, ''),
|
||||
chapterNumber: chapterIndex,
|
||||
};
|
||||
|
||||
novelChapters.push(chapter);
|
||||
}
|
||||
} // has parts that needs to be added individually
|
||||
else {
|
||||
const items =
|
||||
cheerio.find('i').parent().next().html()?.split('</a>') || [];
|
||||
items?.shift();
|
||||
const dates: string[] = [];
|
||||
items?.forEach(item => {
|
||||
// there is a date on every publish parts
|
||||
dates.push(
|
||||
item.substring(item.indexOf('(') + 1, item.indexOf(')')),
|
||||
);
|
||||
});
|
||||
const hrefs: string[] = [];
|
||||
cheerio
|
||||
.find('i')
|
||||
.parent()
|
||||
.next()
|
||||
.find('a')
|
||||
.each(function () {
|
||||
hrefs.push(this['attribs']['href']);
|
||||
});
|
||||
if (dates.length == hrefs.length)
|
||||
dates.forEach((date, index) => {
|
||||
const chapter: Plugin.ChapterItem = {
|
||||
name: newChapterName + ' (' + (index + 1) + ')',
|
||||
releaseTime: date,
|
||||
path: hrefs[index].replace(site, ''),
|
||||
chapterNumber: chapterIndex + (index + 1) / 1000,
|
||||
};
|
||||
novelChapters.push(chapter);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
novel.chapters = novelChapters;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
num: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
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 =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
filters = {
|
||||
categorie_genre: {
|
||||
type: FilterTypes.Picker,
|
||||
label: 'Catégorie/Genre',
|
||||
value: 'all',
|
||||
options: [
|
||||
{ label: 'Tous', value: 'all' },
|
||||
{ label: '═══CATÉGORIES═══', value: 'categorie_roman' },
|
||||
{ label: 'Autre', value: 'c_autre' },
|
||||
{ label: 'Fille', value: 'c_fille' },
|
||||
{ label: 'Original', value: 'c_original' },
|
||||
{ label: 'Roman pour Adulte', value: 'c_roman-pour-adulte' },
|
||||
{ label: 'Seinen', value: 'c_seinen' },
|
||||
{ label: 'Shonen', value: 'c_shonen' },
|
||||
{ label: 'Xuanhuan', value: 'c_xuanhuan' },
|
||||
{ label: 'Yaoi', value: 'c_yaoi' },
|
||||
{ label: 'Yuri', value: 'c_yuri' },
|
||||
{ label: '═══GENRES═══', value: 'genre' },
|
||||
{ label: 'Action', value: 'g_action' },
|
||||
{ label: 'Adulte', value: 'g_adulte' },
|
||||
{ label: 'Anti-Héros', value: 'g_anti-heros' },
|
||||
{ label: 'Arts Martiaux', value: 'g_arts-martiaux' },
|
||||
{ label: 'Aventure', value: 'g_aventure' },
|
||||
{ label: 'Comédie', value: 'g_comedie' },
|
||||
{ label: 'Drame', value: 'g_drame' },
|
||||
{ label: 'Ecchi', value: 'g_ecchi' },
|
||||
{ label: 'Fantastique', value: 'g_fantastique' },
|
||||
{ label: 'Harem', value: 'g_harem' },
|
||||
{ label: 'Horreur', value: 'g_horreur' },
|
||||
{ label: 'Insectes', value: 'g_insectes' },
|
||||
{ label: 'Lolicon', value: 'g_lolicon' },
|
||||
{ label: 'Mature', value: 'g_mature' },
|
||||
{ label: 'Mecha', value: 'g_mecha' },
|
||||
{ label: 'Mystère', value: 'g_mystere' },
|
||||
{ label: 'Pas de harem', value: 'g_pas-de-harem' },
|
||||
{ label: 'Psychologique', value: 'g_psychologique' },
|
||||
{ label: 'Romance', value: 'g_romance' },
|
||||
{ label: 'Sci-fi', value: 'g_sci-fi' },
|
||||
{ label: 'Science-Fiction', value: 'g_science-fiction' },
|
||||
{ label: 'Shotacon', value: 'g_shotacon' },
|
||||
{ label: 'Shoujo Ai', value: 'g_shoujo-ai' },
|
||||
{ label: 'Smut', value: 'g_smut' },
|
||||
{ label: 'Surnaturel', value: 'g_surnaturel' },
|
||||
{ label: 'Tragédie', value: 'g_tragedie' },
|
||||
{ label: 'Tranche de vie', value: 'g_tranche-de-vie' },
|
||||
{ label: 'Vie scolaire', value: 'g_vie-scolaire' },
|
||||
{ label: 'Xuanhuan', value: 'g_xuanhuan' },
|
||||
],
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new NovelDeGlacePlugin();
|
||||
@@ -0,0 +1,206 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
|
||||
class NovhellPlugin implements Plugin.PluginBase {
|
||||
id = 'novhell';
|
||||
name = 'Novhell';
|
||||
icon = 'src/fr/novhell/icon.png';
|
||||
site = 'https://novhell.org';
|
||||
version = '1.0.1';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
});
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 1) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
const url = this.site;
|
||||
const $ = await this.getCheerio(url);
|
||||
$('article div div div figure').each((i, elem) => {
|
||||
let novelName = $(elem)
|
||||
.find('figcaption span strong')
|
||||
.first()
|
||||
.text()
|
||||
.trim();
|
||||
if (!novelName || novelName.trim() === '') {
|
||||
novelName = $(elem).find('figcaption a strong').first().text().trim();
|
||||
}
|
||||
const novelCover = $(elem).find('a img').attr('src');
|
||||
const novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
if (novelUrl && novelName) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name =
|
||||
$('meta[property="og:title"]')
|
||||
.attr('content')
|
||||
?.replace('- NovHell', '') || '';
|
||||
novel.cover =
|
||||
$('section div div div div div img').first().attr('src') || defaultCover;
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
novel.author = $("strong:contains('Ecrit par ')")
|
||||
.parent()
|
||||
.text()
|
||||
.replace('Ecrit par ', '')
|
||||
.trim();
|
||||
|
||||
if (!novel.author) {
|
||||
novel.author = $("div p:contains('Auteur')")
|
||||
.text()
|
||||
.replace('Auteur', '')
|
||||
.replace(':', '')
|
||||
.trim();
|
||||
}
|
||||
if (!novel.author) {
|
||||
novel.author = $("div p:contains('Ecrit par :')")
|
||||
.text()
|
||||
.replace('Ecrit par :', '')
|
||||
.trim();
|
||||
}
|
||||
novel.genres = $("strong:contains('Genre')")
|
||||
.parent()
|
||||
.text()
|
||||
.replace('Genre', '')
|
||||
.replace(':', '')
|
||||
.trim();
|
||||
if (!novel.genres) {
|
||||
novel.genres = $("div p:contains('Genre')")
|
||||
.text()
|
||||
.replace('Genre', '')
|
||||
.replace(':', '')
|
||||
.trim();
|
||||
}
|
||||
novel.summary = $("strong:contains('Synopsis')")
|
||||
.parent()
|
||||
.parent()
|
||||
.text()
|
||||
.replace('Synopsis', '')
|
||||
.replace('Synopsis', '')
|
||||
.replace(':', '')
|
||||
.trim();
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
|
||||
$('main div article div div section div div div div div p a').each(
|
||||
(i, elem) => {
|
||||
// Replace non-breaking spaces with a 'normal' space.
|
||||
const chapterName = $(elem)
|
||||
.text()
|
||||
.replace(/\u00A0/g, ' ')
|
||||
.trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
// Check if the chapter URL exists and contains the site name.
|
||||
if (chapterUrl && chapterUrl.includes(this.site)) {
|
||||
const regex = /Chapitre (\d+)/g;
|
||||
let chapterNumber = 0;
|
||||
let match;
|
||||
while ((match = regex.exec(chapterName)) !== null) {
|
||||
const number = parseInt(match[1]);
|
||||
chapterNumber += number;
|
||||
}
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
chapterNumber: chapterNumber,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Sort the chapters array based on the chapter numbers.
|
||||
// We retrieve the chapters in the order 1-6-11-16-21-......
|
||||
novel.chapters = chapters.sort((chapterA, chapterB) => {
|
||||
if (
|
||||
chapterA.chapterNumber !== undefined &&
|
||||
chapterB.chapterNumber !== undefined
|
||||
) {
|
||||
return chapterA.chapterNumber - chapterB.chapterNumber;
|
||||
}
|
||||
if (chapterA.chapterNumber === undefined) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
const sections = $('main article div div section');
|
||||
if (sections) {
|
||||
const numberOfSection = sections.length;
|
||||
let title;
|
||||
let positionChapter = 2;
|
||||
|
||||
for (let i = 3; i <= 5; i++) {
|
||||
title = sections.eq(numberOfSection - i);
|
||||
if (title.find('h4').length !== 0) {
|
||||
positionChapter = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const chapter = sections.eq(numberOfSection - positionChapter);
|
||||
|
||||
if (title && chapter) {
|
||||
return (title.html() || '') + (chapter.html() || '');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
}
|
||||
|
||||
export default new NovhellPlugin();
|
||||
@@ -0,0 +1,275 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
class PhenixScansTradPlugin implements Plugin.PluginBase {
|
||||
id = 'phenixscans';
|
||||
name = 'PhenixScans';
|
||||
icon = 'src/fr/phenixscans/icon.png';
|
||||
site = 'https://phenixscans.fr';
|
||||
version = '1.0.1';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url);
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
|
||||
let filter = '';
|
||||
for (const key in filters) {
|
||||
if (typeof filters[key].value === 'object') {
|
||||
for (const value of filters[key].value as string[]) {
|
||||
filter += `&genre%5B%5D=${value}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const order = showLatestNovels ? 'update' : 'popular';
|
||||
const url = `${this.site}/manga/?page=${pageNo}${filter}&status=&type=novel&order=${order}`;
|
||||
|
||||
const $ = await this.getCheerio(url);
|
||||
$('div div div div a').each((i, elem) => {
|
||||
const novelName = $(elem).attr('title')?.trim();
|
||||
const novelUrl = $(elem).attr('href');
|
||||
const novelCover = $(elem).find('div img').attr('src') || defaultCover;
|
||||
|
||||
if (novelUrl && novelName) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name = $('h1[itemprop=name]').text().replace('– Novel', '').trim();
|
||||
novel.cover =
|
||||
$('div[itemprop=image] img').first().attr('src') || defaultCover;
|
||||
novel.author = $('.fmed b:contains(Auteur)+span').text().trim();
|
||||
novel.genres = $('.mgen a')
|
||||
.map(function () {
|
||||
return $(this).text();
|
||||
})
|
||||
.get()
|
||||
.join(', ');
|
||||
novel.summary = $('.entry-content[itemprop=description]').text().trim();
|
||||
novel.status = this.getStatus(
|
||||
$('.tsinfo .imptdt:contains(Statut)').text().replace('Statut', '').trim(),
|
||||
);
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$('ul li:has(div.chbox):has(div.eph-num)').each((i, elem) => {
|
||||
const chapterName = $(elem).find('a .chapternum').text().trim();
|
||||
const chapterUrl = $(elem).find('a').attr('href');
|
||||
const releaseDate = this.parseDate($(elem).find('a .chapterdate').text());
|
||||
if (chapterUrl && chapterUrl.includes(this.site) && chapterName) {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
}
|
||||
});
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
|
||||
parseDate(date: string): string {
|
||||
const monthMapping: Record<string, number> = {
|
||||
janvier: 1,
|
||||
fevrier: 2,
|
||||
mars: 3,
|
||||
avril: 4,
|
||||
mai: 5,
|
||||
juin: 6,
|
||||
juillet: 7,
|
||||
aout: 8,
|
||||
septembre: 9,
|
||||
octobre: 10,
|
||||
novembre: 11,
|
||||
decembre: 12,
|
||||
};
|
||||
|
||||
const [day, month, year] = date.split(' ');
|
||||
return dayjs(
|
||||
`${day} ${monthMapping[month.normalize('NFD').replace(/[\u0300-\u036f]/g, '')]} ${year}`,
|
||||
'D MMMM YYYY',
|
||||
).format('DD MMMM YYYY');
|
||||
}
|
||||
|
||||
getStatus(status: string) {
|
||||
const lowerCaseStatus = status.toLowerCase();
|
||||
const ongoing = ['en cours', 'en cours de publication'];
|
||||
const onhiatus = ['en pause', 'en attente'];
|
||||
const completed = ['complété', 'fini', 'achevé', 'terminé'];
|
||||
const cancelled = ['abandonné'];
|
||||
|
||||
if (ongoing.includes(lowerCaseStatus)) {
|
||||
return NovelStatus.Ongoing;
|
||||
} else if (onhiatus.includes(lowerCaseStatus)) {
|
||||
return NovelStatus.OnHiatus;
|
||||
} else if (completed.includes(lowerCaseStatus)) {
|
||||
return NovelStatus.Completed;
|
||||
} else if (cancelled.includes(lowerCaseStatus)) {
|
||||
return NovelStatus.Cancelled;
|
||||
}
|
||||
return NovelStatus.Unknown;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
return $('#readerarea').html() || '';
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1, {
|
||||
showLatestNovels: true,
|
||||
filters: undefined,
|
||||
});
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
filters = {
|
||||
genre: {
|
||||
type: FilterTypes.CheckboxGroup,
|
||||
label: 'Genre',
|
||||
value: [],
|
||||
options: [
|
||||
{ label: 'Action', value: 'action' },
|
||||
{
|
||||
label: 'Action Adventure Fantaisie Psychologique',
|
||||
value: 'action-adventure-fantaisie-psychologique',
|
||||
},
|
||||
{
|
||||
label: 'Action Arts martiaux Aventure Fantastique Surnaturel',
|
||||
value: 'action-arts-martiaux-aventure-fantastique-surnaturel',
|
||||
},
|
||||
{
|
||||
label: 'Action Aventure Fantastique',
|
||||
value: 'action-aventure-fantastique',
|
||||
},
|
||||
{ label: 'Action Drame Shônen', value: 'action-drame-shonen' },
|
||||
{ label: 'Adult', value: 'adult' },
|
||||
{ label: 'Adventure', value: 'adventure' },
|
||||
{ label: 'amitié', value: 'amitie' },
|
||||
{ label: 'amour', value: 'amour' },
|
||||
{ label: 'Art-martiaux', value: 'art-martiaux' },
|
||||
{ label: 'Arts-martiaux', value: 'arts-martiaux' },
|
||||
{ label: 'Aventure', value: 'aventure' },
|
||||
{ label: 'Combat', value: 'combat' },
|
||||
{ label: 'Comedie', value: 'comedie' },
|
||||
{ label: 'Comedy', value: 'comedy' },
|
||||
{ label: 'Demons', value: 'demons' },
|
||||
{ label: 'Dragon', value: 'dragon' },
|
||||
{ label: 'Drama', value: 'drama' },
|
||||
{ label: 'Drame', value: 'drame' },
|
||||
{ label: 'Ecchi', value: 'ecchi' },
|
||||
{ label: 'Fantaisie', value: 'fantaisie' },
|
||||
{ label: 'fantastique', value: 'fantastique' },
|
||||
{ label: 'Fantasy', value: 'fantasy' },
|
||||
{ label: 'Ghosts', value: 'ghosts' },
|
||||
{ label: 'Harem', value: 'harem' },
|
||||
{ label: 'Historical', value: 'historical' },
|
||||
{ label: 'Historique', value: 'historique' },
|
||||
{ label: 'Horreur', value: 'horreur' },
|
||||
{ label: 'Horror', value: 'horror' },
|
||||
{ label: 'Isekai', value: 'isekai' },
|
||||
{ label: 'Josei', value: 'josei' },
|
||||
{ label: 'longstrip art', value: 'longstrip-art' },
|
||||
{ label: 'Magic', value: 'magic' },
|
||||
{ label: 'Magie', value: 'magie' },
|
||||
{ label: 'Male Protagonist', value: 'male-protagonist' },
|
||||
{ label: 'manga', value: 'manga' },
|
||||
{ label: 'Manhwa', value: 'manhwa' },
|
||||
{ label: 'Manhwa Player', value: 'manhwa-player' },
|
||||
{ label: 'Manwha', value: 'manwha' },
|
||||
{ label: 'Martial Arts', value: 'martial-arts' },
|
||||
{ label: 'Mature', value: 'mature' },
|
||||
{ label: 'Monstre', value: 'monstre' },
|
||||
{ label: 'Murim', value: 'murim' },
|
||||
{ label: 'mystère', value: 'mystere' },
|
||||
{ label: 'Mystery', value: 'mystery' },
|
||||
{ label: 'Necromancien', value: 'necromancien' },
|
||||
{ label: 'necromencer', value: 'necromencer' },
|
||||
{ label: 'Novel', value: 'novel' },
|
||||
{ label: 'One Shot', value: 'one-shot' },
|
||||
{ label: 'Over Power MC', value: 'over-power-mc' },
|
||||
{ label: 'Partenaire', value: 'partenaire' },
|
||||
{ label: 'Player', value: 'player' },
|
||||
{ label: 'Player Manhwa', value: 'player-manhwa' },
|
||||
{ label: 'Portail', value: 'portail' },
|
||||
{ label: 'Psychological', value: 'psychological' },
|
||||
{ label: 'Psychologique', value: 'psychologique' },
|
||||
{ label: 'regresseur', value: 'regresseur' },
|
||||
{ label: 'régression', value: 'regression' },
|
||||
{ label: 'Réincarnation', value: 'reincarnation' },
|
||||
{ label: 'Returner', value: 'returner' },
|
||||
{ label: 'Romance', value: 'romance' },
|
||||
{ label: 'School Life', value: 'school-life' },
|
||||
{ label: 'Sci-fi', value: 'sci-fi' },
|
||||
{ label: 'Seinen', value: 'seinen' },
|
||||
{ label: 'Shôjo', value: 'shojo' },
|
||||
{ label: 'Shônen', value: 'shonen' },
|
||||
{ label: 'Shotacon', value: 'shotacon' },
|
||||
{ label: 'Shoujo', value: 'shoujo' },
|
||||
{ label: 'Shounen', value: 'shounen' },
|
||||
{ label: 'Slice of Life', value: 'slice-of-life' },
|
||||
{ label: 'Slide of Life', value: 'slide-of-life' },
|
||||
{ label: 'Smut', value: 'smut' },
|
||||
{ label: 'Sports', value: 'sports' },
|
||||
{ label: 'Supernatural', value: 'supernatural' },
|
||||
{ label: 'Surnaturel', value: 'surnaturel' },
|
||||
{ label: 'Système', value: 'systeme' },
|
||||
{ label: 'Tragédie', value: 'tragedie' },
|
||||
{ label: 'Tragedy', value: 'tragedy' },
|
||||
{ label: 'Webtoons', value: 'webtoons' },
|
||||
],
|
||||
},
|
||||
} satisfies Filters;
|
||||
}
|
||||
|
||||
export default new PhenixScansTradPlugin();
|
||||
@@ -0,0 +1,187 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
class WarriorLegendTradPlugin implements Plugin.PluginBase {
|
||||
id = 'warriorlegendtrad';
|
||||
name = 'Warrior Legend Trad';
|
||||
icon = 'src/fr/warriorlegendtrad/icon.png';
|
||||
site = 'https://warriorlegendtrad.wordpress.com';
|
||||
version = '1.0.1';
|
||||
|
||||
regexAuthors = [/Auteur\u00A0:([^\n]*)/];
|
||||
|
||||
regexGenres = [/Genre :([^\n]*)/];
|
||||
|
||||
regexSummary = [/Synopsis\u00A0:([\s\S]*)index chapitre :/i];
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url);
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 2) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
let url;
|
||||
// light novel
|
||||
if (pageNo === 1) {
|
||||
url = this.site + '/light-novel';
|
||||
}
|
||||
// Original creation
|
||||
else {
|
||||
url = this.site + '/crea';
|
||||
}
|
||||
|
||||
const $ = await this.getCheerio(url);
|
||||
$('div div div article').each((i, elem) => {
|
||||
const novelName = $(elem).find('.entry-wrapper h2').first().text().trim();
|
||||
const novelUrl = $(elem).find('.entry-wrapper h2 a').attr('href');
|
||||
const novelCover =
|
||||
$(elem).find('figure a img').attr('src') || defaultCover;
|
||||
|
||||
if (novelUrl && novelName) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name = $('.site-main article header h1').text().trim();
|
||||
novel.cover =
|
||||
$('.site-main article figure img').first().attr('src') || defaultCover;
|
||||
const entryContentText = $('.entry-content').text();
|
||||
novel.author = this.extractInfo(entryContentText, this.regexAuthors);
|
||||
novel.genres = this.extractInfo(entryContentText, this.regexGenres);
|
||||
novel.summary = this.extractInfo(entryContentText, this.regexSummary);
|
||||
novel.status = this.getStatus(entryContentText);
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
$('div div article div')
|
||||
.find('h2 a, h3 a')
|
||||
.each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
const releaseDate = dayjs(
|
||||
chapterUrl?.substring(this.site.length + 1, this.site.length + 11),
|
||||
).format('DD MMMM YYYY');
|
||||
if (chapterUrl && chapterUrl.includes(this.site) && chapterName) {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//We sort by date because the elements are not in a fixed order,
|
||||
//and then by name because there are chapters with the same dates.
|
||||
novel.chapters = chapters.sort((a, b) => {
|
||||
if (!a.releaseTime) return 1;
|
||||
if (!b.releaseTime) return -1;
|
||||
const dateA = new Date(a.releaseTime).getTime();
|
||||
const dateB = new Date(b.releaseTime).getTime();
|
||||
const dateComparison = dateA - dateB;
|
||||
if (dateComparison === 0) {
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
return dateComparison;
|
||||
});
|
||||
return novel;
|
||||
}
|
||||
|
||||
extractInfo(text: string, regexes: RegExp[]): string {
|
||||
for (const regex of regexes) {
|
||||
const match = regex.exec(text);
|
||||
if (match !== null) {
|
||||
return match[1].trim();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getStatus(text: string) {
|
||||
const regexSummary = [
|
||||
/État sur le site :([^\n]*)/i,
|
||||
/état sur le site:([^\n]*)/i,
|
||||
];
|
||||
|
||||
const status = this.extractInfo(text, regexSummary);
|
||||
if (status.includes('en cours')) {
|
||||
return NovelStatus.Ongoing;
|
||||
} else if (status.includes('en pause')) {
|
||||
return NovelStatus.OnHiatus;
|
||||
} else if (status.includes('terminé')) {
|
||||
return NovelStatus.Completed;
|
||||
} else if (status.includes('abandonné')) {
|
||||
return NovelStatus.Cancelled;
|
||||
}
|
||||
|
||||
return NovelStatus.Ongoing;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
let contenuHtml = '';
|
||||
$('.entry-content')
|
||||
.contents()
|
||||
.each(function () {
|
||||
if (
|
||||
!$.html(this)?.startsWith('<div') &&
|
||||
!$.html(this)?.startsWith('<hr') &&
|
||||
!$.html(this)?.includes('<script')
|
||||
) {
|
||||
contenuHtml += $.html(this);
|
||||
}
|
||||
});
|
||||
return contenuHtml;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
}
|
||||
|
||||
export default new WarriorLegendTradPlugin();
|
||||
@@ -0,0 +1,205 @@
|
||||
import { CheerioAPI, load } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
class WuxialnscantradPlugin implements Plugin.PluginBase {
|
||||
id = 'wuxialnscantrad';
|
||||
name = 'WuxiaLnScantrad';
|
||||
icon = 'src/fr/wuxialnscantrad/icon.png';
|
||||
site = 'https://wuxialnscantrad.wordpress.com';
|
||||
version = '1.0.0';
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
const r = await fetchApi(url, {
|
||||
headers: { 'Accept-Encoding': 'deflate' },
|
||||
});
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo > 1) return [];
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
const url = this.site;
|
||||
const $ = await this.getCheerio(url);
|
||||
$('#menu-item-2210 ul li').each((i, elem) => {
|
||||
const novelName = $(elem).first().text().trim();
|
||||
const novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
if (novelUrl && novelName) {
|
||||
novel = {
|
||||
name: novelName,
|
||||
cover: defaultCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name = $('.entry-title').text().trim();
|
||||
novel.cover =
|
||||
$('.entry-content p strong img').first().attr('src') ||
|
||||
$('.entry-content p img').first().attr('src');
|
||||
|
||||
const entryContentText = $('.entry-content').text();
|
||||
novel.author = this.getAuthor(entryContentText);
|
||||
novel.genres = this.getGenres(entryContentText);
|
||||
novel.artist = this.getArtist(entryContentText);
|
||||
novel.summary = this.getSummary(entryContentText);
|
||||
novel.status = this.getStatus(entryContentText);
|
||||
|
||||
const pathChapter = $('.entry-content ul').first().children('li');
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
pathChapter.each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).find('a').attr('href');
|
||||
if (chapterUrl && chapterUrl.includes(this.site) && chapterName) {
|
||||
const pathchapter = chapterUrl.replace(this.site, '');
|
||||
// we do not take the paths already present
|
||||
if (!chapters.some(chap => chap.path === pathchapter)) {
|
||||
const releaseDate = dayjs(
|
||||
chapterUrl?.substring(this.site.length + 1, this.site.length + 11),
|
||||
).format('DD MMMM YYYY');
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: pathchapter,
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
|
||||
getAuthor(text: string) {
|
||||
const regex = /Auteur\(s\):\s*(.*)/;
|
||||
const match = regex.exec(text);
|
||||
let author = '';
|
||||
if (match !== null) {
|
||||
author = match[1].trim();
|
||||
}
|
||||
return author;
|
||||
}
|
||||
|
||||
getGenres(text: string) {
|
||||
const regex = /Genres:\s*(.*)/;
|
||||
const match = regex.exec(text);
|
||||
let genre = '';
|
||||
if (match !== null) {
|
||||
genre = match[1].trim();
|
||||
}
|
||||
return genre;
|
||||
}
|
||||
|
||||
getArtist(text: string) {
|
||||
const regex = /Artiste\(s\):\s*(.*)Genres/;
|
||||
const match = regex.exec(text);
|
||||
let artist = '';
|
||||
if (match !== null) {
|
||||
artist = match[1].trim();
|
||||
}
|
||||
return artist;
|
||||
}
|
||||
|
||||
getSummary(text: string) {
|
||||
const regexAuthors = [
|
||||
/Synopsis :([\s\S]*)Chapitres disponibles/,
|
||||
/Sypnopsis([\s\S]*)Sypnopsis officiel/,
|
||||
/Synopsis([\s\S]*)Chapitres disponibles/,
|
||||
];
|
||||
|
||||
for (const regex of regexAuthors) {
|
||||
const match = regex.exec(text);
|
||||
if (match !== null) {
|
||||
return match[1].trim();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getStatus(text: string) {
|
||||
const regex = /Statut:\s*(.*)/;
|
||||
const match = regex.exec(text);
|
||||
let status = '';
|
||||
if (match !== null) {
|
||||
status = match[1].trim();
|
||||
}
|
||||
switch (status) {
|
||||
case 'En cours':
|
||||
return NovelStatus.Ongoing;
|
||||
case 'Arrêté':
|
||||
return NovelStatus.Cancelled;
|
||||
case 'Terminé':
|
||||
return NovelStatus.Completed;
|
||||
default:
|
||||
return NovelStatus.Ongoing;
|
||||
}
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
|
||||
let contenuHtml = '';
|
||||
$('.entry-content')
|
||||
.contents()
|
||||
.each(function () {
|
||||
if ($(this).html()?.includes('<script')) {
|
||||
return false;
|
||||
}
|
||||
//Removing tags linked to navigation and unnecessary paragraphs.
|
||||
if (
|
||||
!$(this).html()?.includes('data-attachment-id="480') &&
|
||||
!$.html(this)?.includes('<hr>') &&
|
||||
!$.html(this)?.includes('<p> </p>')
|
||||
) {
|
||||
contenuHtml += $.html(this);
|
||||
}
|
||||
});
|
||||
return contenuHtml;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
const popularNovels = this.popularNovels(1);
|
||||
|
||||
const novels = (await popularNovels).filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return novels;
|
||||
}
|
||||
}
|
||||
|
||||
export default new WuxialnscantradPlugin();
|
||||
@@ -0,0 +1,296 @@
|
||||
import { Cheerio, CheerioAPI, load, Element } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
|
||||
class XiaowazPlugin implements Plugin.PluginBase {
|
||||
id = 'xiaowaz';
|
||||
name = 'Xiaowaz';
|
||||
icon = 'src/fr/xiaowaz/icon.png';
|
||||
site = 'https://xiaowaz.fr';
|
||||
version = '1.0.1';
|
||||
static novels: Plugin.NovelItem[] | undefined;
|
||||
|
||||
async getCheerio(url: string): Promise<CheerioAPI> {
|
||||
let retries = 5; // when fetching for images the sites sometimes terminates the connection
|
||||
let returnError: any;
|
||||
while (retries > 0) {
|
||||
try {
|
||||
const r = await fetchApi(url);
|
||||
const body = await r.text();
|
||||
const $ = load(body);
|
||||
return $;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
returnError = error;
|
||||
retries--;
|
||||
// wait 1 second before retrying
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
throw new Error(returnError ? returnError : 'Error fetching the page');
|
||||
}
|
||||
|
||||
async getAllNovels(): Promise<Plugin.NovelItem[]> {
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
let novel: Plugin.NovelItem;
|
||||
const $ = await this.getCheerio(this.site);
|
||||
|
||||
const categories: Cheerio<Element>[] = [
|
||||
$('li.page_item').find('a:contains("Séries")').parent(),
|
||||
$('li.page_item').find('a:contains("Créations")').parent(),
|
||||
$('li.page_item').find('a:contains("†")').parent(),
|
||||
];
|
||||
|
||||
categories.forEach(cheerio => {
|
||||
cheerio.find('ul.children li').each((i, elem) => {
|
||||
const novelName = $(elem).first().text().trim().replace('✔', '');
|
||||
const novelUrl = $(elem).find('a').attr('href');
|
||||
|
||||
// Douluo Dalu is no good
|
||||
if (novelUrl && novelName && novelName !== 'Douluo Dalu') {
|
||||
novel = {
|
||||
name: novelName,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
novels.push(novel);
|
||||
}
|
||||
});
|
||||
});
|
||||
return novels;
|
||||
}
|
||||
|
||||
async getNovelsCovers(
|
||||
novels: Plugin.NovelItem[],
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
await Promise.all(
|
||||
novels.map(async novel => {
|
||||
const $novel = await this.getCheerio(this.site + novel.path);
|
||||
novel.cover =
|
||||
$novel('img[fetchpriority = "high"]').first().attr('src') ||
|
||||
$novel('img.aligncenter').first().attr('src') ||
|
||||
defaultCover;
|
||||
}),
|
||||
);
|
||||
return novels;
|
||||
}
|
||||
|
||||
async popularNovels(pageNo: number): Promise<Plugin.NovelItem[]> {
|
||||
const PAGE_SIZE = 5;
|
||||
|
||||
if (!XiaowazPlugin.novels) XiaowazPlugin.novels = await this.getAllNovels();
|
||||
let novels: Plugin.NovelItem[] = XiaowazPlugin.novels;
|
||||
|
||||
const totalPages = Math.ceil(novels.length / PAGE_SIZE);
|
||||
if (pageNo > totalPages) return [];
|
||||
|
||||
// splitting novel list to make fewer requests for getting images
|
||||
novels = novels.slice(PAGE_SIZE * (pageNo - 1), PAGE_SIZE * pageNo);
|
||||
|
||||
return await this.getNovelsCovers(novels);
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: 'Sans titre',
|
||||
};
|
||||
|
||||
const $ = await this.getCheerio(this.site + novelPath);
|
||||
|
||||
novel.name = $('.card_title').text().trim();
|
||||
novel.cover =
|
||||
$('img[fetchpriority = "high"]').first().attr('src') ||
|
||||
$('img.aligncenter').first().attr('src') ||
|
||||
defaultCover;
|
||||
|
||||
novel.status = NovelStatus.Ongoing;
|
||||
if (novel.name.charAt(novel.name.length - 1) === '✔') {
|
||||
novel.status = NovelStatus.Completed;
|
||||
novel.name = novel.name.slice(0, -1);
|
||||
} else if (novelPath.startsWith('/series-abandonnees')) {
|
||||
novel.status = NovelStatus.Cancelled;
|
||||
}
|
||||
|
||||
const entryContentText = $('.entry-content').text();
|
||||
novel.author = this.getAuthor(entryContentText);
|
||||
novel.genres = this.getGenres(entryContentText);
|
||||
if (novelPath.startsWith('/oeuvres-originales')) {
|
||||
novel.genres += novel.genres ? ', Oeuvre originale' : 'Oeuvre originale';
|
||||
}
|
||||
|
||||
const listeParagraphe: string[] = [];
|
||||
|
||||
const PARAGRAPH_EXCLUDE_LIST = [
|
||||
'Écrit par',
|
||||
'Ecrit par',
|
||||
'Sorties régulières',
|
||||
'Auteur\u00A0:',
|
||||
'Statut VO\u00A0:',
|
||||
'Nom utilisé\u00A0:',
|
||||
'Auteur original\u00A0:',
|
||||
'Auteur original de l’oeuvre',
|
||||
'851 chapitres en',
|
||||
'Index\u00A0:',
|
||||
];
|
||||
|
||||
$('.entry-content > p').each((index, element) => {
|
||||
const balise = $(element);
|
||||
|
||||
// remove chapter links
|
||||
if (balise.find('a[href*="xiaowaz.fr/articles"]').length !== 0)
|
||||
return false;
|
||||
|
||||
const textbalise = balise.text();
|
||||
if (PARAGRAPH_EXCLUDE_LIST.some(keyword => textbalise.includes(keyword)))
|
||||
return false;
|
||||
|
||||
if (
|
||||
!textbalise.includes('Genre') &&
|
||||
!textbalise.includes('Synopsis') &&
|
||||
//Managing the novel 'Rebirth of The Thief Who Roamed The World' to remove these three fields.
|
||||
!textbalise.includes('重生之賊行天下') &&
|
||||
!textbalise.includes('Rebirth of The Thief Who Roamed The World') &&
|
||||
!textbalise.includes(
|
||||
'Romance, Comédie, Action, VRMMO, Réincarnation, Futuriste',
|
||||
)
|
||||
)
|
||||
listeParagraphe.push(textbalise);
|
||||
});
|
||||
novel.summary = listeParagraphe.join('\n').trim();
|
||||
|
||||
//Search for chapter links within ul/li tags; otherwise, within p/a tags,
|
||||
//but not both at the same time because otherwise, on the TDG page, it redirects to a PDF download link.
|
||||
let pathChapter = $('.entry-content ul li a');
|
||||
if (pathChapter.length === 0) {
|
||||
pathChapter = $('.entry-content p a');
|
||||
}
|
||||
|
||||
const chapters: Plugin.ChapterItem[] = [];
|
||||
pathChapter.each((i, elem) => {
|
||||
const chapterName = $(elem).text().trim();
|
||||
const chapterUrl = $(elem).attr('href');
|
||||
if (chapterUrl && chapterUrl.includes(this.site) && chapterName) {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
novel.chapters = chapters;
|
||||
return novel;
|
||||
}
|
||||
|
||||
getAuthor(text: string) {
|
||||
const regexAuthors = [
|
||||
/Écrit par([^\n]*). Traduction/i,
|
||||
/Écrit par([^\n]*)./i,
|
||||
/Auteur original de l’œuvre\u00A0:([^\n]*)VO/i,
|
||||
/Auteur\u00A0:([^\n]*)sur/,
|
||||
/Auteur\u00A0:([^\n]*)/,
|
||||
/Auteure\u00A0:\u00A0([^\n]*)/,
|
||||
/Auteur original de l’oeuvre\u00A0:([^\n]*)/i,
|
||||
/Auteur original\u00A0:([^\n]*)/i,
|
||||
];
|
||||
|
||||
for (const regex of regexAuthors) {
|
||||
const match = regex.exec(text);
|
||||
if (match !== null) {
|
||||
return match[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
getGenres(text: string) {
|
||||
// We handle several cases where there are multiple spellings for the word 'genre'. Genre, Genre :, Genres, Genres:
|
||||
const regex = /Genre((?:.*?\n)*?)\s*Synopsis\s*/;
|
||||
const match = regex.exec(text);
|
||||
let genre = '';
|
||||
if (match !== null) {
|
||||
genre = match[1]
|
||||
.replace('\u00A0', ' ')
|
||||
.replace('s :', '')
|
||||
.replace(':', '')
|
||||
.trim();
|
||||
if (genre.startsWith('s\n')) {
|
||||
genre = genre.replace(/^./, '').trim();
|
||||
}
|
||||
}
|
||||
return genre;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const $ = await this.getCheerio(this.site + chapterPath);
|
||||
|
||||
const startTag = $('.wp-post-navigation');
|
||||
const endTag = $('.abh_box.abh_box_down.abh_box_business');
|
||||
|
||||
const elementsBetweenTags: string[] = [];
|
||||
let footnotesElement: string | null = null;
|
||||
|
||||
if (startTag.length > 0 && endTag.length > 0) {
|
||||
let currentElement = startTag.next();
|
||||
while (currentElement.length > 0 && !currentElement.is(endTag)) {
|
||||
if (
|
||||
currentElement.find('p > a[href="https://ko-fi.com/wazouille"]')
|
||||
.length > 0
|
||||
) {
|
||||
break;
|
||||
}
|
||||
if (currentElement.hasClass('footnote_container_prepare')) {
|
||||
footnotesElement = $.html(currentElement);
|
||||
} else {
|
||||
let htmlCurrentElement = $.html(currentElement);
|
||||
htmlCurrentElement =
|
||||
htmlCurrentElement === '<p> </p>'
|
||||
? '<p/>'
|
||||
: htmlCurrentElement;
|
||||
elementsBetweenTags.push(htmlCurrentElement);
|
||||
}
|
||||
currentElement = currentElement.next();
|
||||
}
|
||||
}
|
||||
|
||||
// Place footnotes at the end of the chapter, not at the beginning
|
||||
if (footnotesElement) {
|
||||
elementsBetweenTags.push(footnotesElement);
|
||||
}
|
||||
|
||||
return elementsBetweenTags.join('\n').trim();
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
|
||||
if (!XiaowazPlugin.novels) XiaowazPlugin.novels = await this.getAllNovels();
|
||||
const popularNovels = XiaowazPlugin.novels;
|
||||
|
||||
// Normalize the text to remove accents and other special characters
|
||||
// This ensures that the search term and novel names are compared accurately
|
||||
const novels = popularNovels.filter(novel =>
|
||||
novel.name
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim()
|
||||
.includes(
|
||||
searchTerm
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
return await this.getNovelsCovers(novels);
|
||||
}
|
||||
}
|
||||
|
||||
export default new XiaowazPlugin();
|
||||
Reference in New Issue
Block a user