Update multisrc (madara & mtlnovel) (#1023)
* Madara: - fix foxaholic infinite loop on premium chapters - genre, author and status fix for foxaholic - remove iframe from summary on foxaholic - defaultCover when viewing novels - parseData actually working * added mtlnovel multisrc for more languages
This commit is contained in:
@@ -39,7 +39,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||
this.version = `1.0.${1 + versionIncrements}`;
|
||||
this.version = `1.0.${2 + versionIncrements}`;
|
||||
this.options = metadata.options;
|
||||
this.filters = metadata.filters;
|
||||
}
|
||||
@@ -126,7 +126,8 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
const novelCover =
|
||||
image.attr('data-src') ||
|
||||
image.attr('src') ||
|
||||
image.attr('data-lazy-srcset');
|
||||
image.attr('data-lazy-srcset') ||
|
||||
defaultCover;
|
||||
const novel: Plugin.NovelItem = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
@@ -182,17 +183,22 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
|
||||
switch (detailName) {
|
||||
case 'Genre(s)':
|
||||
case 'Genre':
|
||||
case 'Tags':
|
||||
case 'Género(s)':
|
||||
case 'التصنيفات':
|
||||
novel.genres = detail;
|
||||
if (novel.genres) novel.genres += ', ' + detail;
|
||||
else novel.genres = detail;
|
||||
break;
|
||||
case 'Author(s)':
|
||||
case 'Author':
|
||||
case 'Autor(es)':
|
||||
case 'المؤلف':
|
||||
case 'المؤلف (ين)':
|
||||
novel.author = detail;
|
||||
break;
|
||||
case 'Status':
|
||||
case 'Novel':
|
||||
case 'Estado':
|
||||
novel.status =
|
||||
detail.includes('OnGoing') || detail.includes('مستمرة')
|
||||
@@ -202,7 +208,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
});
|
||||
|
||||
loadedCheerio('div.summary__content .code-block,script').remove();
|
||||
loadedCheerio('div.summary__content .code-block,script,noscript').remove();
|
||||
const summary =
|
||||
loadedCheerio('div.summary__content') ||
|
||||
loadedCheerio('#tab-manga-about') ||
|
||||
@@ -252,12 +258,14 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
|
||||
const chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
|
||||
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(/https?:\/\/.*?\//, '/'),
|
||||
releaseTime: releaseDate || null,
|
||||
chapterNumber: totalChapters - chapterIndex,
|
||||
});
|
||||
if (chapterUrl && chapterUrl != '#') {
|
||||
chapters.push({
|
||||
name: chapterName,
|
||||
path: chapterUrl.replace(/https?:\/\/.*?\//, '/'),
|
||||
releaseTime: releaseDate || null,
|
||||
chapterNumber: totalChapters - chapterIndex,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
novel.chapters = chapters.reverse();
|
||||
@@ -295,14 +303,14 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
|
||||
parseData = (date: string) => {
|
||||
const dayJSDate = dayjs(); // today
|
||||
let dayJSDate = dayjs(); // today
|
||||
const timeAgo = date.match(/\d+/)?.[0] || '';
|
||||
const timeAgoInt = parseInt(timeAgo, 10);
|
||||
|
||||
if (!timeAgo) return date; // there is no number!
|
||||
|
||||
if (includesAny(date, ['detik', 'segundo', 'second', 'วินาที'])) {
|
||||
dayJSDate.subtract(timeAgoInt, 'second'); // go back N seconds
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'second'); // go back N seconds
|
||||
} else if (
|
||||
includesAny(date, [
|
||||
'menit',
|
||||
@@ -314,7 +322,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
'دقائق',
|
||||
])
|
||||
) {
|
||||
dayJSDate.subtract(timeAgoInt, 'minute'); // go back N minute
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'minute'); // go back N minute
|
||||
} else if (
|
||||
includesAny(date, [
|
||||
'jam',
|
||||
@@ -329,7 +337,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
'小时',
|
||||
])
|
||||
) {
|
||||
dayJSDate.subtract(timeAgoInt, 'hours'); // go back N hours
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'hours'); // go back N hours
|
||||
} else if (
|
||||
includesAny(date, [
|
||||
'hari',
|
||||
@@ -345,14 +353,17 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
'天',
|
||||
])
|
||||
) {
|
||||
dayJSDate.subtract(timeAgoInt, 'days'); // go back N days
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'days'); // go back N days
|
||||
} else if (includesAny(date, ['week', 'semana'])) {
|
||||
dayJSDate.subtract(timeAgoInt, 'week'); // go back N a week
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'week'); // go back N a week
|
||||
} else if (includesAny(date, ['month', 'mes'])) {
|
||||
dayJSDate.subtract(timeAgoInt, 'month'); // go back N months
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'month'); // go back N months
|
||||
} else if (includesAny(date, ['year', 'año'])) {
|
||||
dayJSDate.subtract(timeAgoInt, 'year'); // go back N years
|
||||
dayJSDate = dayJSDate.subtract(timeAgoInt, 'year'); // go back N years
|
||||
} else {
|
||||
if (dayjs(date).format('LL') !== 'Invalid Date') {
|
||||
return dayjs(date).format('LL');
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"order": {
|
||||
"value": "view",
|
||||
"label": "Order by",
|
||||
"options": [
|
||||
{ "label": "Date", "value": "date" },
|
||||
{ "label": "Name", "value": "name" },
|
||||
{ "label": "Rating", "value": "rating" },
|
||||
{ "label": "View", "value": "view" }
|
||||
],
|
||||
"type": "Picker"
|
||||
},
|
||||
"sort": {
|
||||
"value": "desc",
|
||||
"label": "Sort by",
|
||||
"options": [
|
||||
{ "label": "Descending", "value": "desc" },
|
||||
{ "label": "Ascending", "value": "asc" }
|
||||
],
|
||||
"type": "Picker"
|
||||
},
|
||||
"storyStatus": {
|
||||
"value": "all",
|
||||
"label": "Status",
|
||||
"options": [
|
||||
{ "label": "All", "value": "all" },
|
||||
{ "label": "Ongoing", "value": "ongoing" },
|
||||
{ "label": "Complete", "value": "completed" }
|
||||
],
|
||||
"type": "Picker"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import list from './sources.json' with { type: 'json' };
|
||||
import { readFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
export const generateAll = function () {
|
||||
list.sort((a, b) => a.id.length - b.id.length);
|
||||
return list.map(source => {
|
||||
try {
|
||||
const filters = JSON.parse(
|
||||
readFileSync(`${__dirname}/filters/mtlnovel.json`, 'utf-8'),
|
||||
);
|
||||
source.filters = filters;
|
||||
} catch (e) {}
|
||||
console.log(
|
||||
`[mtlnovel] Generating: ${source.id}`.padEnd(35),
|
||||
source.filters ? '🔎with filters🔍' : '🚫 no filters 🚫',
|
||||
);
|
||||
return generator(source);
|
||||
});
|
||||
};
|
||||
|
||||
const generator = function generator(source) {
|
||||
const MTLNovelTemplate = readFileSync(__dirname + '/template.ts', {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
const pluginScript = `
|
||||
${MTLNovelTemplate}
|
||||
|
||||
const plugin = new MTLNovelPlugin(${JSON.stringify(source)});
|
||||
export default plugin;
|
||||
`.trim();
|
||||
|
||||
return {
|
||||
lang: source.options?.lang || 'English',
|
||||
filename: source.sourceName,
|
||||
pluginScript,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"id": "mtlnovel",
|
||||
"sourceSite": "https://www.mtlnovel.com/",
|
||||
"sourceName": "MTL Novel",
|
||||
"options": {
|
||||
"lang": "English"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "mtlnovel-fr",
|
||||
"sourceSite": "https://fr.mtlnovel.com/",
|
||||
"sourceName": "MTL Novel",
|
||||
"options": {
|
||||
"lang": "French"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "mtlnovel-es",
|
||||
"sourceSite": "https://es.mtlnovel.com/",
|
||||
"sourceName": "MTL Novel",
|
||||
"options": {
|
||||
"lang": "Spanish"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "mtlnovel-id",
|
||||
"sourceSite": "https://id.mtlnovel.com/",
|
||||
"sourceName": "MTL Novel",
|
||||
"options": {
|
||||
"lang": "Indonesian"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,199 @@
|
||||
import { load as parseHTML } from 'cheerio';
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { NovelStatus } from '@libs/novelStatus';
|
||||
import { defaultCover } from '@libs/defaultCover';
|
||||
import { Filters } from '@libs/filterInputs';
|
||||
|
||||
interface MTLNovelOptions {
|
||||
lang?: string;
|
||||
}
|
||||
|
||||
export interface MTLNovelMetadata {
|
||||
id: string;
|
||||
sourceSite: string;
|
||||
sourceName: string;
|
||||
options?: MTLNovelOptions;
|
||||
filters?: any;
|
||||
}
|
||||
|
||||
class MTLNovelPlugin implements Plugin.PluginBase {
|
||||
id: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
site: string;
|
||||
version: string;
|
||||
options?: MTLNovelOptions;
|
||||
filters?: Filters;
|
||||
|
||||
constructor(metadata: MTLNovelMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = 'multisrc/mtlnovel/mtlnovel/icon.png';
|
||||
this.site = metadata.sourceSite;
|
||||
this.version = '1.1.0';
|
||||
this.options = metadata.options ?? ({} as MTLNovelOptions);
|
||||
this.filters = metadata.filters satisfies Filters;
|
||||
}
|
||||
|
||||
async safeFecth(
|
||||
url: string,
|
||||
headers: Headers = new Headers(),
|
||||
): Promise<Response> {
|
||||
headers.append('Alt-Used', 'www.mtlnovel.com');
|
||||
const r = await fetchApi(url, { headers });
|
||||
if (!r.ok)
|
||||
throw new Error(
|
||||
'Could not reach site (' + r.status + ') try to open in webview.',
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
page: number,
|
||||
{
|
||||
filters,
|
||||
showLatestNovels,
|
||||
}: Plugin.PopularNovelsOptions<typeof this.filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let link = `${this.site}novel-list/?`;
|
||||
if (filters) {
|
||||
link += `orderby=${filters.order.value}`;
|
||||
link += `&order=${filters.sort.value}`;
|
||||
link += `&status=${filters.storyStatus.value}`;
|
||||
}
|
||||
if (showLatestNovels) link += '&m_orderby=date';
|
||||
link += `&pg=${page}`;
|
||||
|
||||
const body = await this.safeFecth(link).then(r => r.text());
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
|
||||
loadedCheerio('div.box.wide').each((i, el) => {
|
||||
const novelName = loadedCheerio(el).find('a.list-title').text().trim();
|
||||
let novelCover = loadedCheerio(el).find('amp-img').attr('src');
|
||||
if (
|
||||
!novelCover ||
|
||||
novelCover == 'https://www.mtlnovel.net/no-image.jpg.webp'
|
||||
) {
|
||||
novelCover = defaultCover;
|
||||
}
|
||||
const novelUrl = loadedCheerio(el).find('a.list-title').attr('href');
|
||||
|
||||
if (!novelUrl) return;
|
||||
|
||||
const novel = {
|
||||
name: novelName,
|
||||
cover: novelCover,
|
||||
path: novelUrl.replace(this.site, ''),
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const headers = new Headers();
|
||||
headers.append('Referer', `${this.site}novel-list/`);
|
||||
|
||||
const body = await this.safeFecth(this.site + novelPath, headers).then(r =>
|
||||
r.text(),
|
||||
);
|
||||
|
||||
let loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
path: novelPath,
|
||||
name: loadedCheerio('h1.entry-title').text() || 'Untitled',
|
||||
cover: loadedCheerio('.nov-head > amp-img').attr('src'),
|
||||
summary: loadedCheerio('div.desc > h2').next().text().trim(),
|
||||
author: loadedCheerio('#author').text(),
|
||||
status: loadedCheerio('#status').text(),
|
||||
genres: loadedCheerio('#genre').text().replace(/\s+/g, ''),
|
||||
chapters: [],
|
||||
};
|
||||
|
||||
const chapterListUrl = this.site + novelPath + 'chapter-list/';
|
||||
|
||||
const getChapters = async () => {
|
||||
const listBody = await this.safeFecth(chapterListUrl, headers).then(r =>
|
||||
r.text(),
|
||||
);
|
||||
|
||||
loadedCheerio = parseHTML(listBody);
|
||||
|
||||
const chapter: Plugin.ChapterItem[] = [];
|
||||
|
||||
loadedCheerio('div.ch-list')
|
||||
.find('a.ch-link')
|
||||
.each((i, el) => {
|
||||
const chapterName = loadedCheerio(el).text().replace('~ ', '');
|
||||
const releaseDate = null;
|
||||
const chapterUrl = loadedCheerio(el).attr('href');
|
||||
if (!chapterUrl) return;
|
||||
chapter.push({
|
||||
path: chapterUrl.replace(this.site, ''),
|
||||
name: chapterName,
|
||||
releaseTime: releaseDate,
|
||||
});
|
||||
});
|
||||
return chapter.reverse();
|
||||
};
|
||||
|
||||
novel.chapters = await getChapters();
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const body = await this.safeFecth(this.site + chapterPath).then(r =>
|
||||
r.text(),
|
||||
);
|
||||
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const chapterText = loadedCheerio('div.par').html() || '';
|
||||
|
||||
return chapterText;
|
||||
}
|
||||
|
||||
async searchNovels(
|
||||
searchTerm: string,
|
||||
pageNo: number,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
if (pageNo !== 1) return [];
|
||||
const searchUrl =
|
||||
this.site + 'wp-admin/admin-ajax.php?action=autosuggest&q=' + searchTerm;
|
||||
|
||||
const res = await this.safeFecth(searchUrl);
|
||||
const result = await res.json();
|
||||
|
||||
const novels: Plugin.NovelItem[] = [];
|
||||
interface SearchEntry {
|
||||
title: string;
|
||||
thumbnail: string;
|
||||
permalink: string;
|
||||
}
|
||||
result.items[0].results.map((item: SearchEntry) => {
|
||||
const novelName = item.title.replace(/<\/?strong>/g, '');
|
||||
const novelCover = item.thumbnail;
|
||||
const novelUrl = item.permalink.replace(this.site, '');
|
||||
|
||||
const novel = { name: novelName, cover: novelCover, path: novelUrl };
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
return novels;
|
||||
}
|
||||
|
||||
imageRequestInit: Plugin.ImageRequestInit = {
|
||||
headers: {
|
||||
'Alt-Used': 'www.mtlnovel.com',
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user