Re:Library fix (#1813)
* Re:Library: - all tags allowed in chapter text (#1788) - better status - fix genres - fix images - fix search * remove unused import statements in ReLibrary plugin
This commit is contained in:
@@ -4,7 +4,7 @@ import { Filters } from '@libs/filterInputs';
|
|||||||
import { load as loadCheerio } from 'cheerio';
|
import { load as loadCheerio } from 'cheerio';
|
||||||
import { defaultCover } from '@libs/defaultCover';
|
import { defaultCover } from '@libs/defaultCover';
|
||||||
import { NovelItem } from '../../test_web/static/js';
|
import { NovelItem } from '../../test_web/static/js';
|
||||||
// import { isUrlAbsolute } from "@libs/isAbsoluteUrl";
|
import { NovelStatus } from '@libs/novelStatus';
|
||||||
|
|
||||||
type FuzzySearchOptions = {
|
type FuzzySearchOptions = {
|
||||||
caseSensitive: boolean;
|
caseSensitive: boolean;
|
||||||
@@ -164,7 +164,12 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
name = 'Re:Library';
|
name = 'Re:Library';
|
||||||
icon = 'src/en/relibrary/icon.png';
|
icon = 'src/en/relibrary/icon.png';
|
||||||
site = 'https://re-library.com';
|
site = 'https://re-library.com';
|
||||||
version = '1.0.1';
|
version = '1.0.2';
|
||||||
|
imageRequestInit: Plugin.ImageRequestInit = {
|
||||||
|
headers: {
|
||||||
|
Referer: 'https://re-library.com/',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
private searchFunc = new FuzzySearch<Plugin.NovelItem>(item => [item.name], {
|
private searchFunc = new FuzzySearch<Plugin.NovelItem>(item => [item.name], {
|
||||||
sort: true,
|
sort: true,
|
||||||
@@ -187,7 +192,11 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
novel.cover =
|
novel.cover =
|
||||||
loadedCheerio(el)
|
loadedCheerio(el)
|
||||||
.find('table > tbody > tr > td > a > img')
|
.find('table > tbody > tr > td > a > img')
|
||||||
.attr('src') || defaultCover;
|
.attr('data-cfsrc') ||
|
||||||
|
loadedCheerio(el)
|
||||||
|
.find('table > tbody > tr > td > a > img')
|
||||||
|
.attr('src') ||
|
||||||
|
defaultCover;
|
||||||
if (novel.path.startsWith(this.site)) {
|
if (novel.path.startsWith(this.site)) {
|
||||||
novel.path = novel.path.slice(this.site.length);
|
novel.path = novel.path.slice(this.site.length);
|
||||||
}
|
}
|
||||||
@@ -210,7 +219,11 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
novel.cover =
|
novel.cover =
|
||||||
loadedCheerio(el)
|
loadedCheerio(el)
|
||||||
.find('.entry-content > table > tbody > tr > td > a >img')
|
.find('.entry-content > table > tbody > tr > td > a >img')
|
||||||
.attr('src') || defaultCover;
|
.attr('data-cfsrc') ||
|
||||||
|
loadedCheerio(el)
|
||||||
|
.find('.entry-content > table > tbody > tr > td > a >img')
|
||||||
|
.attr('src') ||
|
||||||
|
defaultCover;
|
||||||
if (novel.path.startsWith(this.site)) {
|
if (novel.path.startsWith(this.site)) {
|
||||||
novel.path = novel.path.slice(this.site.length);
|
novel.path = novel.path.slice(this.site.length);
|
||||||
}
|
}
|
||||||
@@ -259,26 +272,15 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
|
|
||||||
// Find the cover
|
// Find the cover
|
||||||
novel.cover =
|
novel.cover =
|
||||||
loadedCheerio('.entry-content > table > tbody > tr > td > img').attr(
|
loadedCheerio('.entry-content > table img').attr('data-cfsrc') ||
|
||||||
'src',
|
loadedCheerio('.entry-content > table img').attr('src') ||
|
||||||
) || defaultCover;
|
defaultCover;
|
||||||
|
|
||||||
// Genres in comma separated "list"
|
novel.status = NovelStatus.Unknown;
|
||||||
novel.genres = (() => {
|
|
||||||
const genres: string[] = [];
|
|
||||||
loadedCheerio(
|
|
||||||
'.entry-content > table > tbody > tr > td > p > span > a',
|
|
||||||
).each((_i, el) => {
|
|
||||||
genres.push(loadedCheerio(el).text().trim());
|
|
||||||
});
|
|
||||||
return genres.join(', ');
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Handle the novel status
|
|
||||||
// Sadly some novels just state the status inside the summary...
|
|
||||||
// I don't even know if the snippet here works for *most* of the novels preset, or only for a few
|
|
||||||
loadedCheerio('.entry-content > table > tbody > tr > td > p').each(
|
loadedCheerio('.entry-content > table > tbody > tr > td > p').each(
|
||||||
function (_i, el) {
|
function (_i, el) {
|
||||||
|
// Handle the novel status
|
||||||
|
// Sadly some novels just state the status inside the summary...
|
||||||
if (
|
if (
|
||||||
loadedCheerio(el)
|
loadedCheerio(el)
|
||||||
.find('strong')
|
.find('strong')
|
||||||
@@ -288,7 +290,30 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
.startsWith('status')
|
.startsWith('status')
|
||||||
) {
|
) {
|
||||||
loadedCheerio(el).find('strong').remove();
|
loadedCheerio(el).find('strong').remove();
|
||||||
novel.status = loadedCheerio(el).text();
|
let status = loadedCheerio(el).text().toLowerCase().trim();
|
||||||
|
if (status.includes('on-going')) {
|
||||||
|
novel.status = NovelStatus.Ongoing;
|
||||||
|
} else if (status.includes('completed')) {
|
||||||
|
novel.status = NovelStatus.Completed;
|
||||||
|
} else if (status.includes('hiatus')) {
|
||||||
|
novel.status = NovelStatus.OnHiatus;
|
||||||
|
} else if (status.includes('cancelled')) {
|
||||||
|
novel.status = NovelStatus.Cancelled;
|
||||||
|
} else {
|
||||||
|
novel.status = loadCheerio(el).text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle the genres
|
||||||
|
else if (
|
||||||
|
loadedCheerio(el)
|
||||||
|
.find('strong')
|
||||||
|
.text()
|
||||||
|
.toLowerCase()
|
||||||
|
.trim()
|
||||||
|
.startsWith('Category')
|
||||||
|
) {
|
||||||
|
loadedCheerio(el).find('strong').remove();
|
||||||
|
novel.genres = loadedCheerio(el).text();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -334,20 +359,38 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
const body = await result.text();
|
const body = await result.text();
|
||||||
|
|
||||||
const loadedCheerio = loadCheerio(body);
|
const loadedCheerio = loadCheerio(body);
|
||||||
const text: string[] = [];
|
|
||||||
loadedCheerio('.entry-content > p')
|
const entryContent = loadedCheerio('.entry-content');
|
||||||
.slice(1)
|
const pageLinkHr = entryContent.find('.PageLink + hr').first();
|
||||||
.each((_i, el) => {
|
if (pageLinkHr.length) {
|
||||||
loadedCheerio(el).find('span').remove();
|
// Remove all previous siblings before the .PageLink + hr
|
||||||
const t = loadedCheerio(el).html();
|
let prev = pageLinkHr.prev();
|
||||||
if (t === undefined) return;
|
while (prev.length) {
|
||||||
text.push(`<p>${t}</p>`);
|
prev.remove();
|
||||||
});
|
prev = pageLinkHr.prev();
|
||||||
if (text.length == 0)
|
}
|
||||||
throw new Error(
|
const pageLink = pageLinkHr.prev('.PageLink');
|
||||||
`Invalid Parsing of chapter, couldn't find any text for url "${this.site}/${chapterPath}"`,
|
if (pageLink.length) {
|
||||||
);
|
pageLink.remove();
|
||||||
return text.join('');
|
}
|
||||||
|
pageLinkHr.next().remove();
|
||||||
|
pageLinkHr.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the first <hr> followed by a .PageLink and remove everything after
|
||||||
|
const hrAfterPageLink = entryContent.find('hr + .PageLink').first();
|
||||||
|
if (hrAfterPageLink.length) {
|
||||||
|
let next = hrAfterPageLink.next();
|
||||||
|
while (next.length) {
|
||||||
|
const temp = next.next();
|
||||||
|
next.remove();
|
||||||
|
next = temp;
|
||||||
|
}
|
||||||
|
hrAfterPageLink.prev().remove();
|
||||||
|
hrAfterPageLink.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
return entryContent.html() || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchNovels(
|
async searchNovels(
|
||||||
@@ -363,14 +406,17 @@ class ReLibraryPlugin implements Plugin.PluginBase {
|
|||||||
|
|
||||||
const loadedCheerio = loadCheerio(body);
|
const loadedCheerio = loadCheerio(body);
|
||||||
|
|
||||||
loadedCheerio('.entry-content table a').each((_i, el) => {
|
loadedCheerio('article article').each((_i, el) => {
|
||||||
const e = loadedCheerio(el);
|
const e = loadedCheerio(el);
|
||||||
if (e && e.attr('href') && e.text()) {
|
if (e.find('a').attr('href') && e.find('a').text()) {
|
||||||
let path = e.attr('href')!;
|
novels.push({
|
||||||
if (path.startsWith(this.site)) {
|
name: e.find('h4').text(),
|
||||||
path = path.slice(this.site.length);
|
path: e.find('a').attr('href')?.replace(this.site, '') || '',
|
||||||
}
|
cover:
|
||||||
novels.push({ name: e.text(), path: path, cover: defaultCover });
|
e.find('img').attr('data-cfsrc') ||
|
||||||
|
e.find('img').attr('src') ||
|
||||||
|
defaultCover,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.searchFunc.setHaystack(novels);
|
this.searchFunc.setHaystack(novels);
|
||||||
|
|||||||
Reference in New Issue
Block a user