updates and new extensions
This commit is contained in:
115
book/nhentai.js
115
book/nhentai.js
@@ -2,10 +2,67 @@ class NHentai {
|
||||
constructor() {
|
||||
this.baseUrl = "https://nhentai.net";
|
||||
this.type = "book-board";
|
||||
this.version = "1.1";
|
||||
this.version = "1.2";
|
||||
this.mediaType = "manga";
|
||||
}
|
||||
|
||||
getFilters() {
|
||||
return {
|
||||
sort: {
|
||||
label: "Order",
|
||||
type: "select",
|
||||
options: [
|
||||
{ value: "date", label: "Recent" },
|
||||
{ value: "popular", label: "Popular: All time" },
|
||||
{ value: "popular-month", label: "Popular: Month" },
|
||||
{ value: "popular-week", label: "Popular: Week" },
|
||||
{ value: "popular-today", label: "Popular: Today" }
|
||||
],
|
||||
default: "date"
|
||||
},
|
||||
tags: {
|
||||
label: "Tags (separated by comma)",
|
||||
type: "text",
|
||||
placeholder: "ej. big breasts, stocking"
|
||||
},
|
||||
categories: {
|
||||
label: "Categories",
|
||||
type: "text",
|
||||
placeholder: "ej. doujinshi, manga"
|
||||
},
|
||||
groups: {
|
||||
label: "Groups",
|
||||
type: "text",
|
||||
placeholder: "ej. fakku"
|
||||
},
|
||||
artists: {
|
||||
label: "Artists",
|
||||
type: "text",
|
||||
placeholder: "ej. shindo l"
|
||||
},
|
||||
parodies: {
|
||||
label: "Parodies",
|
||||
type: "text",
|
||||
placeholder: "ej. naruto"
|
||||
},
|
||||
characters: {
|
||||
label: "Characters",
|
||||
type: "text",
|
||||
placeholder: "ej. sakura haruno"
|
||||
},
|
||||
pages: {
|
||||
label: "Pages (ej. >20)",
|
||||
type: "text",
|
||||
placeholder: ">20"
|
||||
},
|
||||
uploaded: {
|
||||
label: "Uploaded (ej. >20d)",
|
||||
type: "text",
|
||||
placeholder: ">20d"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
shortenTitle(title) {
|
||||
return title.replace(/(\[[^]]*]|[({][^)}]*[)}])/g, "").trim();
|
||||
}
|
||||
@@ -26,16 +83,62 @@ class NHentai {
|
||||
return JSON.parse(unicodeFixed);
|
||||
}
|
||||
|
||||
async search({ query = "", page = 1 }) {
|
||||
if (query.startsWith("id:") || (!isNaN(query) && query.length <= 7)) {
|
||||
async search({ query = "", page = 1, filters = null }) {
|
||||
|
||||
if (query.startsWith("id:") || (!isNaN(query) && query.length <= 7 && query.length > 0)) {
|
||||
return [await this.getMetadata(this.parseId(query))];
|
||||
}
|
||||
|
||||
const url = `${this.baseUrl}/search/?q=${encodeURIComponent(query)}&page=${page}`;
|
||||
let advQuery = "";
|
||||
let sortParam = "";
|
||||
|
||||
if (filters) {
|
||||
|
||||
const textFilters = [
|
||||
{ key: "tags", prefix: "tag" },
|
||||
{ key: "categories", prefix: "category" },
|
||||
{ key: "groups", prefix: "group" },
|
||||
{ key: "artists", prefix: "artist" },
|
||||
{ key: "parodies", prefix: "parody" },
|
||||
{ key: "characters", prefix: "character" },
|
||||
{ key: "uploaded", prefix: "uploaded", noQuote: true },
|
||||
{ key: "pages", prefix: "pages", noQuote: true }
|
||||
];
|
||||
|
||||
textFilters.forEach(({ key, prefix, noQuote }) => {
|
||||
if (filters[key]) {
|
||||
const terms = filters[key].split(",");
|
||||
terms.forEach(term => {
|
||||
const t = term.trim();
|
||||
if (!t) return;
|
||||
|
||||
let currentPrefix = prefix;
|
||||
let currentTerm = t;
|
||||
let isExclusion = false;
|
||||
|
||||
if (t.startsWith("-")) {
|
||||
isExclusion = true;
|
||||
currentTerm = t.substring(1);
|
||||
}
|
||||
|
||||
advQuery += ` ${isExclusion ? "-" : ""}${currentPrefix}:`;
|
||||
advQuery += noQuote ? currentTerm : `"${currentTerm}"`;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (filters.sort && filters.sort !== "date") {
|
||||
sortParam = `&sort=${filters.sort}`;
|
||||
}
|
||||
}
|
||||
|
||||
const finalQuery = (query + " " + advQuery).trim() || '""';
|
||||
|
||||
const url = `${this.baseUrl}/search/?q=${encodeURIComponent(finalQuery)}&page=${page}${sortParam}`;
|
||||
|
||||
const { result } = await this.scrape(
|
||||
url,
|
||||
page =>
|
||||
page.evaluate(() => document.documentElement.innerHTML),
|
||||
page => page.evaluate(() => document.documentElement.innerHTML),
|
||||
{ waitSelector: ".gallery" }
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user