Files
lustpress/src/controller/xhamster/xhamsterRandom.ts
Indrawan I. cd32689b47 feat(core): hard remake with bun and elysia (#19)
* static files changes

* remake modifiers

* test case

* some docs changes

* deps and rule changes

* edit proper interfaces

* remake getServer

* @elysiajs/swagger

* remake tsconfig

* ci changes use bun

* docs changes

* feat(core): hard remake with bun and elysia

* chore(release): 8.2.0-alpha

* auto release

* ci

* update global

* chore(release): 8.2.1-alpha

* ci
2026-05-14 04:57:54 +07:00

32 lines
925 B
TypeScript

import { scrapeContent } from "../../scraper/xhamster/xhamsterGetController";
import c from "../../utils/options";
import { load } from "cheerio";
import { lust } from "../../LustPress";
export async function randomXhamster() {
try {
const resolve = await lust.fetchBody(`${c.XHAMSTER}/newest`);
const $ = load(resolve);
const videoLinks = $("div.thumb-list__item[data-video-id]")
.map((_, el) => {
const href = $(el).find("a[data-role='thumb-link']").attr("href");
return href && href.includes("/videos/") ? href : null;
})
.get()
.filter(Boolean);
// Select a random video URL from the list
const randomIndex = Math.floor(Math.random() * videoLinks.length);
const randomUrl = videoLinks[randomIndex];
const data = await scrapeContent(randomUrl);
return data;
} catch (err) {
const e = err as Error;
throw new Error(e.message);
}
}