50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { FetchParams, GalleryData } from '@/meta/data';
|
|
import axios, { AxiosError } from 'axios';
|
|
|
|
import * as cheerio from "cheerio";
|
|
|
|
import { getHeaders } from '@/utils/scrape/common/headers';
|
|
import { getXNXXQueryUrl } from './url';
|
|
|
|
import { Platforms } from '@/meta/settings';
|
|
import { XNXX_BASE_URL } from '@/constants/urls';
|
|
|
|
export const fetchXNXXGalleryData = async (params?: FetchParams): Promise<GalleryData[]> => {
|
|
|
|
let data: GalleryData[] = [];
|
|
|
|
const reqHeaders = getHeaders(XNXX_BASE_URL)
|
|
|
|
const queryUrl = await getXNXXQueryUrl(params?.query)
|
|
|
|
await axios.get(queryUrl, reqHeaders)
|
|
|
|
.then(response => {
|
|
|
|
const html = response.data;
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
const thumbs = $(".thumb-block");
|
|
|
|
thumbs.map((key, thumb) => {
|
|
|
|
const videoUrl = $(thumb).find(".thumb a").attr("href")
|
|
const imgUrl = $(thumb).find(".thumb img").attr("data-src")
|
|
const text = $(thumb).find(".thumb-under a").attr("title")
|
|
|
|
videoUrl && imgUrl && text && data.push({
|
|
videoUrl,
|
|
imgUrl,
|
|
text,
|
|
platform: Platforms.xnxx
|
|
})
|
|
})
|
|
|
|
}).catch((error: AxiosError) => {
|
|
// handle errors
|
|
});
|
|
|
|
|
|
return data
|
|
} |