add full support for XNXX

This commit is contained in:
La macchina desiderante 2024-05-12 16:12:26 +02:00
parent a77f009b2a
commit 9639847442
4 changed files with 106 additions and 1 deletions

View File

@ -1,3 +1,11 @@
export const XVIDEOS_BASE_URL: string = "https://www.xvideos.com"
export const XVIDEOS_BASE_URL_GAY: string = "https://www.xvideos.com/gay"
export const XVIDEOS_BASE_URL_TRANS: string = "https://www.xvideos.com/shemale"
export const XVIDEOS_BASE_URL_TRANS: string = "https://www.xvideos.com/shemale"
export const XNXX_BASE_URL: string = 'https://www.xnxx.com'
export const XNXX_BASE_URL_ETERO: string = 'https://www.xnxx.com/best'
export const XNXX_BASE_URL_GAY: string = 'https://www.xnxx.com/best-of-gay'
export const XNXX_BASE_URL_TRANS: string = 'https://www.xnxx.com/best-of-shemale'
export const XNXX_BASE_SEARCH: string = 'https://www.xnxx.com/search'

View File

@ -5,6 +5,9 @@ import { Platforms } from "@/meta/settings";
import { fetchXVideosGalleryData } from "./scrape/xvideos/gallery";
import { fetchXvideosVideoData } from "./scrape/xvideos/video";
import { fetchXNXXGalleryData } from "./scrape/xnxx/gallery";
import { XNXX_BASE_URL } from "@/constants/urls";
export class VideoAgent {
platform: Platforms;
@ -16,6 +19,8 @@ export class VideoAgent {
switch (this.platform) {
case Platforms.xvideos:
return await fetchXVideosGalleryData(params)
case Platforms.xnxx:
return await fetchXNXXGalleryData(params)
default:
return []
}
@ -25,6 +30,8 @@ export class VideoAgent {
switch (this.platform) {
case Platforms.xvideos:
return await fetchXvideosVideoData(id, params)
case Platforms.xnxx:
return await fetchXvideosVideoData(id, { ...params, baseUrl: XNXX_BASE_URL })
default:
return [{ lowResUrl: '' }, []]
}

View File

@ -0,0 +1,50 @@
import { FetchParams, GalleryData } from '@/meta/data';
import axios, { AxiosError } from 'axios';
import * as cheerio from "cheerio";
import { getHeaders } from '../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
}

View File

@ -0,0 +1,40 @@
import { XNXX_BASE_SEARCH, XNXX_BASE_URL_ETERO, XNXX_BASE_URL_GAY, XNXX_BASE_URL_TRANS } from '@/constants/urls';
import { Cookies, XVideosCatQueryMap, XVideosOrientations } from '@/meta/settings';
import { getCookie } from '@/utils/cookies/read';
export const getXNXXQueryUrl = async (query?: string) => {
const category = await getCookie(Cookies.orientation)
if (!category && !query) {
return XNXX_BASE_URL_ETERO
}
if (!category && query) {
return `${XNXX_BASE_SEARCH}/${query}`
}
if (category && !Object.values(XVideosOrientations).includes(category.value as XVideosOrientations)) {
return XNXX_BASE_URL_ETERO
}
if (category && !query) {
switch (category.value) {
case XVideosOrientations.etero:
return XNXX_BASE_URL_ETERO
case XVideosOrientations.gay:
return XNXX_BASE_URL_GAY
case XVideosOrientations.trans:
return XNXX_BASE_URL_TRANS
default:
return XNXX_BASE_URL_ETERO;
}
}
if (category && query) {
return `${XNXX_BASE_SEARCH}/${XVideosCatQueryMap[category.value as XVideosOrientations]}/${query}`
}
return XNXX_BASE_URL_ETERO
}