Create multisrc
@@ -0,0 +1,112 @@
|
||||
const express = require("express");
|
||||
const MadaraScraper = require("./MadaraScraper");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const getPath = (extensionId) => {
|
||||
const path = {
|
||||
38: { novels: "manga", novel: "manga", chapter: "manga" },
|
||||
39: { novels: "series", novel: "series", chapter: "series" },
|
||||
40: { novels: "novels", novel: "novel", chapter: "novel" },
|
||||
41: { novels: "manga", novel: "manga", chapter: "manga" },
|
||||
42: { novels: "all-novels", novel: "manga", chapter: "manga" },
|
||||
43: { novels: "series", novel: "series", chapter: "series" },
|
||||
44: { novels: "series", novel: "series", chapter: "series" },
|
||||
45: { novels: "novel", novel: "novel", chapter: "novel" },
|
||||
};
|
||||
|
||||
return path[extensionId];
|
||||
};
|
||||
|
||||
const madaraSources = [
|
||||
{
|
||||
extensionId: 38,
|
||||
scraper: new MadaraScraper(
|
||||
38,
|
||||
"https://skynovel.org/",
|
||||
"SkyNovel",
|
||||
getPath(38)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 39,
|
||||
scraper: new MadaraScraper(
|
||||
39,
|
||||
"https://novelcake.com/",
|
||||
"NovelCake",
|
||||
getPath(39)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 40,
|
||||
scraper: new MadaraScraper(
|
||||
40,
|
||||
"https://novelsrock.com/",
|
||||
"NovelsRock",
|
||||
getPath(40)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 41,
|
||||
scraper: new MadaraScraper(
|
||||
41,
|
||||
"https://zinnovel.com/",
|
||||
"ZinnNovel",
|
||||
getPath(41)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 42,
|
||||
scraper: new MadaraScraper(
|
||||
42,
|
||||
"https://noveltranslate.com/",
|
||||
"NovelTranslate",
|
||||
getPath(42)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 43,
|
||||
scraper: new MadaraScraper(
|
||||
43,
|
||||
"https://www.lunarletters.com/",
|
||||
"LunarLetters",
|
||||
getPath(43)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 44,
|
||||
scraper: new MadaraScraper(
|
||||
44,
|
||||
"https://sleepytranslations.com/",
|
||||
"SleepyTranslations",
|
||||
getPath(44)
|
||||
),
|
||||
},
|
||||
{
|
||||
extensionId: 45,
|
||||
scraper: new MadaraScraper(
|
||||
45,
|
||||
"https://freenovel.me/",
|
||||
"FreeNovelMe",
|
||||
getPath(45)
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
madaraSources.map((source) => {
|
||||
router.get(`/${source.extensionId}/novels/`, source.scraper.novelsScraper);
|
||||
|
||||
router.get(
|
||||
`/${source.extensionId}/novel/:novelUrl`,
|
||||
source.scraper.novelScraper
|
||||
);
|
||||
|
||||
router.get(
|
||||
`/${source.extensionId}/novel/:novelUrl/:chapterUrl`,
|
||||
source.scraper.chapterScraper
|
||||
);
|
||||
|
||||
router.get(`/${source.extensionId}/search/`, source.scraper.searchScraper);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,220 @@
|
||||
const cheerio = require("cheerio");
|
||||
const fetch = require("node-fetch");
|
||||
const FormData = require("form-data");
|
||||
const { parseHtml } = require("../../src/helper");
|
||||
|
||||
class MadaraScraper {
|
||||
constructor(extensionId, baseUrl, sourceName, path) {
|
||||
this.extensionId = extensionId;
|
||||
this.baseUrl = baseUrl;
|
||||
this.sourceName = sourceName;
|
||||
this.path = path;
|
||||
|
||||
this.novelsScraper = this.novelsScraper.bind(this);
|
||||
this.novelScraper = this.novelScraper.bind(this);
|
||||
this.chapterScraper = this.chapterScraper.bind(this);
|
||||
this.searchScraper = this.searchScraper.bind(this);
|
||||
}
|
||||
|
||||
async novelsScraper(req, res) {
|
||||
let url = this.baseUrl + this.path.novels + "/?m_orderby=rating";
|
||||
let extensionId = this.extensionId;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
let novels = [];
|
||||
|
||||
$(".manga-title-badges").remove();
|
||||
|
||||
$(".page-item-detail").each(function (result) {
|
||||
const novelName = $(this).find(".post-title").text().trim();
|
||||
let image = $(this).find("img");
|
||||
const novelCover = image.attr("data-src") || image.attr("src");
|
||||
|
||||
let novelUrl = $(this)
|
||||
.find(".post-title")
|
||||
.find("a")
|
||||
.attr("href")
|
||||
.split("/")[4];
|
||||
|
||||
const novel = {
|
||||
extensionId,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
res.json(novels);
|
||||
}
|
||||
|
||||
async novelScraper(req, res) {
|
||||
const novelUrl = req.params.novelUrl;
|
||||
const url = `${this.baseUrl}${this.path.novel}/${novelUrl}/`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
let $ = cheerio.load(body);
|
||||
|
||||
let novel = {};
|
||||
|
||||
novel.extensionId = this.extensionId;
|
||||
|
||||
novel.sourceName = this.sourceName;
|
||||
|
||||
novel.sourceUrl = url;
|
||||
|
||||
novel.novelUrl = novelUrl;
|
||||
|
||||
$(".manga-title-badges").remove();
|
||||
|
||||
novel.novelName = $(".post-title > h1").text().trim();
|
||||
|
||||
novel.novelCover =
|
||||
$(".summary_image > a > img").attr("data-src") ||
|
||||
$(".summary_image > a > img").attr("src");
|
||||
|
||||
$(".post-content_item").each(function (result) {
|
||||
const detailName = $(this)
|
||||
.find(".summary-heading > h5")
|
||||
.text()
|
||||
.trim();
|
||||
const detail = $(this).find(".summary-content").text().trim();
|
||||
|
||||
switch (detailName) {
|
||||
case "Genre(s)":
|
||||
novel["Genre(s)"] = detail.replace(/[\t\n]/g, ",");
|
||||
break;
|
||||
case "Author(s)":
|
||||
novel["Author(s)"] = detail;
|
||||
break;
|
||||
case "Status":
|
||||
novel.Status = detail;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
novel.novelSummary = $("div.summary__content").text().trim();
|
||||
|
||||
let novelChapters = [];
|
||||
|
||||
const novelId =
|
||||
$(".rating-post-id").attr("value") ||
|
||||
$("#manga-chapters-holder").attr("data-id");
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("action", "manga_get_chapters");
|
||||
formData.append("manga", novelId);
|
||||
|
||||
const data = await fetch(this.baseUrl + "wp-admin/admin-ajax.php", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const text = await data.text();
|
||||
|
||||
$ = cheerio.load(text);
|
||||
|
||||
$(".wp-manga-chapter").each(function (result) {
|
||||
const chapterName = $(this)
|
||||
.find("a")
|
||||
.text()
|
||||
.replace(/[\t\n]/g, "")
|
||||
.trim();
|
||||
|
||||
const releaseDate = $(this)
|
||||
.find("span")
|
||||
.text()
|
||||
.replace("Free", "")
|
||||
.trim();
|
||||
|
||||
const chapterUrl = $(this).find("a").attr("href").split("/")[5];
|
||||
|
||||
novelChapters.push({ chapterName, releaseDate, chapterUrl });
|
||||
});
|
||||
|
||||
novel.novelChapters = novelChapters.reverse();
|
||||
|
||||
res.json(novel);
|
||||
}
|
||||
|
||||
async chapterScraper(req, res) {
|
||||
let novelUrl = req.params.novelUrl;
|
||||
let chapterUrl = req.params.chapterUrl;
|
||||
|
||||
let extensionId = this.extensionId;
|
||||
|
||||
const url = `${this.baseUrl}${this.path.chapter}/${novelUrl}/${chapterUrl}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
let chapterName =
|
||||
$(".text-center").text() || $("#chapter-heading").text();
|
||||
|
||||
let chapterText = $(".text-left").html();
|
||||
chapterText = parseHtml(chapterText);
|
||||
|
||||
let nextChapter = null;
|
||||
let prevChapter = null;
|
||||
|
||||
const chapter = {
|
||||
extensionId,
|
||||
novelUrl,
|
||||
chapterUrl,
|
||||
chapterName,
|
||||
chapterText,
|
||||
nextChapter,
|
||||
prevChapter,
|
||||
};
|
||||
|
||||
res.json(chapter);
|
||||
}
|
||||
|
||||
async searchScraper(req, res) {
|
||||
const searchTerm = req.query.s;
|
||||
|
||||
const url = `${this.baseUrl}?s=${searchTerm}&post_type=wp-manga`;
|
||||
|
||||
const result = await fetch(url);
|
||||
const body = await result.text();
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
let novels = [];
|
||||
let extensionId = this.extensionId;
|
||||
|
||||
$(".c-tabs-item__content").each(function (result) {
|
||||
const novelName = $(this).find(".post-title").text().trim();
|
||||
|
||||
let image = $(this).find("img");
|
||||
const novelCover = image.attr("data-src") || image.attr("src");
|
||||
|
||||
let novelUrl = $(this)
|
||||
.find(".post-title")
|
||||
.find("a")
|
||||
.attr("href")
|
||||
.split("/")[4];
|
||||
|
||||
const novel = {
|
||||
extensionId,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
res.json(novels);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MadaraScraper;
|
||||
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 159 KiB |
|
After Width: | Height: | Size: 100 KiB |