* 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
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
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);
|
|
}
|
|
}
|