diff --git a/src/controller/eporner/epornerGet.ts b/src/controller/eporner/epornerGet.ts index 6f78be9..414c399 100644 --- a/src/controller/eporner/epornerGet.ts +++ b/src/controller/eporner/epornerGet.ts @@ -1,45 +1,9 @@ import { scrapeContent } from "../../scraper/eporner/epornerGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getEporner(req: Request, res: Response) { +export async function getEporner({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /eporner/get?id=:id Get eporner - * @apiName Get eporner - * @apiGroup eporner - * @apiDescription Get a eporner video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/eporner/get?id=ibvqvezXzcs - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/eporner/get?id=ibvqvezXzcs") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/eporner/get?id=ibvqvezXzcs") as resp: - * print(await resp.json()) - */ - // https://www.eporner.com/video-ibvqvezXzcs/ivy-seduces-her-dad-s-friend/ - // https://www.eporner.com/hd-porn/hgovoiPexQe/Risa-Tsukino/ - + const { id } = query; let path: string; if (id.startsWith("video-")) { @@ -51,16 +15,10 @@ export async function getEporner(req: Request, res: Response) { const url = `${c.EPORNER}/${path}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/eporner/epornerGetRelated.ts b/src/controller/eporner/epornerGetRelated.ts index b9ee25d..12b6621 100644 --- a/src/controller/eporner/epornerGetRelated.ts +++ b/src/controller/eporner/epornerGetRelated.ts @@ -1,28 +1,15 @@ import { scrapeContent } from "../../scraper/eporner/epornerGetRelatedController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedEporner(req: Request, res: Response) { +export async function relatedEporner({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - + const { id } = query; const url = `${c.EPORNER}/video-${id}`; const data = await scrapeContent(url); - - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/eporner/epornerRandom.ts b/src/controller/eporner/epornerRandom.ts index 77bb927..80523be 100644 --- a/src/controller/eporner/epornerRandom.ts +++ b/src/controller/eporner/epornerRandom.ts @@ -1,72 +1,32 @@ -import { scrapeContent as searchScrape } from "../../scraper/eporner/epornerSearchController"; -import { scrapeContent as videoScrape } from "../../scraper/eporner/epornerGetController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function randomEporner(req: Request, res: Response) { - /** - * @api {get} /eporner/random Get random eporner - * @apiName Get random eporner - * @apiGroup eporner - * @apiDescription Get a random eporner video - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/eporner/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/eporner/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/eporner/random") as resp: - * print(await resp.json()) - */ - - // cat/all/SORT-top-weekly/ - - try { - const weeklyUrl = `${c.EPORNER}/cat/all/SORT-top-weekly/`; - const list = await searchScrape(weeklyUrl); - - if (!list.data.length) { - throw new Error("No weekly top videos found"); - } - - const random = list.data[Math.floor(Math.random() * list.data.length)]; - - let path: string; - - if (random.id.startsWith("video-")) { - path = random.id; - } else { - path = `hd-porn/${random.id}`; - } - - const url = `${c.EPORNER}/${path}`; - const data = await videoScrape(url); - - logger.info({ - path: req.path, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - - return res.json(data); - } catch (err) { - res.status(400).json(maybeError(false, (err as Error).message)); - } -} \ No newline at end of file +import { scrapeContent as searchScrape } from "../../scraper/eporner/epornerSearchController"; +import { scrapeContent as videoScrape } from "../../scraper/eporner/epornerGetController"; +import c from "../../utils/options"; + +export async function randomEporner() { + try { + const weeklyUrl = `${c.EPORNER}/cat/all/SORT-top-weekly/`; + const list = await searchScrape(weeklyUrl); + + if (!list.data.length) { + throw new Error("No weekly top videos found"); + } + + const random = list.data[Math.floor(Math.random() * list.data.length)]; + + let path: string; + + if (random.id.startsWith("video-")) { + path = random.id; + } else { + path = `hd-porn/${random.id}`; + } + + const url = `${c.EPORNER}/${path}`; + const data = await videoScrape(url); + + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/eporner/epornerSearch.ts b/src/controller/eporner/epornerSearch.ts index 131a3b2..698e880 100644 --- a/src/controller/eporner/epornerSearch.ts +++ b/src/controller/eporner/epornerSearch.ts @@ -1,72 +1,29 @@ -import { scrapeContent } from "../../scraper/eporner/epornerSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchEporner(req: Request, res: Response) { - try { - /** - * @api {get} /eporner/search Search eporner videos - * @apiName Search eporner - * @apiGroup eporner - * @apiDescription Search eporner videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=1] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/eporner/search?key=milf - * curl -i https://lust.scathach.id/eporner/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/eporner/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/eporner/search?key=milf") as resp: - * print(await resp.json()) - */ - - // https://www.eporner.com/tag/milf/ - - const key = req.query.key as string; - const page = Number(req.query.page || 1); - - if (!key) throw Error("Parameter key is required"); - if (isNaN(page)) throw Error("Parameter page must be a number"); - - const slug = key - .toLowerCase() - .trim() - .replace(/\s+/g, "-"); - - const url = - page === 1 - ? `${c.EPORNER}/tag/${slug}/` - : `${c.EPORNER}/tag/${slug}/${page}/`; - - const data = await scrapeContent(url); - - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/eporner/epornerSearchController"; +import c from "../../utils/options"; + +export async function searchEporner({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = Number(query.page || 1); + + const slug = key + .toLowerCase() + .trim() + .replace(/\s+/g, "-"); + + const url = + page === 1 + ? `${c.EPORNER}/tag/${slug}/` + : `${c.EPORNER}/tag/${slug}/${page}/`; + + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/pornhub/pornhubGet.ts b/src/controller/pornhub/pornhubGet.ts index f1546f5..17c7914 100644 --- a/src/controller/pornhub/pornhubGet.ts +++ b/src/controller/pornhub/pornhubGet.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/pornhub/pornhubGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getPornhub(req: Request, res: Response) { +export async function getPornhub({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /pornhub/get?id=:id Get Pornhub - * @apiName Get pornhub - * @apiGroup pornhub - * @apiDescription Get a pornhub video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.PORNHUB}/view_video.php?viewkey=${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/pornhub/pornhubGetRelated.ts b/src/controller/pornhub/pornhubGetRelated.ts index 92e9aac..59196d0 100644 --- a/src/controller/pornhub/pornhubGetRelated.ts +++ b/src/controller/pornhub/pornhubGetRelated.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/pornhub/pornhubSearchController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedPornhub(req: Request, res: Response) { +export async function relatedPornhub({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /pornhub/get?id=:id Get Pornhub related videos - * @apiName Get pornhub related videos - * @apiGroup pornhub - * @apiDescription Get a related pornhub videos based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/pornhub/get?id=ph63c4e1dc48fe7") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.PORNHUB}/view_video.php?viewkey=${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/pornhub/pornhubRandom.ts b/src/controller/pornhub/pornhubRandom.ts index 2c6ef99..bffac30 100644 --- a/src/controller/pornhub/pornhubRandom.ts +++ b/src/controller/pornhub/pornhubRandom.ts @@ -1,50 +1,14 @@ -import { Request, Response } from "express"; import { scrapeContent } from "../../scraper/pornhub/pornhubGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -export async function randomPornhub(req: Request, res: Response) { +export async function randomPornhub() { try { - /** - * @api {get} /pornhub/random Random pornhub video - * @apiName Random pornhub - * @apiGroup pornhub - * @apiDescription Gets random pornhub video - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/pornhub/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/pornhub/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/pornhub/random") as resp: - * print(await resp.json()) - * - */ const url = `${c.PORNHUB}/video/random`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/pornhub/pornhubSearch.ts b/src/controller/pornhub/pornhubSearch.ts index a706428..8bf060b 100644 --- a/src/controller/pornhub/pornhubSearch.ts +++ b/src/controller/pornhub/pornhubSearch.ts @@ -1,66 +1,29 @@ -import { scrapeContent } from "../../scraper/pornhub/pornhubSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; -const sorting = ["mr", "mv", "tr", "lg"]; - -export async function searchPornhub(req: Request, res: Response) { - try { - /** - * @api {get} /pornhub/search Search pornhub videos - * @apiName Search pornhub - * @apiGroup pornhub - * @apiDescription Search pornhub videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=1] Page number - * @apiParam {String} [sort=mr] Sort by - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/pornhub/search?key=milf - * curl -i https://lust.scathach.id/pornhub/search?key=milf&page=2&sort=mr - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/pornhub/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/pornhub/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 1; - const sort = req.query.sort as string; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - let url; - if (!sort) url = `${c.PORNHUB}/video/search?search=${spacer(key)}`; - else if (!sorting.includes(sort)) url = `${c.PORNHUB}/video/search?search=${spacer(key)}&page=${page}`; - - else url = `${c.PORNHUB}/video/search?search=${spacer(key)}&o=${sort}&page=${page}`; - console.log(url); - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/pornhub/pornhubSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +const sorting = ["mr", "mv", "tr", "lg"]; + +export async function searchPornhub({ + query, +}: { + query: { key: string; page?: string; sort?: string }; +}) { + try { + const { key, sort } = query; + const page = query.page || "1"; + + let url; + if (!sort) url = `${c.PORNHUB}/video/search?search=${spacer(key)}`; + else if (!sorting.includes(sort)) + url = `${c.PORNHUB}/video/search?search=${spacer(key)}&page=${page}`; + else + url = `${c.PORNHUB}/video/search?search=${spacer(key)}&o=${sort}&page=${page}`; + + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/redtube/redtubeGet.ts b/src/controller/redtube/redtubeGet.ts index 61d47db..2b8e4c4 100644 --- a/src/controller/redtube/redtubeGet.ts +++ b/src/controller/redtube/redtubeGet.ts @@ -1,56 +1,15 @@ import { scrapeContent } from "../../scraper/redtube/redtubeGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getRedtube(req: Request, res: Response) { +export async function getRedtube({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - if (isNaN(Number(id))) throw Error("Parameter id must be a number"); - - /** - * @api {get} /redtube/get?id=:id Get Redtube - * @apiName Get redtube - * @apiGroup redtube - * @apiDescription Get a redtube video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/redtube/get?id=42763661 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/redtube/get?id=42763661") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/redtube/get?id=42763661") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.REDTUBE}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/redtube/redtubeGetRelated.ts b/src/controller/redtube/redtubeGetRelated.ts index 8865a75..8a31697 100644 --- a/src/controller/redtube/redtubeGetRelated.ts +++ b/src/controller/redtube/redtubeGetRelated.ts @@ -1,54 +1,14 @@ -import { scrapeContent } from "../../scraper/redtube/redtubeSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function relatedRedtube(req: Request, res: Response) { - try { - /** - * @api {get} /redtube/get?id=:id Get redtube related videos - * @apiName Get redtube related videos - * @apiGroup redtube - * @apiDescription Get a related redtube videos based on id - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/redtube/get?id=41698751 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/redtube/get?id=41698751") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/redtube/get?id=41698751") as resp: - * print(await resp.json()) - */ - - const id = req.query.id as string; - if (!id) throw Error("Parameter key is required"); - if (isNaN(Number(id))) throw Error("Parameter id must be a number"); - - const url = `${c.REDTUBE}/${id}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/redtube/redtubeSearchController"; +import c from "../../utils/options"; + +export async function relatedRedtube({ query }: { query: { id: string } }) { + try { + const { id } = query; + const url = `${c.REDTUBE}/${id}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/redtube/redtubeRandom.ts b/src/controller/redtube/redtubeRandom.ts index 3dd6257..3517fe0 100644 --- a/src/controller/redtube/redtubeRandom.ts +++ b/src/controller/redtube/redtubeRandom.ts @@ -1,65 +1,25 @@ import { scrapeContent } from "../../scraper/redtube/redtubeGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; -const lust = new LustPress(); - -export async function randomRedtube(req: Request, res: Response) { +export async function randomRedtube() { try { - - - /** - * @api {get} /redtube/random Get random redtube - * @apiName Get random redtube - * @apiGroup redtube - * @apiDescription Get a random redtube video - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/redtube/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/redtube/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/redtube/random") as resp: - * print(await resp.json()) - */ const resolve = await lust.fetchBody(c.REDTUBE); const $ = load(resolve); const search = $("a.video_link") .map((i, el) => { return $(el).attr("href"); - }).get(); + }) + .get(); const random = Math.floor(Math.random() * search.length); - + const url = c.REDTUBE + search[random]; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/redtube/redtubeSearch.ts b/src/controller/redtube/redtubeSearch.ts index afaf7ca..a96f1a7 100644 --- a/src/controller/redtube/redtubeSearch.ts +++ b/src/controller/redtube/redtubeSearch.ts @@ -1,58 +1,21 @@ -import { scrapeContent } from "../../scraper/redtube/redtubeSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchRedtube(req: Request, res: Response) { - try { - /** - * @api {get} /redtube/search Search redtube videos - * @apiName Search redtube - * @apiGroup redtube - * @apiDescription Search redtube videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=1] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/redtube/search?key=milf - * curl -i https://lust.scathach.id/redtube/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/redtube/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/redtube/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 1; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - const url = `${c.REDTUBE}/?search=${spacer(key)}&page=${page}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/redtube/redtubeSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +export async function searchRedtube({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = query.page || "1"; + + const url = `${c.REDTUBE}/?search=${spacer(key)}&page=${page}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/txxx/txxxGet.ts b/src/controller/txxx/txxxGet.ts index 134d810..dbdf3f1 100644 --- a/src/controller/txxx/txxxGet.ts +++ b/src/controller/txxx/txxxGet.ts @@ -1,10 +1,5 @@ -import { Request, Response } from "express"; -import LustPress from "../../LustPress"; -import { maybeError } from "../../utils/modifier"; -import { logger } from "../../utils/logger"; -import { IVideoData } from "../../interfaces"; - -const lust = new LustPress(); +import { lust } from "../../LustPress"; +import { IVideoData, TxxxResponse } from "../../interfaces"; // Generate sharded API URL exactly like TXXX expects function getApiUrl(videoId: string): string { @@ -17,15 +12,13 @@ function getApiUrl(videoId: string): string { return `https://txxx.com/api/json/video/86400/${million}/${thousand}/${id}.json`; } -export async function getTxxx(req: Request, res: Response) { +export async function getTxxx({ query }: { query: { id: string } }) { try { - const id = String(req.query.id || "").trim(); - if (!id) throw new Error("Parameter id is required"); - + const { id } = query; const apiUrl = getApiUrl(id); const buffer = await lust.fetchBody(apiUrl); - const parsed = JSON.parse(buffer.toString("utf-8")); + const parsed = JSON.parse(buffer.toString("utf-8")) as TxxxResponse; if (!parsed?.video) { throw new Error("Invalid API response"); @@ -34,12 +27,12 @@ export async function getTxxx(req: Request, res: Response) { const video = parsed.video; const categories = Object.values(video.categories || {}).map( - (c: any) => c.title, + (c) => c.title ); - const tags = Object.values(video.tags || {}).map((t: any) => t.title); + const tags = Object.values(video.tags || {}).map((t) => t.title); - const models = Object.values(video.models || {}).map((m: any) => m.title); + const models = Object.values(video.models || {}).map((m) => m.title); const videoDir = video.dir || ""; const videoId = video.video_id; @@ -63,20 +56,14 @@ export async function getTxxx(req: Request, res: Response) { tags: [...categories, ...tags], }, source: `https://txxx.com/videos/${videoId}/${videoDir}/`, - assets: [embed, video.thumbsrc].filter(Boolean), + assets: [embed, video.thumbsrc].filter(Boolean) as string[], }; - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - - return res.json(response); + return response; } catch (err) { const e = err as Error; - return res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + + diff --git a/src/controller/txxx/txxxGetRelated.ts b/src/controller/txxx/txxxGetRelated.ts index a5fc00e..8f2e171 100644 --- a/src/controller/txxx/txxxGetRelated.ts +++ b/src/controller/txxx/txxxGetRelated.ts @@ -1,10 +1,5 @@ -import { Request, Response } from "express"; -import LustPress from "../../LustPress"; -import { maybeError } from "../../utils/modifier"; -import { logger } from "../../utils/logger"; -import { ISearchVideoData } from "../../interfaces"; - -const lust = new LustPress(); +import { lust } from "../../LustPress"; +import { ISearchVideoData, TxxxRelatedResponse } from "../../interfaces"; function getRelatedApiUrl(videoId: string, page = 1, count = 50): string { const id = Number(videoId); @@ -19,10 +14,14 @@ function getRelatedApiUrl(videoId: string, page = 1, count = 50): string { ); } -export async function relatedTxxx(req: Request, res: Response) { +export async function relatedTxxx({ + query, +}: { + query: { id: string; page?: string }; +}) { try { - const id = String(req.query.id || "").trim(); - const page = Number(req.query.page || 1); + const { id } = query; + const page = Number(query.page || 1); if (!id) throw new Error("Parameter id is required"); if (Number.isNaN(page)) throw new Error("Parameter page must be a number"); @@ -30,14 +29,14 @@ export async function relatedTxxx(req: Request, res: Response) { const apiUrl = getRelatedApiUrl(id, page); const buffer = await lust.fetchBody(apiUrl); - const rawData = JSON.parse(buffer.toString("utf-8")); + const rawData = JSON.parse(buffer.toString("utf-8")) as TxxxRelatedResponse; const videos = Array.isArray(rawData.videos) ? rawData.videos : []; - const data = videos.map((v: any) => ({ - id: v.video_id, + const data = videos.map((v) => ({ + id: String(v.video_id), title: v.title, - image: v.scr || v.thumb || null, + image: v.scr || v.thumb || "", duration: v.duration || "None", views: v.video_viewed || "0", rating: v.rating || "0", @@ -46,24 +45,16 @@ export async function relatedTxxx(req: Request, res: Response) { video: `https://txxx.com/embed/${v.video_id}/`, })); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - - return res.json({ + return { success: true, - total_count: rawData.total_count || "0", + total_count: String(rawData.total_count || "0"), pages: rawData.pages || 1, page, data, source: `https://txxx.com/videos/${id}/`, - } as ISearchVideoData); + } as unknown as ISearchVideoData; } catch (err) { const e = err as Error; - return res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } diff --git a/src/controller/txxx/txxxRandom.ts b/src/controller/txxx/txxxRandom.ts index 6c339b9..3c77493 100644 --- a/src/controller/txxx/txxxRandom.ts +++ b/src/controller/txxx/txxxRandom.ts @@ -1,21 +1,15 @@ -import { Request, Response } from "express"; -import LustPress from "../../LustPress"; -import { maybeError } from "../../utils/modifier"; -import { logger } from "../../utils/logger"; +import { lust } from "../../LustPress"; +import { TxxxSearchResponse as TxxxResponse } from "../../interfaces"; -const lust = new LustPress(); - -export async function randomTxxx(req: Request, res: Response) { +export async function randomTxxx() { try { const apiUrl = - "https://txxx.com/api/json/videos2/14400/str/most-popular/60/..1.all..day.json"; + "https://txxx.com/api/json/videos2/14400/str/most-popular/60/..1.all..day.json"; const buffer = await lust.fetchBody(apiUrl); - const rawData = JSON.parse(buffer.toString("utf-8")); + const rawData = JSON.parse(buffer.toString("utf-8")) as TxxxResponse; - const videos = Array.isArray(rawData.videos) - ? rawData.videos - : []; + const videos = Array.isArray(rawData.videos) ? rawData.videos : []; if (videos.length === 0) { throw new Error("No videos returned from upstream"); @@ -39,20 +33,15 @@ export async function randomTxxx(req: Request, res: Response) { embed: `https://txxx.com/embed/${v.video_id}/`, }; - logger.info({ - path: req.path, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - - return res.json({ + return { success: true, data, source: apiUrl, - }); + }; } catch (err) { const e = err as Error; - return res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + + diff --git a/src/controller/txxx/txxxSearch.ts b/src/controller/txxx/txxxSearch.ts index 6b4e8a9..746ecac 100644 --- a/src/controller/txxx/txxxSearch.ts +++ b/src/controller/txxx/txxxSearch.ts @@ -1,40 +1,27 @@ -import { Request, Response } from "express"; -import LustPress from "../../LustPress"; -import { maybeError } from "../../utils/modifier"; +import { lust } from "../../LustPress"; +import { TxxxSearchResponse } from "../../interfaces"; -const lust = new LustPress(); - -export async function searchTxxx(req: Request, res: Response) { +export async function searchTxxx({ + query, +}: { + query: { key: string; page?: string }; +}) { try { - const key = String(req.query.key || "").trim(); - const page = Number(req.query.page || 1); - - if (!key) { - return res.json({ - success: false, - error: "Parameter key is required", - }); - } - - if (Number.isNaN(page)) { - return res.json({ - success: false, - error: "Parameter page must be a number", - }); - } + const { key } = query; + const page = Number(query.page || 1); const apiUrl = - "https://txxx.com/api/videos2.php" + - `?params=259200/str/relevance/60/search..${page}.all..` + - `&s=${encodeURIComponent(key)}`; + "https://txxx.com/api/videos2.php" + + `?params=259200/str/relevance/60/search..${page}.all..` + + `&s=${encodeURIComponent(key)}`; // Fetch from API directly const buffer = await lust.fetchBody(apiUrl); - const rawData = JSON.parse(buffer.toString("utf-8")); + const rawData = JSON.parse(buffer.toString("utf-8")) as TxxxSearchResponse; const videos = Array.isArray(rawData.videos) ? rawData.videos : []; - const data = videos.map((v: any) => ({ + const data = videos.map((v) => ({ video_id: v.video_id, title: v.title, dir: v.dir, @@ -49,15 +36,17 @@ export async function searchTxxx(req: Request, res: Response) { embed: `https://txxx.com/embed/${v.video_id}/`, })); - return res.json({ + return { success: true, total_count: String(rawData.total_count ?? videos.length), pages: Number(rawData.pages ?? 1), page, data, - }); + }; } catch (err) { const e = err as Error; - return res.json(maybeError(false, e.message)); + throw new Error(e.message); } } + + diff --git a/src/controller/xhamster/xhamsterGet.ts b/src/controller/xhamster/xhamsterGet.ts index a9159ec..a8a28a4 100644 --- a/src/controller/xhamster/xhamsterGet.ts +++ b/src/controller/xhamster/xhamsterGet.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xhamster/xhamsterGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getXhamster(req: Request, res: Response) { +export async function getXhamster({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xhamster/get?id=:id Get xhamster - * @apiName Get xhamster - * @apiGroup xhamster - * @apiDescription Get a xhamster video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xhamster/get?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xhamster/get?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xhamster/get?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XHAMSTER}/videos/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xhamster/xhamsterGetRelated.ts b/src/controller/xhamster/xhamsterGetRelated.ts index 7f88e44..c93d821 100644 --- a/src/controller/xhamster/xhamsterGetRelated.ts +++ b/src/controller/xhamster/xhamsterGetRelated.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xhamster/xhamsterSearchController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedXhamster(req: Request, res: Response) { +export async function relatedXhamster({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xhamster/get?id=:id Get related xhamster - * @apiName Get related xhamster - * @apiGroup xhamster - * @apiDescription Get a xhamster video based on related id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xhamster/related?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xhamster/related?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xhamster/related?id=videos/horny-makima-tests-new-toy-and-cums-intensely-xhAa5wx") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XHAMSTER}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xhamster/xhamsterRandom.ts b/src/controller/xhamster/xhamsterRandom.ts index f72d324..7059d66 100644 --- a/src/controller/xhamster/xhamsterRandom.ts +++ b/src/controller/xhamster/xhamsterRandom.ts @@ -1,42 +1,10 @@ import { scrapeContent } from "../../scraper/xhamster/xhamsterGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; -const lust = new LustPress(); - -export async function randomXhamster(req: Request, res: Response) { +export async function randomXhamster() { try { - /** - * @api {get} /xhamster/random Get random xhamster video - * @apiName Get random xhamster - * @apiGroup xhamster - * @apiDescription Get a random xhamster video from the list of newest videos. - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xhamster/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xhamster/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xhamster/random") as resp: - * print(await resp.json()) - */ - const resolve = await lust.fetchBody(`${c.XHAMSTER}/newest`); const $ = load(resolve); @@ -54,17 +22,10 @@ export async function randomXhamster(req: Request, res: Response) { const data = await scrapeContent(randomUrl); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent"), - }); - - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xhamster/xhamsterSearch.ts b/src/controller/xhamster/xhamsterSearch.ts index 5590546..b1469bd 100644 --- a/src/controller/xhamster/xhamsterSearch.ts +++ b/src/controller/xhamster/xhamsterSearch.ts @@ -1,58 +1,21 @@ -import { scrapeContent } from "../../scraper/xhamster/xhamsterSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchXhamster(req: Request, res: Response) { - try { - /** - * @api {get} /xhamster/search Search xhamster videos - * @apiName Search xhamster - * @apiGroup xhamster - * @apiDescription Search xhamster videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=1] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xhamster/search?key=milf - * curl -i https://lust.scathach.id/xhamster/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xhamster/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xhamster/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 1; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - const url = `${c.XHAMSTER}/search/${spacer(key)}?page=${page}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/xhamster/xhamsterSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +export async function searchXhamster({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = query.page || "1"; + + const url = `${c.XHAMSTER}/search/${spacer(key)}?page=${page}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/xnxx/xnxxGet.ts b/src/controller/xnxx/xnxxGet.ts index fa0a798..577a79c 100644 --- a/src/controller/xnxx/xnxxGet.ts +++ b/src/controller/xnxx/xnxxGet.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xnxx/xnxxGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getXnxx(req: Request, res: Response) { +export async function getXnxx({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xnxx/get?id=:id Get xnxx - * @apiName Get xnxx - * @apiGroup xnxx - * @apiDescription Get a xnxx video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xnxx/get?id=video-17vah71a/makima_y_denji - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xnxx/get?id=video-17vah71a/makima_y_denji") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xnxx/get?id=video-17vah71a/makima_y_denji") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XNXX}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xnxx/xnxxGetRelated.ts b/src/controller/xnxx/xnxxGetRelated.ts index 4fc270b..21aa170 100644 --- a/src/controller/xnxx/xnxxGetRelated.ts +++ b/src/controller/xnxx/xnxxGetRelated.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xnxx/xnxxGetRelatedController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedXnxx(req: Request, res: Response) { +export async function relatedXnxx({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xnxx/get?id=:id Get related xnxx - * @apiName Get related xnxx - * @apiGroup xnxx - * @apiDescription Get a xnxx video based on related id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xnxx/related?id=video-17vah71a/makima_y_denji - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xnxx/related?id=video-17vah71a/makima_y_denji") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xnxx/related?id=video-17vah71a/makima_y_denji") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XNXX}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xnxx/xnxxRandom.ts b/src/controller/xnxx/xnxxRandom.ts index 74a06cb..82976ea 100644 --- a/src/controller/xnxx/xnxxRandom.ts +++ b/src/controller/xnxx/xnxxRandom.ts @@ -1,63 +1,27 @@ import { scrapeContent } from "../../scraper/xnxx/xnxxGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; +import { lust } from "../../LustPress"; import { load } from "cheerio"; -import LustPress from "../../LustPress"; -const lust = new LustPress(); - -export async function randomXnxx(req: Request, res: Response) { +export async function randomXnxx() { try { - - - /** - * @api {get} /xnxx/random Get random xnxx - * @apiName Get random xnxx - * @apiGroup xnxx - * @apiDescription Get a random xnxx video - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xnxx/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xnxx/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xnxx/random") as resp: - * print(await resp.json()) - */ - const resolve = await lust.fetchBody("https://www.xnxx.com/search/random/random"); + const resolve = await lust.fetchBody( + "https://www.xnxx.com/search/random/random" + ); const $ = load(resolve); const search = $("div.mozaique > div") .map((i, el) => { return $(el).find("a").attr("href"); - }).get(); + }) + .get(); const random = Math.floor(Math.random() * search.length); - + const url = c.XNXX + search[random]; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xnxx/xnxxSearch.ts b/src/controller/xnxx/xnxxSearch.ts index 49416f1..423eeb5 100644 --- a/src/controller/xnxx/xnxxSearch.ts +++ b/src/controller/xnxx/xnxxSearch.ts @@ -1,58 +1,20 @@ -import { scrapeContent } from "../../scraper/xnxx/xnxxSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchXnxx(req: Request, res: Response) { - try { - /** - * @api {get} /xnxx/search Search xnxx videos - * @apiName Search xnxx - * @apiGroup xnxx - * @apiDescription Search xnxx videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=0] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xnxx/search?key=milf - * curl -i https://lust.scathach.id/xnxx/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xnxx/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xnxx/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 0; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - const url = `${c.XNXX}/search/${spacer(key)}/${page}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/xnxx/xnxxSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +export async function searchXnxx({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = query.page || "0"; + const url = `${c.XNXX}/search/${spacer(key)}/${page}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/xvideos/xvideosGet.ts b/src/controller/xvideos/xvideosGet.ts index 80688b4..867a4af 100644 --- a/src/controller/xvideos/xvideosGet.ts +++ b/src/controller/xvideos/xvideosGet.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xvideos/xvideosGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getXvideos(req: Request, res: Response) { +export async function getXvideos({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xvideos/get?id=:id Get xvideos - * @apiName Get xvideos - * @apiGroup xvideos - * @apiDescription Get a xvideos video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xvideos/get?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_ - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xvideos/get?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xvideos/get?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XVIDEOS}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xvideos/xvideosGetRelated.ts b/src/controller/xvideos/xvideosGetRelated.ts index 7e9400a..0581901 100644 --- a/src/controller/xvideos/xvideosGetRelated.ts +++ b/src/controller/xvideos/xvideosGetRelated.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/xvideos/xvideosGetRelatedController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedXvideos(req: Request, res: Response) { +export async function relatedXvideos({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /xvideos/get?id=:id Get related xvideos - * @apiName Get related xvideos - * @apiGroup xvideos - * @apiDescription Get a xvideos video based on related id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xvideos/related?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_ - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xvideos/related?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xvideos/related?id=video73564387/cute_hentai_maid_with_pink_hair_fucking_uncensored_") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.XVIDEOS}/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xvideos/xvideosRandom.ts b/src/controller/xvideos/xvideosRandom.ts index 8acc3db..6571d86 100644 --- a/src/controller/xvideos/xvideosRandom.ts +++ b/src/controller/xvideos/xvideosRandom.ts @@ -1,41 +1,10 @@ +import { load } from "cheerio"; import { scrapeContent } from "../../scraper/xvideos/xvideosGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; -const lust = new LustPress(); - -export async function randomXvideos(req: Request, res: Response) { +export async function randomXvideos() { try { - /** - * @api {get} /xvideos/random Get random xvideos - * @apiName Get random xvideos - * @apiGroup xvideos - * @apiDescription Get a random xvideos video - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xvideos/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xvideos/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xvideos/random") as resp: - * print(await resp.json()) - */ const resolve = await lust.fetchBody(c.XVIDEOS); const $ = load(resolve); const search = $("div.thumb-under") @@ -45,19 +14,13 @@ export async function randomXvideos(req: Request, res: Response) { const filtered = search.filter((el) => el.includes("/video")); const filtered_ = filtered.filter((el) => !el.includes("THUMBNUM")); const random = Math.floor(Math.random() * filtered_.length); - - const url = c.XVIDEOS + filtered[random]; + + const url = c.XVIDEOS + filtered_[random]; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/xvideos/xvideosSearch.ts b/src/controller/xvideos/xvideosSearch.ts index 728eb9b..4a8ef84 100644 --- a/src/controller/xvideos/xvideosSearch.ts +++ b/src/controller/xvideos/xvideosSearch.ts @@ -1,58 +1,21 @@ -import { scrapeContent } from "../../scraper/xvideos/xvideosSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchXvideos(req: Request, res: Response) { - try { - /** - * @api {get} /xvideos/search Search xvideos videos - * @apiName Search xvideos - * @apiGroup xvideos - * @apiDescription Search xvideos videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=0] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/xvideos/search?key=milf - * curl -i https://lust.scathach.id/xvideos/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/xvideos/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/xvideos/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 0; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - const url = `${c.XVIDEOS}/?k=${spacer(key)}&p=${page}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/xvideos/xvideosSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +export async function searchXvideos({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = query.page || "0"; + + const url = `${c.XVIDEOS}/?k=${spacer(key)}&p=${page}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/controller/youporn/youpornGet.ts b/src/controller/youporn/youpornGet.ts index 92e331d..e778869 100644 --- a/src/controller/youporn/youpornGet.ts +++ b/src/controller/youporn/youpornGet.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/youporn/youpornGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function getYouporn(req: Request, res: Response) { +export async function getYouporn({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /youporn/get?id=:id Get youporn - * @apiName Get youporn - * @apiGroup youporn - * @apiDescription Get a youporn video based on id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/youporn/get?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/youporn/get?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/youporn/get?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.YOUPORN}/watch/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/youporn/youpornGetRelated.ts b/src/controller/youporn/youpornGetRelated.ts index 007f205..82727af 100644 --- a/src/controller/youporn/youpornGetRelated.ts +++ b/src/controller/youporn/youpornGetRelated.ts @@ -1,55 +1,15 @@ import { scrapeContent } from "../../scraper/youporn/youpornSearchController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; -export async function relatedYouporn(req: Request, res: Response) { +export async function relatedYouporn({ query }: { query: { id: string } }) { try { - const id = req.query.id as string; - if (!id) throw Error("Parameter id is required"); - - /** - * @api {get} /youporn/get?id=:id Get related youporn - * @apiName Get related youporn - * @apiGroup youporn - * @apiDescription Get a youporn video based on related id - * - * @apiParam {String} id Video ID - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/youporn/related?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/youporn/related?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/youporn/related?id=16621192/chainsaw-man-fuck-makima-3d-porn-60-fps") as resp: - * print(await resp.json()) - */ - + const { id } = query; const url = `${c.YOUPORN}/watch/${id}`; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } + diff --git a/src/controller/youporn/youpornRandom.ts b/src/controller/youporn/youpornRandom.ts index e72e68a..83f25e4 100644 --- a/src/controller/youporn/youpornRandom.ts +++ b/src/controller/youporn/youpornRandom.ts @@ -1,62 +1,23 @@ import { scrapeContent } from "../../scraper/youporn/youpornGetController"; import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError } from "../../utils/modifier"; -import { Request, Response } from "express"; import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; -const lust = new LustPress(); - -export async function randomYouporn(req: Request, res: Response) { +export async function randomYouporn() { try { - - - /** - * @api {get} /youporn/random Get random youporn - * @apiName Get random youporn - * @apiGroup youporn - * @apiDescription Get a random youporn video - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/youporn/random - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/youporn/random") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/youporn/random") as resp: - * print(await resp.json()) - */ const resolve = await lust.fetchBody(`${c.YOUPORN}`); const $ = load(resolve); const search = $("a[href^='/watch/']") .map((i, el) => { return $(el).attr("href"); - }).get(); + }) + .get(); const random = Math.floor(Math.random() * search.length); const url = c.YOUPORN + search[random]; const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); + return data; } catch (err) { const e = err as Error; - res.status(400).json(maybeError(false, e.message)); + throw new Error(e.message); } } diff --git a/src/controller/youporn/youpornSearch.ts b/src/controller/youporn/youpornSearch.ts index e0d3014..2ea67a3 100644 --- a/src/controller/youporn/youpornSearch.ts +++ b/src/controller/youporn/youpornSearch.ts @@ -1,58 +1,21 @@ -import { scrapeContent } from "../../scraper/youporn/youpornSearchController"; -import c from "../../utils/options"; -import { logger } from "../../utils/logger"; -import { maybeError, spacer } from "../../utils/modifier"; -import { Request, Response } from "express"; - -export async function searchYouporn(req: Request, res: Response) { - try { - /** - * @api {get} /youporn/search Search youporn videos - * @apiName Search youporn - * @apiGroup youporn - * @apiDescription Search youporn videos - * @apiParam {String} key Keyword to search - * @apiParam {Number} [page=1] Page number - * - * @apiSuccessExample {json} Success-Response: - * HTTP/1.1 200 OK - * HTTP/1.1 400 Bad Request - * - * @apiExample {curl} curl - * curl -i https://lust.scathach.id/youporn/search?key=milf - * curl -i https://lust.scathach.id/youporn/search?key=milf&page=2 - * - * @apiExample {js} JS/TS - * import axios from "axios" - * - * axios.get("https://lust.scathach.id/youporn/search?key=milf") - * .then(res => console.log(res.data)) - * .catch(err => console.error(err)) - * - * @apiExample {python} Python - * import aiohttp - * async with aiohttp.ClientSession() as session: - * async with session.get("https://lust.scathach.id/youporn/search?key=milf") as resp: - * print(await resp.json()) - */ - - const key = req.query.key as string; - const page = req.query.page || 1; - if (!key) throw Error("Parameter key is required"); - if (isNaN(Number(page))) throw Error("Parameter page must be a number"); - - const url = `${c.YOUPORN}/search/?query=${spacer(key)}&page=${page}`; - const data = await scrapeContent(url); - logger.info({ - path: req.path, - query: req.query, - method: req.method, - ip: req.ip, - useragent: req.get("User-Agent") - }); - return res.json(data); - } catch (err) { - const e = err as Error; - res.status(400).json(maybeError(false, e.message)); - } -} \ No newline at end of file +import { scrapeContent } from "../../scraper/youporn/youpornSearchController"; +import c from "../../utils/options"; +import { spacer } from "../../utils/modifier"; + +export async function searchYouporn({ + query, +}: { + query: { key: string; page?: string }; +}) { + try { + const { key } = query; + const page = query.page || "1"; + + const url = `${c.YOUPORN}/search/?query=${spacer(key)}&page=${page}`; + const data = await scrapeContent(url); + return data; + } catch (err) { + const e = err as Error; + throw new Error(e.message); + } +} \ No newline at end of file diff --git a/src/scraper/eporner/epornerGetController.ts b/src/scraper/eporner/epornerGetController.ts index 47f3bd1..278a357 100644 --- a/src/scraper/eporner/epornerGetController.ts +++ b/src/scraper/eporner/epornerGetController.ts @@ -1,9 +1,7 @@ import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; import { IVideoData } from "../../interfaces"; -const lust = new LustPress(); - function calculateRatingFromStrings( upVote: string, downVote: string diff --git a/src/scraper/eporner/epornerGetRelatedController.ts b/src/scraper/eporner/epornerGetRelatedController.ts index 6d55c7a..dadde65 100644 --- a/src/scraper/eporner/epornerGetRelatedController.ts +++ b/src/scraper/eporner/epornerGetRelatedController.ts @@ -1,9 +1,7 @@ import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; import { ISearchVideoData } from "../../interfaces"; -const lust = new LustPress(); - export async function scrapeContent(url: string) { const html = await lust.fetchBody(url); const $ = load(html); diff --git a/src/scraper/pornhub/pornhubGetController.ts b/src/scraper/pornhub/pornhubGetController.ts index 0d3a091..a7402ce 100644 --- a/src/scraper/pornhub/pornhubGetController.ts +++ b/src/scraper/pornhub/pornhubGetController.ts @@ -1,9 +1,7 @@ import { load } from "cheerio"; -import LustPress from "../../LustPress"; +import { lust } from "../../LustPress"; import { IVideoData } from "../../interfaces"; -const lust = new LustPress(); - export async function scrapeContent(url: string) { try { const resolve = await lust.fetchBody(url); diff --git a/src/scraper/pornhub/pornhubSearchController.ts b/src/scraper/pornhub/pornhubSearchController.ts index a95a045..d688082 100644 --- a/src/scraper/pornhub/pornhubSearchController.ts +++ b/src/scraper/pornhub/pornhubSearchController.ts @@ -1,59 +1,54 @@ -import { load } from "cheerio"; -import LustPress from "../../LustPress"; -import c from "../../utils/options"; -import { ISearchVideoData } from "../../interfaces"; - -const lust = new LustPress(); - -export async function scrapeContent(url: string) { - try { - const res = await lust.fetchBody(url); - const $ = load(res); - - class PornhubSearch { - search: object[]; - data: object; - constructor() { - this.search = $("div.wrap") - .map((i, el) => { - const link = $(el).find("a").attr("href"); - const id = link?.split("=")[1]; - const title = $(el).find("a").attr("title"); - const image = $(el).find("img").attr("src"); - const duration = $(el).find("var.duration").text(); - const views = $(el).find("div.videoDetailsBlock").find("span.views").text(); - return { - link: `${c.PORNHUB}${link}`, - id: id, - title: title, - image: image, - duration: duration, - views: views, - video: `${c.PORNHUB}/embed/${id}`, - }; - }).get(); - - this.data = this.search.filter((el: any) => { - return el.link.includes("javascript:void(0)") === false && el.image?.startsWith("data:image") === false; - }); - } - - } - - const ph = new PornhubSearch(); - if (ph.search.length === 0) throw Error("No result found"); - const data = ph.data as string[]; - const result: ISearchVideoData = { - success: true, - data: data, - source: url, - }; - return result; - - - - } catch (err) { - const e = err as Error; - throw Error(e.message); - } -} \ No newline at end of file +import { load } from "cheerio"; +import { lust } from "../../LustPress"; +import c from "../../utils/options"; +import { ISearchVideoData, PornhubSearchItem } from "../../interfaces"; + +export async function scrapeContent(url: string) { + try { + const res = await lust.fetchBody(url); + const $ = load(res); + + class PornhubSearch { + search: PornhubSearchItem[]; + data: PornhubSearchItem[]; + constructor() { + this.search = $("div.wrap") + .map((i, el) => { + const link = $(el).find("a").attr("href") || ""; + const id = link.split("=")[1] || "None"; + const title = $(el).find("a").attr("title") || "None"; + const image = $(el).find("img").attr("src") || "None"; + const duration = $(el).find("var.duration").text() || "None"; + const views = $(el).find("div.videoDetailsBlock").find("span.views").text() || "None"; + return { + link: `${c.PORNHUB}${link}`, + id: id, + title: title, + image: image, + duration: duration, + views: views, + video: `${c.PORNHUB}/embed/${id}`, + }; + }).get(); + + this.data = this.search.filter((el) => { + return el.link.includes("javascript:void(0)") === false && el.image?.startsWith("data:image") === false; + }); + } + + } + + const ph = new PornhubSearch(); + if (ph.search.length === 0) throw Error("No result found"); + const result: ISearchVideoData = { + success: true, + data: ph.data as unknown as string[], + source: url, + }; + return result; + + } catch (err) { + const e = err as Error; + throw Error(e.message); + } +} \ No newline at end of file diff --git a/src/scraper/redtube/redtubeSearchController.ts b/src/scraper/redtube/redtubeSearchController.ts index f05c677..44b6ab9 100644 --- a/src/scraper/redtube/redtubeSearchController.ts +++ b/src/scraper/redtube/redtubeSearchController.ts @@ -1,72 +1,63 @@ -import { load } from "cheerio"; -import LustPress from "../../LustPress"; -import c from "../../utils/options"; -import { ISearchVideoData } from "../../interfaces"; - -const lust = new LustPress(); - -export async function scrapeContent(url: string) { - try { - const res = await lust.fetchBody(url); - const $ = load(res); - - class RedTubeSearch { - views: string[]; - search: object[]; - data: object; - constructor() { - this.views = $("span.video_count") - .map((i, el) => { - const views = $(el).text(); - return views; - }).get(); - this.search = $("a.video_link") - .map((i, el) => { - const link = $(el).attr("href"); - const id = link?.split("/")[1]; - const title = $(el).find("img").attr("alt"); - const image = $(el).find("img").attr("data-src"); - const duration = $(el).find("span.duration").text().split(" ").map((el: string) => { - return el.replace(/[^0-9:]/g, ""); - }).filter((el: string) => { - return el.includes(":"); - }).join(" "); - - return { - link: `${c.REDTUBE}${link}`, - id: id, - title: title, - image: image, - duration: duration, - views: this.views[i], - video: `https://embed.redtube.com/?id=${id}`, - - }; - }).get(); - - - - - this.data = this.search.filter((el: any) => { - return el.link.includes("javascript:void(0)") === false && el.image?.startsWith("data:image") === false; - }); - } - - } - - const red = new RedTubeSearch(); - - if (red.search.length === 0) throw Error("No result found"); - const data = red.data as string[]; - const result: ISearchVideoData = { - success: true, - data: data, - source: url, - }; - return result; - - } catch (err) { - const e = err as Error; - throw Error(e.message); - } -} \ No newline at end of file +import { load } from "cheerio"; +import { lust } from "../../LustPress"; +import c from "../../utils/options"; +import { ISearchVideoData, RedTubeSearchItem } from "../../interfaces"; + +export async function scrapeContent(url: string) { + try { + const res = await lust.fetchBody(url); + const $ = load(res); + + class RedTubeSearch { + views: string[]; + search: RedTubeSearchItem[]; + data: RedTubeSearchItem[]; + constructor() { + this.views = $("span.video_count") + .map((i, el) => { + return $(el).text(); + }).get(); + this.search = $("a.video_link") + .map((i, el) => { + const link = $(el).attr("href") || ""; + const id = link.split("/")[1] || "None"; + const title = $(el).find("img").attr("alt") || "None"; + const image = $(el).find("img").attr("data-src") || "None"; + const duration = $(el).find("span.duration").text().split(" ").map((el: string) => { + return el.replace(/[^0-9:]/g, ""); + }).filter((el: string) => { + return el.includes(":"); + }).join(" "); + + return { + link: `${c.REDTUBE}${link}`, + id: id, + title: title, + image: image, + duration: duration, + views: this.views[i] || "None", + video: `https://embed.redtube.com/?id=${id}`, + }; + }).get(); + + this.data = this.search.filter((el) => { + return el.link.includes("javascript:void(0)") === false && el.image?.startsWith("data:image") === false; + }); + } + } + + const red = new RedTubeSearch(); + + if (red.search.length === 0) throw Error("No result found"); + const result: ISearchVideoData = { + success: true, + data: red.data as unknown as string[], + source: url, + }; + return result; + + } catch (err) { + const e = err as Error; + throw Error(e.message); + } +} \ No newline at end of file diff --git a/src/scraper/xhamster/xhamsterGetController.ts b/src/scraper/xhamster/xhamsterGetController.ts index 2680602..5231e46 100644 --- a/src/scraper/xhamster/xhamsterGetController.ts +++ b/src/scraper/xhamster/xhamsterGetController.ts @@ -1,8 +1,6 @@ import { load } from "cheerio"; -import LustPress from "../../LustPress"; -import { IVideoData } from "../../interfaces"; - -const lust = new LustPress(); +import { lust } from "../../LustPress"; +import { IVideoData, XhamsterInitials } from "../../interfaces"; export async function scrapeContent(url: string) { try { @@ -10,11 +8,11 @@ export async function scrapeContent(url: string) { const $ = load(buffer.toString("utf8")); const raw = $("#initials-script").html(); - const initials = raw + const initials = (raw ? JSON.parse( raw.replace(/^window\.initials\s*=\s*/, "").replace(/;$/, ""), ) - : null; + : null) as XhamsterInitials | null; class Xhamster { link: string; @@ -71,13 +69,13 @@ export async function scrapeContent(url: string) { this.tags = initials?.videoTagsComponent?.tags - ?.filter((t: any) => t.isTag) - .map((t: any) => t.name) || []; + ?.filter((t) => t.isTag) + .map((t) => t.name) || []; this.models = initials?.videoTagsComponent?.tags - ?.filter((t: any) => t.isPornstar) - .map((t: any) => t.name) || []; + ?.filter((t) => t.isPornstar) + .map((t) => t.name) || []; const embedId = this.link.split("-").pop()?.replace("/", ""); this.video = embedId ? `https://xhamster.com/embed/${embedId}` : "None"; @@ -109,3 +107,4 @@ export async function scrapeContent(url: string) { throw new Error(e.message); } } + diff --git a/src/scraper/xhamster/xhamsterSearchController.ts b/src/scraper/xhamster/xhamsterSearchController.ts index 8ff2dea..45fd9fe 100644 --- a/src/scraper/xhamster/xhamsterSearchController.ts +++ b/src/scraper/xhamster/xhamsterSearchController.ts @@ -1,59 +1,54 @@ -import { load } from "cheerio"; -import LustPress from "../../LustPress"; -import c from "../../utils/options"; -import { ISearchVideoData } from "../../interfaces"; - -const lust = new LustPress(); - -export async function scrapeContent(url: string) { - try { - const res = await lust.fetchBody(url); - const $ = load(res); - - class XhamsterSearch { - search: any; - constructor() { - const views = $("div.video-thumb-views") - .map((i, el) => { - const views = $(el).text(); - return views; - }) - .get(); - const duration = $("span[data-role='video-duration']") - .map((i, el) => { - const duration = $(el).text(); - return duration; - }) - .get(); - this.search = $("a.video-thumb__image-container") - .map((i, el) => { - const link = $(el).attr("href"); - - return { - link: `${link}`, - id: link?.split("/")[4], - title: $(el).find("img").attr("alt"), - image: $(el).find("img").attr("src"), - duration: duration[i], - views: views[i], - video: `${c.XHAMSTER}/embed/${link?.split("-").pop()}`, - }; - }) - .get(); - } - } - - const xh = new XhamsterSearch(); - if (xh.search.length === 0) throw Error("No result found"); - const data = xh.search as unknown as string[]; - const result: ISearchVideoData = { - success: true, - data: data, - source: url, - }; - return result; - } catch (err) { - const e = err as Error; - throw Error(e.message); - } -} \ No newline at end of file +import { load } from "cheerio"; +import { lust } from "../../LustPress"; +import c from "../../utils/options"; +import { ISearchVideoData, XhamsterSearchItem } from "../../interfaces"; + +export async function scrapeContent(url: string) { + try { + const res = await lust.fetchBody(url); + const $ = load(res); + + class XhamsterSearch { + search: XhamsterSearchItem[]; + constructor() { + const views = $("div.video-thumb-views") + .map((i, el) => { + return $(el).text(); + }) + .get(); + const duration = $("span[data-role='video-duration']") + .map((i, el) => { + return $(el).text(); + }) + .get(); + this.search = $("a.video-thumb__image-container") + .map((i, el) => { + const link = $(el).attr("href") || ""; + + return { + link: link, + id: link.split("/")[4] || "None", + title: $(el).find("img").attr("alt") || "None", + image: $(el).find("img").attr("src") || "None", + duration: duration[i] || "None", + views: views[i] || "None", + video: `${c.XHAMSTER}/embed/${link.split("-").pop()}`, + }; + }) + .get(); + } + } + + const xh = new XhamsterSearch(); + if (xh.search.length === 0) throw Error("No result found"); + const result: ISearchVideoData = { + success: true, + data: xh.search as unknown as string[], + source: url, + }; + return result; + } catch (err) { + const e = err as Error; + throw Error(e.message); + } +} \ No newline at end of file diff --git a/src/scraper/xnxx/xnxxGetRelatedController.ts b/src/scraper/xnxx/xnxxGetRelatedController.ts index cf8a1a2..9fd8705 100644 --- a/src/scraper/xnxx/xnxxGetRelatedController.ts +++ b/src/scraper/xnxx/xnxxGetRelatedController.ts @@ -1,56 +1,49 @@ -import { load } from "cheerio"; -import LustPress from "../../LustPress"; -import c from "../../utils/options"; -import { ISearchVideoData } from "../../interfaces"; - -const lust = new LustPress(); - -export async function scrapeContent(url: string) { - try { - const res = await lust.fetchBody(url); - const $ = load(res); - - class PornhubSearch { - search: object[]; - data: object; - constructor() { - // in
get