From 4ce195e453f280e6898a8b61efa7431a8715c02f Mon Sep 17 00:00:00 2001 From: Indrawan I Date: Fri, 4 Aug 2023 19:29:21 +0700 Subject: [PATCH] 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 --- .vscode/settings.json | 3 +++ README.md | 5 +--- package.json | 2 +- src/controller/pururin/pururinSearch.ts | 10 ++++---- src/scraper/pururin/pururinGetController.ts | 7 +++--- .../pururin/pururinSearchController.ts | 24 +++++++++---------- src/utils/modifier.ts | 4 ++-- 7 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..318a06a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deepscan.enable": true +} \ No newline at end of file diff --git a/README.md b/README.md index b0f91de..9fe08db 100644 --- a/README.md +++ b/README.md @@ -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** - - sort parameters on search - - "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 diff --git a/package.json b/package.json index c567f22..f4dde34 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/controller/pururin/pururinSearch.ts b/src/controller/pururin/pururinSearch.ts index 6099213..ae3ae41 100644 --- a/src/controller/pururin/pururinSearch.ts +++ b/src/controller/pururin/pururinSearch.ts @@ -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, diff --git a/src/scraper/pururin/pururinGetController.ts b/src/scraper/pururin/pururinGetController.ts index 787f97a..02d4618 100644 --- a/src/scraper/pururin/pururinGetController.ts +++ b/src/scraper/pururin/pururinGetController.ts @@ -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++) { diff --git a/src/scraper/pururin/pururinSearchController.ts b/src/scraper/pururin/pururinSearchController.ts index 03246de..1fc2753 100644 --- a/src/scraper/pururin/pururinSearchController.ts +++ b/src/scraper/pururin/pururinSearchController.ts @@ -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) { diff --git a/src/utils/modifier.ts b/src/utils/modifier.ts index 3ec2b5f..a1faeb8 100644 --- a/src/utils/modifier.ts +++ b/src/utils/modifier.ts @@ -130,9 +130,9 @@ export const isNumeric = (val: string): boolean => { */ export async function getIdRandomPururin(): Promise { 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);