refactor: Classes for Plugins (#631)

* set target to ES5

* refactor types

* use .gitkeep

* use dot to make dist/js dirs on top

* add hako

* add Hako

* add madara

* fix: url path js -> .js

* fix: branch

* freestyle for using UA, cookie

* add parseNovels for Hako

* update readme

* fix: conflict types

* add Kolnovel, remove node-fetch

* add bestlightnovel

* add plugins

* WQMangaStreamScraper
* PandaMTL
* NobleMTL
* LightNovelBrasil
* WPMangaStream

* add filters for popularNovels

* fix undefined json

* Linovelib (#26)

* linovelib CN

* icon for linovelib

* fix undefined chapter

* add check

* fix: add artist

* TuNovelaLigera ES + Madara Fix (#28)

* app repo test

* POST is now working

* update madara template + run generator

* template fix didnt get pushed commited idk why

* template update POST

* generated

* fix: useNewChapterEndpoint update (#29)

* useNewChapterEndpoint update

* Update Selectors

---------

Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
This commit is contained in:
nyagami
2023-11-04 17:15:49 +07:00
committed by GitHub
parent 538841ddee
commit 20efcf404c
295 changed files with 67636 additions and 57286 deletions
View File
+236 -197
View File
@@ -1,213 +1,252 @@
import { fetchApi, fetchFile } from "@libs/fetch";
import { Filter } from "@libs/filterInputs";
import { Plugin } from '@typings/plugin'
import { load as parseHTML } from "cheerio";
import { fetchFile, fetchApi } from "@libs/fetch";
import { Novel, Plugin, Chapter } from "@typings/plugin";
import { FilterInputs } from "@libs/filterInputs";
import { defaultCover } from "@libs/defaultCover";
import { NovelStatus } from "@libs/novelStatus"
import { NovelStatus } from "@libs/novelStatus";
import { parseMadaraDate } from "@libs/parseMadaraDate";
import dayjs from "dayjs";
export const id = "turkcelightnovels";
export const name = "TurkceLightNovels [madara]";
export const icon = "multisrc/madara/icons/turkcelightnovels.png";
export const version = "1.0.0";
export const site = "https://turkcelightnovels.com/";
const baseUrl = site;
interface MadaraOptionPath{
genres?: string,
novels?: string,
novel?: string,
chapter?: string,
}
export const popularNovels: Plugin.popularNovels = async (pageNo, {filters, showLatestNovels}) => {
const novels: Novel.Item[] = [];
const MadaraDefaultPath: MadaraOptionPath = {
novels: 'novel',
novel: 'novel',
chapter: 'novel'
}
let url = site;
interface MadaraOptions {
useNewChapterEndpoint?: boolean,
path?: MadaraOptionPath,
lang?: string,
orderBy?: string
}
if (filters?.genres) {
url += "novel-genre/" + filters.genres + '/';
} else {
url += "light-novel/";
export interface MadaraMetadata {
id: string,
sourceSite: string,
sourceName: string,
options?: MadaraOptions,
filters?: Filter[],
}
class MadaraPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
options?: MadaraOptions;
filter?: Filter[] | undefined;
constructor(metadata: MadaraMetadata){
this.id = metadata.id;
this.name = metadata.sourceName + "[madara]";
const iconFileName = metadata.sourceName.replace(/\s+/g, "").toLowerCase();
this.icon = `multisrc/madara/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.options = metadata.options;
this.filter = metadata.filters;
}
async popularNovels(pageNo: number, {filters, showLatestNovels}: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
url += '/page/' + pageNo + '/' +
'?m_orderby=' + (showLatestNovels ? 'latest' : (filters?.sort || 'rating'));
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this).find('.post-title')
.find('a')
.attr('href') || '';
const novel: Novel.Item = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const parseNovelAndChapters: Plugin.parseNovelAndChapters = async (
novelUrl
) => {
const novel: Novel.instance = {
url: novelUrl,
};
const body = await fetchApi(novelUrl).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
novel.name = loadedCheerio('.post-title h1').text().trim();
novel.cover =
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case 'Genre(s)':
case 'التصنيفات':
novel.genres = detail.replace(/[\t\n]/g, ',');
break;
case 'Author(s)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case 'Status':
case 'الحالة':
novel.status =
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary = loadedCheerio('div.summary__content').text().trim();
let html;
if (false) {
const novelId =
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') || '';
const body = {
action: "manga_get_chapters",
manga: novelId,
}
html = await fetchApi(
baseUrl + 'wp-admin/admin-ajax.php',
{
method: 'POST',
body: JSON.stringify(body),
})
.then(res => res.text());
} else {
html = await fetchApi(
baseUrl + 'ajax/chapters/',
{ method: 'POST' })
.then(res => res.text());
}
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const chapters: Chapter.Item[] = [];
loadedCheerio('.wp-manga-chapter').each(function () {
const chapterName = loadedCheerio(this).find('a').text().trim();
let releaseDate = null;
releaseDate = loadedCheerio(this)
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = parseMadaraDate(releaseDate);
let url = this.site;
if (filters?.genres && this.options?.path?.genres) {
url += this.options?.path?.genres + filters.genres + '/';
} else {
/**
* Insert current date
*/
releaseDate = dayjs().format('LL');
url += this.options?.path?.novels ? this.options.path.novels : MadaraDefaultPath.novels;
}
url += '/page/' + pageNo + '/' +
'?m_orderby=' + (showLatestNovels ? 'latest' : (filters?.sort || 'rating'));
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this).find('.post-title')
.find('a')
.attr('href') || '';
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
}
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const novel: Plugin.SourceNovel = {
url: novelUrl,
};
const body = await fetchApi(novelUrl).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges, #manga-title span').remove();
novel.name =
loadedCheerio('.post-title h1').text().trim() ||
loadedCheerio('#manga-title h1').text();
novel.cover =
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case 'Genre(s)':
case 'التصنيفات':
novel.genres = detail.replace(/[\\t\\n]/g, ',');
break;
case 'Author(s)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case 'Status':
case 'الحالة':
novel.status =
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary =
loadedCheerio('div.summary__content').text().trim() ||
loadedCheerio('#tab-manga-about').text().trim() ||
loadedCheerio('.post-content_item h5:contains("Summary")').next().text().trim();
let html;
if (this.options?.useNewChapterEndpoint !== true) {
const novelId =
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') || '';
const formData = new FormData()
formData.append("action", "manga_get_chapters");
formData.append("manga", novelId);
let chapterUrl = loadedCheerio(this).find('a').attr('href') || '';
html = await fetchApi(
this.site + 'wp-admin/admin-ajax.php',
{
method: 'POST',
body: formData,
})
.then(res => res.text());
} else {
html = await fetchApi(
novelUrl + 'ajax/chapters/',
{ method: 'POST' })
.then(res => res.text());
}
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio('.wp-manga-chapter').each(function () {
const chapterName = loadedCheerio(this).find('a').text().trim();
let releaseDate = null;
releaseDate = loadedCheerio(this)
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = parseMadaraDate(releaseDate);
} else {
/**
* Insert current date
*/
releaseDate = dayjs().format('LL');
}
let chapterUrl = loadedCheerio(this).find('a').attr('href') || '';
chapters.push({ name: chapterName, releaseTime: releaseDate, url: chapterUrl });
});
novel.chapters = chapters.reverse();
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const body = await fetchApi(chapterUrl).then(res => res.text());
chapters.push({ name: chapterName, releaseTime: releaseDate, url: chapterUrl });
});
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html() || "";
novel.chapters = chapters.reverse();
return novel;
};
export const parseChapter: Plugin.parseChapter = async (chapterUrl) => {
const url = baseUrl + "/" + "light-novel" + "/" + chapterUrl;
const body = await fetchApi(chapterUrl).then(res => res.text());
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html();
return chapterText;
};
export const searchNovels: Plugin.searchNovels = async (searchTerm) => {
const novels: Novel.Item[] = [];
const url = baseUrl + "?s=" + searchTerm + "&post_type=wp-manga";
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.c-tabs-item__content').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this)
.find('.post-title')
.find('a')
.attr('href') || '';
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const fetchImage: Plugin.fetchImage = async (url) => {
return await fetchFile(url);
};
export const filters = [{"key":"sort","label":"Order by","values":[{"label":"Rating","value":"rating"},{"label":"A-Z","value":"alphabet"},{"label":"Latest","value":"latest"},{"label":"Most Views","value":"views"},{"label":"New","value":"new-manga"},{"label":"Trending","value":"trending"}],"inputType":FilterInputs.Picker}];
return chapterText;
}
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const url = this.site + "?s=" + searchTerm + "&post_type=wp-manga";
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.c-tabs-item__content').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this)
.find('.post-title')
.find('a')
.attr('href') || '';
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
}
async fetchImage(url: string): Promise<string | undefined> {
return await fetchFile(url, {});
}
}
const plugin = new MadaraPlugin({"id":"turkcelightnovels","sourceSite":"https://turkcelightnovels.com/","sourceName":"TurkceLightNovels","filters":[{"key":"sort","label":"Order by","values":[{"label":"Rating","value":"rating"},{"label":"A-Z","value":"alphabet"},{"label":"Latest","value":"latest"},{"label":"Most Views","value":"views"},{"label":"New","value":"new-manga"},{"label":"Trending","value":"trending"}],"inputType":"Picker"}],"options":{"path":{"novels":"light-novel","novel":"light-novel","chapter":"light-novel"},"lang":"Turkish"}});
export default plugin;
+236 -197
View File
@@ -1,213 +1,252 @@
import { fetchApi, fetchFile } from "@libs/fetch";
import { Filter } from "@libs/filterInputs";
import { Plugin } from '@typings/plugin'
import { load as parseHTML } from "cheerio";
import { fetchFile, fetchApi } from "@libs/fetch";
import { Novel, Plugin, Chapter } from "@typings/plugin";
import { FilterInputs } from "@libs/filterInputs";
import { defaultCover } from "@libs/defaultCover";
import { NovelStatus } from "@libs/novelStatus"
import { NovelStatus } from "@libs/novelStatus";
import { parseMadaraDate } from "@libs/parseMadaraDate";
import dayjs from "dayjs";
export const id = "webnoveloku";
export const name = "WebNovelOku [madara]";
export const icon = "multisrc/madara/icons/webnoveloku.png";
export const version = "1.0.0";
export const site = "https://www.webnoveloku.com/";
const baseUrl = site;
interface MadaraOptionPath{
genres?: string,
novels?: string,
novel?: string,
chapter?: string,
}
export const popularNovels: Plugin.popularNovels = async (pageNo, {filters, showLatestNovels}) => {
const novels: Novel.Item[] = [];
const MadaraDefaultPath: MadaraOptionPath = {
novels: 'novel',
novel: 'novel',
chapter: 'novel'
}
let url = site;
interface MadaraOptions {
useNewChapterEndpoint?: boolean,
path?: MadaraOptionPath,
lang?: string,
orderBy?: string
}
if (filters?.genres) {
url += "novel-genre/" + filters.genres + '/';
} else {
url += "novel/";
export interface MadaraMetadata {
id: string,
sourceSite: string,
sourceName: string,
options?: MadaraOptions,
filters?: Filter[],
}
class MadaraPlugin implements Plugin.PluginBase {
id: string;
name: string;
icon: string;
site: string;
version: string;
userAgent: string;
cookieString: string;
options?: MadaraOptions;
filter?: Filter[] | undefined;
constructor(metadata: MadaraMetadata){
this.id = metadata.id;
this.name = metadata.sourceName + "[madara]";
const iconFileName = metadata.sourceName.replace(/\s+/g, "").toLowerCase();
this.icon = `multisrc/madara/icons/${iconFileName}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.userAgent = "";
this.cookieString = "";
this.options = metadata.options;
this.filter = metadata.filters;
}
async popularNovels(pageNo: number, {filters, showLatestNovels}: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
url += '/page/' + pageNo + '/' +
'?m_orderby=' + (showLatestNovels ? 'latest' : (filters?.sort || 'rating'));
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this).find('.post-title')
.find('a')
.attr('href') || '';
const novel: Novel.Item = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const parseNovelAndChapters: Plugin.parseNovelAndChapters = async (
novelUrl
) => {
const novel: Novel.instance = {
url: novelUrl,
};
const body = await fetchApi(novelUrl).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
novel.name = loadedCheerio('.post-title h1').text().trim();
novel.cover =
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case 'Genre(s)':
case 'التصنيفات':
novel.genres = detail.replace(/[\t\n]/g, ',');
break;
case 'Author(s)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case 'Status':
case 'الحالة':
novel.status =
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary = loadedCheerio('div.summary__content').text().trim();
let html;
if (false) {
const novelId =
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') || '';
const body = {
action: "manga_get_chapters",
manga: novelId,
}
html = await fetchApi(
baseUrl + 'wp-admin/admin-ajax.php',
{
method: 'POST',
body: JSON.stringify(body),
})
.then(res => res.text());
} else {
html = await fetchApi(
baseUrl + 'ajax/chapters/',
{ method: 'POST' })
.then(res => res.text());
}
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const chapters: Chapter.Item[] = [];
loadedCheerio('.wp-manga-chapter').each(function () {
const chapterName = loadedCheerio(this).find('a').text().trim();
let releaseDate = null;
releaseDate = loadedCheerio(this)
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = parseMadaraDate(releaseDate);
let url = this.site;
if (filters?.genres && this.options?.path?.genres) {
url += this.options?.path?.genres + filters.genres + '/';
} else {
/**
* Insert current date
*/
releaseDate = dayjs().format('LL');
url += this.options?.path?.novels ? this.options.path.novels : MadaraDefaultPath.novels;
}
url += '/page/' + pageNo + '/' +
'?m_orderby=' + (showLatestNovels ? 'latest' : (filters?.sort || 'rating'));
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this).find('.post-title')
.find('a')
.attr('href') || '';
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
}
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const novel: Plugin.SourceNovel = {
url: novelUrl,
};
const body = await fetchApi(novelUrl).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio('.manga-title-badges, #manga-title span').remove();
novel.name =
loadedCheerio('.post-title h1').text().trim() ||
loadedCheerio('#manga-title h1').text();
novel.cover =
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case 'Genre(s)':
case 'التصنيفات':
novel.genres = detail.replace(/[\\t\\n]/g, ',');
break;
case 'Author(s)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case 'Status':
case 'الحالة':
novel.status =
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary =
loadedCheerio('div.summary__content').text().trim() ||
loadedCheerio('#tab-manga-about').text().trim() ||
loadedCheerio('.post-content_item h5:contains("Summary")').next().text().trim();
let html;
if (this.options?.useNewChapterEndpoint !== true) {
const novelId =
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') || '';
const formData = new FormData()
formData.append("action", "manga_get_chapters");
formData.append("manga", novelId);
let chapterUrl = loadedCheerio(this).find('a').attr('href') || '';
html = await fetchApi(
this.site + 'wp-admin/admin-ajax.php',
{
method: 'POST',
body: formData,
})
.then(res => res.text());
} else {
html = await fetchApi(
novelUrl + 'ajax/chapters/',
{ method: 'POST' })
.then(res => res.text());
}
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio('.wp-manga-chapter').each(function () {
const chapterName = loadedCheerio(this).find('a').text().trim();
let releaseDate = null;
releaseDate = loadedCheerio(this)
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = parseMadaraDate(releaseDate);
} else {
/**
* Insert current date
*/
releaseDate = dayjs().format('LL');
}
let chapterUrl = loadedCheerio(this).find('a').attr('href') || '';
chapters.push({ name: chapterName, releaseTime: releaseDate, url: chapterUrl });
});
novel.chapters = chapters.reverse();
return novel;
}
async parseChapter(chapterUrl: string): Promise<string> {
const body = await fetchApi(chapterUrl).then(res => res.text());
chapters.push({ name: chapterName, releaseTime: releaseDate, url: chapterUrl });
});
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html() || "";
novel.chapters = chapters.reverse();
return novel;
};
export const parseChapter: Plugin.parseChapter = async (chapterUrl) => {
const url = baseUrl + "/" + "novel" + "/" + chapterUrl;
const body = await fetchApi(chapterUrl).then(res => res.text());
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html();
return chapterText;
};
export const searchNovels: Plugin.searchNovels = async (searchTerm) => {
const novels: Novel.Item[] = [];
const url = baseUrl + "?s=" + searchTerm + "&post_type=wp-manga";
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.c-tabs-item__content').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this)
.find('.post-title')
.find('a')
.attr('href') || '';
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
};
export const fetchImage: Plugin.fetchImage = async (url) => {
return await fetchFile(url);
};
export const filters = [{"key":"sort","label":"Sırala","values":[{"label":"A-Z","value":"alphabet"},{"label":"En Son","value":"latest"},{"label":"Görüntülenme","value":"views"},{"label":"Popülarite","value":"trending"},{"label":"Reyting","value":"rating"},{"label":"Yeni","value":"new-manga"}],"inputType":FilterInputs.Picker}];
return chapterText;
}
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const url = this.site + "?s=" + searchTerm + "&post_type=wp-manga";
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio('.c-tabs-item__content').each(function () {
const novelName = loadedCheerio(this).find('.post-title').text().trim();
let image = loadedCheerio(this).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
let novelUrl = loadedCheerio(this)
.find('.post-title')
.find('a')
.attr('href') || '';
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
return novels;
}
async fetchImage(url: string): Promise<string | undefined> {
return await fetchFile(url, {});
}
}
const plugin = new MadaraPlugin({"id":"webnoveloku","sourceSite":"https://www.webnoveloku.com/","sourceName":"WebNovelOku ","filters":[{"key":"sort","label":"Sırala","values":[{"label":"A-Z","value":"alphabet"},{"label":"En Son","value":"latest"},{"label":"Görüntülenme","value":"views"},{"label":"Popülarite","value":"trending"},{"label":"Reyting","value":"rating"},{"label":"Yeni","value":"new-manga"}],"inputType":"Picker"}],"options":{"lang":"Turkish"}});
export default plugin;
+174 -173
View File
@@ -1,75 +1,76 @@
import { load as parseHTML } from "cheerio";
import { fetchApi, fetchFile } from "@libs/fetch";
import { FilterInputs } from "@libs/filterInputs";
import { Chapter, Novel, Plugin } from "@typings/plugin";
import { Filter, FilterInputs } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
export const id = "lshnovel";
export const name = "Liebe Schnee Hiver Novel";
export const version = "1.0.0";
export const icon = "multisrc/wpmangastream/icons/lshnovel.png";
export const site = "https://lshnovel.com/";
class LSHNovel implements Plugin.PluginBase {
id = "lshnovel";
name = "Liebe Schnee Hiver Novel";
icon = "multisrc/wpmangastream/icons/lshnovel.png";
site = "https://lshnovel.com/";
version = "1.0.0";
userAgent = "";
cookieString = "";
async popularNovels(pageNo: number, {filters}: Plugin.PopularNovelsOptions): Promise<Plugin.NovelItem[]> {
let link = `${this.site}series/?page=${pageNo}`;
if (filters) {
if (Array.isArray(filters.genres) && filters.genres.length) {
link += filters.genres.map((i) => `&genre[]=${i}`).join("");
}
const pluginId = id;
const baseUrl = site;
export const popularNovels: Plugin.popularNovels = async function (
page,
{ filters }
) {
let link = `${baseUrl}series/?page=${page}`;
if (filters) {
if (Array.isArray(filters.genres) && filters.genres.length) {
link += filters.genres.map((i) => `&genre[]=${i}`).join("");
if (Array.isArray(filters.type) && filters.type.length)
link += filters.type.map((i) => `&lang[]=${i}`).join("");
}
link += "&status=" + (filters?.status ? filters.status : "");
if (Array.isArray(filters.type) && filters.type.length) {
link += filters.type.map((i) => `&lang[]=${i}`).join("");
link += "&order=" + (filters?.order ? filters.order : "popular");
const headers = new Headers();
if(this.cookieString){
headers.append("cookie", this.cookieString);
}
}
const body = await fetchApi(link, {headers}).then((result) =>
result.text()
);
link += "&status=" + (filters?.status ? filters?.status : "");
const loadedCheerio = parseHTML(body);
link += "&order=" + (filters?.order ? filters?.order : "popular");
const novels: Plugin.NovelItem[] = [];
const body = await fetchApi(link, {}, pluginId).then((result) =>
result.text()
);
loadedCheerio("article.bs").each(function () {
const novelName = loadedCheerio(this).find(".ntitle").text().trim();
let image = loadedCheerio(this).find("img");
const novelCover = image.attr("data-src") || image.attr("src");
const loadedCheerio = parseHTML(body);
const novelUrl = loadedCheerio(this).find("a").attr("href");
const novels: Novel.Item[] = [];
if (!novelUrl) return;
loadedCheerio("article.bs").each(function () {
const novelName = loadedCheerio(this).find(".ntitle").text().trim();
let image = loadedCheerio(this).find("img");
const novelCover = image.attr("data-src") || image.attr("src");
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
const novelUrl = loadedCheerio(this).find("a").attr("href");
if (!novelUrl) return;
const novel = {
name: novelName,
cover: novelCover,
url: novelUrl,
};
novels.push(novel);
});
novels.push(novel);
});
return novels;
};
return novels;
};
export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
async function (novelUrl) {
async parseNovelAndChapters(novelUrl: string): Promise<Plugin.SourceNovel> {
const url = novelUrl;
const result = await fetchApi(url, {}, pluginId);
const headers = new Headers();
if(this.cookieString){
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(url, {headers});
const body = await result.text();
let loadedCheerio = parseHTML(body);
const novel: Novel.instance = {
const novel: Plugin.SourceNovel = {
url,
chapters: [],
};
@@ -82,21 +83,12 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
loadedCheerio("div.spe > span").each(function () {
const detailName = loadedCheerio(this).find("b").text().trim();
const detail = loadedCheerio(this)
.find("b")
.remove()
.end()
.text()
.trim();
const detail = loadedCheerio(this).find('b').remove().end().text().trim();
switch (detailName) {
case "المؤلف:":
case "Yazar:":
case "Autor:":
case "Author:":
novel.author = detail;
break;
case "Status:":
case "Seviye:":
novel.status = detail;
break;
@@ -115,7 +107,7 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
.end()
.text();
let chapter: Chapter.Item[] = [];
let chapter: Plugin.ChapterItem[] = [];
loadedCheerio(".eplister")
.find("li")
@@ -131,7 +123,9 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
.trim();
const chapterUrl = loadedCheerio(this).find("a").attr("href");
if (!chapterUrl) return;
chapter.push({
name: chapterName,
releaseTime: releaseDate,
@@ -142,172 +136,179 @@ export const parseNovelAndChapters: Plugin.parseNovelAndChapters =
novel.chapters = chapter.reverse();
return novel;
};
}
async parseChapter(chapterUrl: string): Promise<string> {
const headers = new Headers();
if(this.cookieString){
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(chapterUrl, {headers});
const body = await result.text();
export const parseChapter: Plugin.parseChapter = async function (chapterUrl) {
const result = await fetchApi(chapterUrl, {}, pluginId);
const body = await result.text();
const loadedCheerio = parseHTML(body);
const loadedCheerio = parseHTML(body);
let chapterText = loadedCheerio(".epcontent").html() || "";
let chapterText = loadedCheerio("div.epcontent").html();
return chapterText;
}
return chapterText;
};
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
const url = `${this.site}?s=${searchTerm}`;
const headers = new Headers();
if(this.cookieString){
headers.append("cookie", this.cookieString);
}
const result = await fetchApi(url, {headers});
const body = await result.text();
export const searchNovels: Plugin.searchNovels = async function (searchTerm) {
const url = `${baseUrl}?s=${searchTerm}`;
const loadedCheerio = parseHTML(body);
const result = await fetchApi(url, {}, pluginId);
const body = await result.text();
const novels: Plugin.NovelItem[] = [];
const loadedCheerio = parseHTML(body);
loadedCheerio("article.bs").each(function () {
const novelName = loadedCheerio(this).find(".ntitle").text().trim();
const novelCover = loadedCheerio(this).find("img").attr("src");
const novelUrl = loadedCheerio(this).find("a").attr("href");
if (!novelUrl) return;
const novels: Novel.Item[] = [];
loadedCheerio("article.bs").each(function () {
const novelName = loadedCheerio(this).find(".ntitle").text().trim();
const novelCover = loadedCheerio(this).find("img").attr("src");
const novelUrl = loadedCheerio(this).find("a").attr("href");
if (!novelUrl) return;
novels.push({
name: novelName,
url: novelUrl,
cover: novelCover,
novels.push({
name: novelName,
url: novelUrl,
cover: novelCover,
});
});
});
return novels;
};
return novels;
}
async fetchImage(url: string): Promise<string | undefined> {
return await fetchFile(url);
}
export const fetchImage: Plugin.fetchImage = async function (url) {
const headers = {
Referer: baseUrl,
};
return await fetchFile(url, { headers: headers });
};
export const filters = [
{
key: "order",
label: "Önerilen",
values: [
{ label: "Varsayılan", value: "" },
filters = [
{
key: "order",
label: "Önerilen",
values: [
{ label: "Varsayılan", value: "" },
{ label: "A-Z", value: "title" },
{ label: "A-Z", value: "title" },
{ label: "Z-A", value: "titlereverse" },
{ label: "Z-A", value: "titlereverse" },
{ label: "Son Yüklemeler", value: "update" },
{ label: "Son Yüklemeler", value: "update" },
{ label: "Son Eklenenler", value: "latest" },
{ label: "Son Eklenenler", value: "latest" },
{ label: "Bestimiz", value: "popular" },
],
inputType: FilterInputs.Picker,
},
{
key: "status",
label: "Statü",
values: [
{ label: "Tümü", value: "" },
{ label: "Bestimiz", value: "popular" },
],
inputType: FilterInputs.Picker,
},
{
key: "status",
label: "Statü",
values: [
{ label: "Tümü", value: "" },
{ label: "Ongoing", value: "ongoing" },
{ label: "Ongoing", value: "ongoing" },
{ label: "Hiatus", value: "hiatus" },
{ label: "Hiatus", value: "hiatus" },
{ label: "Completed", value: "completed" },
],
inputType: FilterInputs.Picker,
},
{
key: "type",
label: "Tür",
values: [
{ label: "Çeviri Novel", value: "ceviri-novel" },
{ label: "Completed", value: "completed" },
],
inputType: FilterInputs.Picker,
},
{
key: "type",
label: "Tür",
values: [
{ label: "Çeviri Novel", value: "ceviri-novel" },
{ label: "Liz-Chan", value: "liz-chan" },
{ label: "Liz-Chan", value: "liz-chan" },
{ label: "Manhwa", value: "manhwa" },
{ label: "Manhwa", value: "manhwa" },
{ label: "Orijinal Novel", value: "orijinal-novel" },
{ label: "Orijinal Novel", value: "orijinal-novel" },
{ label: "Web Novel", value: "web-novel" },
],
inputType: FilterInputs.Checkbox,
},
{
key: "genres",
label: "Kategori",
values: [
{ label: "+18", value: "18" },
{ label: "Web Novel", value: "web-novel" },
],
inputType: FilterInputs.Checkbox,
},
{
key: "genres",
label: "Kategori",
values: [
{ label: "+18", value: "18" },
{ label: "Action", value: "action" },
{ label: "Action", value: "action" },
{ label: "Adult", value: "adult" },
{ label: "Adult", value: "adult" },
{ label: "Aksiyon", value: "aksiyon" },
{ label: "Aksiyon", value: "aksiyon" },
{ label: "BL", value: "bl" },
{ label: "BL", value: "bl" },
{ label: "Comedy", value: "comedy" },
{ label: "Comedy", value: "comedy" },
{ label: "Doğaüstü", value: "dogaustu" },
{ label: "Doğaüstü", value: "dogaustu" },
{ label: "Dram", value: "dram" },
{ label: "Dram", value: "dram" },
{ label: "Drama", value: "drama" },
{ label: "Drama", value: "drama" },
{ label: "Ecchi", value: "ecchi" },
{ label: "Ecchi", value: "ecchi" },
{ label: "Fantastik", value: "fantastik" },
{ label: "Fantastik", value: "fantastik" },
{ label: "Fantasy", value: "fantasy" },
{ label: "Fantasy", value: "fantasy" },
{ label: "Gizem", value: "gizem" },
{ label: "Gizem", value: "gizem" },
{ label: "Harem", value: "harem" },
{ label: "Harem", value: "harem" },
{ label: "Historical", value: "historical" },
{ label: "Historical", value: "historical" },
{ label: "Josei", value: "josei" },
{ label: "Josei", value: "josei" },
{ label: "Macera", value: "macera" },
{ label: "Macera", value: "macera" },
{ label: "Manhwa", value: "manhwa" },
{ label: "Manhwa", value: "manhwa" },
{ label: "Martial Arts", value: "martial-arts" },
{ label: "Martial Arts", value: "martial-arts" },
{ label: "Mature", value: "mature" },
{ label: "Mature", value: "mature" },
{ label: "Novel", value: "novel" },
{ label: "Novel", value: "novel" },
{ label: "Okul", value: "okul" },
{ label: "Okul", value: "okul" },
{ label: "Psikolojik", value: "psikolojik" },
{ label: "Psikolojik", value: "psikolojik" },
{ label: "Psychological", value: "psychological" },
{ label: "Psychological", value: "psychological" },
{ label: "Reverse Harem", value: "reverse-harem" },
{ label: "Reverse Harem", value: "reverse-harem" },
{ label: "Romance", value: "romance" },
{ label: "Romance", value: "romance" },
{ label: "Romantik", value: "romantik" },
{ label: "Romantik", value: "romantik" },
{ label: "Shoujo", value: "shoujo" },
{ label: "Shoujo", value: "shoujo" },
{ label: "Slice Of Life", value: "slice-of-life" },
{ label: "Slice Of Life", value: "slice-of-life" },
{ label: "Smut", value: "smut" },
{ label: "Smut", value: "smut" },
{ label: "Supernatural", value: "supernatural" },
{ label: "Supernatural", value: "supernatural" },
{ label: "Tarihi", value: "tarihi" },
{ label: "Tarihi", value: "tarihi" },
{ label: "Tragedy", value: "tragedy" },
{ label: "Tragedy", value: "tragedy" },
{ label: "Yaoi", value: "yaoi" },
],
inputType: FilterInputs.Checkbox,
},
];
{ label: "Yaoi", value: "yaoi" },
],
inputType: FilterInputs.Checkbox,
},
];
}
export default new LSHNovel();