fix(pururin, modifier): remove sort consume & update elements (#30)

* enable deepscan

* doesn't accept sorting anymore tho

* update element

* outdated apidoc definitions

* pururin update

* pre release
このコミットが含まれているのは:
Indrawan I 2023-08-04 19:29:21 +07:00 committed by GitHub
コミット 4ce195e453
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 4AEE18F83AFDEB23
7個のファイルの変更27行の追加28行の削除

3
.vscode/settings.json vendored ノーマルファイル
ファイルの表示

@ -0,0 +1,3 @@
{
"deepscan.enable": true
}

ファイルの表示

@ -207,14 +207,11 @@ The missing piece of nhentai.net - https://sinkaroid.github.io/jandapress/#api-n
The missing piece of pururin.to - https://sinkaroid.github.io/jandapress/#api-pururin
- `/pururin` : pururin api
- **get**, takes parameters : `book`
- **search**, takes parameters : `key`, `?page`, `?sort`
- **search**, takes parameters : `key`, `?page`
- **random**
- <u>sort parameters on search</u>
- "newest", "most-popular", "highest-rated", "most-viewed", "title", "random"
- Example
- https://janda.sinkaroid.org/pururin/get?book=63373
- https://janda.sinkaroid.org/pururin/search?key=futanari
- https://janda.sinkaroid.org/pururin/search?key=futanari&page=2&sort=most-viewed
- https://janda.sinkaroid.org/pururin/random
### Hentaifox

ファイルの表示

@ -1,6 +1,6 @@
{
"name": "jandapress",
"version": "3.8.1-alpha",
"version": "3.8.2-alpha",
"description": "RESTful and experimental API for the Doujinshi, Pressing the whole nhentai, pururin, hentaifox, and more.. where the official one is lack.",
"main": "build/src/index.js",
"scripts": {

ファイルの表示

@ -2,16 +2,16 @@ import { scrapeContent } from "../../scraper/pururin/pururinSearchController";
import c from "../../utils/options";
import { logger } from "../../utils/logger";
import { maybeError } from "../../utils/modifier";
const sorting = ["newest", "most-popular", "highest-rated", "most-viewed", "title", "random"];
// const sorting = ["newest", "most-popular", "highest-rated", "most-viewed", "title", "random"];
import { Request, Response } from "express";
export async function searchPururin(req: Request, res: Response) {
try {
const key = req.query.key as string;
const page = req.query.page || 1;
const sort = req.query.sort as string || sorting[0] as string;
// const sort = req.query.sort as string || sorting[0] as string;
if (!key) throw Error("Parameter key is required");
if (!sorting.includes(sort)) throw Error("Invalid sort: " + sorting.join(", "));
// if (!sorting.includes(sort)) throw Error("Invalid sort: " + sorting.join(", "));
/**
* @api {get} /pururin/search Search pururin
@ -20,7 +20,6 @@ export async function searchPururin(req: Request, res: Response) {
* @apiDescription Search doujinshi on pururin
* @apiParam {String} key Keyword to search
* @apiParam {Number} [page=1] Page number
* @apiParam {String} [sort=newest]
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
@ -28,7 +27,6 @@ export async function searchPururin(req: Request, res: Response) {
*
* @apiExample {curl} curl
* curl -i https://janda.sinkaroid.org/pururin/search?key=yuri
* curl -i https://janda.sinkaroid.org/pururin/search?key=yuri&page=2&sort=newest
*
* @apiExample {js} JS/TS
* import axios from "axios"
@ -44,7 +42,7 @@ export async function searchPururin(req: Request, res: Response) {
* print(await resp.json())
*/
const url = `${c.PURURIN}/search/${sort}?q=${key}&page=${page}`;
const url = `${c.PURURIN}/search?q=${key}&page=${page}`;
const data = await scrapeContent(url);
logger.info({
path: req.path,

ファイルの表示

@ -28,7 +28,8 @@ export async function scrapeContent(url: string, random = false) {
else res = await janda.fetchBody(url), raw = res;
const $ = load(raw);
const title: string = $("div.content-wrapper h1").html() || "";
const title: string = $("meta[property='og:title']").attr("content") || "";
if (!title) throw Error("Not found");
const tags: string[] = $("div.content-wrapper ul.list-inline li").map((i, abc) => {
@ -37,8 +38,8 @@ export async function scrapeContent(url: string, random = false) {
const cover = $("meta[property='og:image']").attr("content");
const extension = `.${cover?.split(".").pop()}`;
const total: number = parseInt($("gallery-thumbnails").attr(":total") || "0");
const id: number = parseInt($("gallery-thumbnails").attr(":id") || "0");
const total: number = parseInt($("span[itemprop='numberOfPages']").text()) || 0;
const id: number = parseInt($("meta[property='og:url']").attr("content")?.split("/")[4] || "0");
const image = [];
for (let i = 0; i < total; i++) {

ファイルの表示

@ -1,12 +1,11 @@
import { load } from "cheerio";
import JandaPress from "../../JandaPress";
import c from "../../utils/options";
import { isText } from "domhandler";
import { getPururinInfo, getPururinPageCount, getPururinLanguage } from "../../utils/modifier";
interface ISearchPururin {
title: string;
cover: string;
cover: string | null;
id: number;
language: string;
info: string;
@ -18,7 +17,7 @@ interface IData {
success: boolean;
data: object;
page: number;
sort: string;
sort: string | null;
source: string;
}
@ -28,8 +27,11 @@ export async function scrapeContent(url: string) {
try {
const res = await janda.fetchBody(url);
const $ = load(res);
const dataRaw = $("img.card-img-top");
const dataRaw = $(".card.card-gallery");
const info = $("div.info");
const card = $("img.card-img-top").map((i, abc) => {
return abc.attribs["src"];
}).get();
const infoBook = [];
for (let i = 0; i < info.length; i++) {
@ -39,21 +41,19 @@ export async function scrapeContent(url: string) {
}
}
const content = [];
for (const abc of dataRaw) {
const objectData: ISearchPururin = {
title: abc.attribs["alt"],
cover: abc.attribs["data-src"].replace(/^\/\//, "https://"),
id: parseInt(abc.attribs["data-src"].split("data/")[1].split("/cover")[0]),
title: abc.attribs["title"],
cover: card ? card[dataRaw.index(abc)] : null,
id: parseInt(abc.attribs["data-gid"]),
language: getPururinLanguage(infoBook[dataRaw.index(abc)]) || "Unknown",
info: infoBook[dataRaw.index(abc)],
link: `${c.PURURIN}/gallery/${abc.attribs["data-src"].split("data/")[1].split("/cover")[0]}/janda`,
link: abc.attribs["data-href"],
total: getPururinPageCount(infoBook[dataRaw.index(abc)])
};
content.push(objectData);
}
if (content.length === 0) throw Error("No result found");
@ -62,8 +62,8 @@ export async function scrapeContent(url: string) {
success: true,
data: content,
page: parseInt(url.split("&page=")[1]),
sort: url.split("/search/")[1].split("?")[0],
source: c.PURURIN
sort: null,
source: url
};
return data;
} catch (err) {

ファイルの表示

@ -130,9 +130,9 @@ export const isNumeric = (val: string): boolean => {
*/
export async function getIdRandomPururin(): Promise<number> {
const randomNumber = Math.floor(Math.random() * 500) + 1;
const raw = await p(`${c.PURURIN}/browse/random?page=${randomNumber}`);
const raw = await p(`${c.PURURIN}/browse?sort=newest&page=${randomNumber}`);
const $ = load(raw.body);
const gallery = $("img.card-img-top").map((i, el) => $(el).attr("data-src")).get();
const gallery = $(".card.card-gallery").map((i, el) => $(el).attr("href")).get();
const galleryNumber = gallery.map(el => removeNonNumeric(el));
const randomgallery = galleryNumber[Math.floor(Math.random() * galleryNumber.length)];
return parseInt(randomgallery);