@yeci226/nhentai-ts
Version:
A scraper for NHentai with types
93 lines (92 loc) • 3.9 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var doujin_exports = {};
__export(doujin_exports, {
parseDoujinInfo: () => parseDoujinInfo
});
module.exports = __toCommonJS(doujin_exports);
var import_lib = require("../lib");
const parseDoujinInfo = async ($, site, api_pages) => {
var _a, _b;
const pages = [];
const dataSrc = $(".thumb-container").first().find("a > img").attr("data-src") || "";
const gallery_id = dataSrc.includes("/galleries/") ? ((_a = dataSrc.split("/galleries/")[1]) == null ? void 0 : _a.split("/")[0]) || "" : "";
if (site === "net" && api_pages)
api_pages.forEach(
(page, i) => pages.push(
"https://i.nhentai.net/galleries/".concat(gallery_id, "/").concat(i + 1, ".").concat((0, import_lib.getExtension)(page.t))
)
);
else
for (const el of $(".thumb-container")) {
const url2 = ($(el).find("a > img").attr("data-src") || "").replace(
/t(?=\.)/,
""
);
if (url2) {
const page = url2.replace(import_lib.imageSites[site], "i.nhentai.net");
pages.push(page);
}
}
const cover = $("#cover").find("a > img").attr("data-src") || $("#cover").find("a > img").attr("src");
const href = $("#cover").find("a").attr("href") || "";
const id = href.includes("g/") ? ((_b = href.split("g/")[1]) == null ? void 0 : _b.split("/")[0]) || "" : "";
const titles = {
english: $("#info").find("h1").text().trim(),
original: $("#info").find("h2").text().trim()
};
const baseURL = import_lib.baseURLS[site];
const parodies = [];
const characters = [];
const tags = [];
const artists = [];
const groups = [];
const languages = [];
const categories = [];
$(".tag-container.field-name").each((i, el) => {
const type = $(el).text().trim().toLowerCase();
const contents = [];
const push = (field) => contents.filter((content) => content !== "").forEach((content) => field.push(content));
$(el).find(".tags").find("a").each((i2, el2) => {
contents.push($(el2).text().trim().split("\n")[0]);
});
type.startsWith("parodies") ? push(parodies) : type.startsWith("characters") ? push(characters) : type.startsWith("tags") ? push(tags) : type.startsWith("artists") ? push(artists) : type.startsWith("groups") ? push(groups) : type.startsWith("languages") ? push(languages) : push(categories);
});
const url = "".concat(baseURL, "/g/").concat(id);
const images = new import_lib.Pages(pages, titles.english);
return {
id,
title: titles.english,
originalTitle: titles.original,
parodies: (0, import_lib.clean)(parodies),
characters: (0, import_lib.clean)(characters),
tags: (0, import_lib.clean)(tags),
artists: (0, import_lib.clean)(artists),
groups: (0, import_lib.clean)(groups),
languages: (0, import_lib.clean)(languages),
categories: (0, import_lib.clean)(categories),
cover: !pages.some((url2) => url2.includes("cdn.dogehls.xyz")) ? cover.replace("cdn.dogehls.xyz", "t3.nhentai.net") : null,
images,
url
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
parseDoujinInfo
});