add PornHub orientations and switching mechanism

This commit is contained in:
La macchina desiderante 2024-05-24 21:45:42 +02:00
parent 6efe6582a5
commit b0710671b3
6 changed files with 75 additions and 21 deletions

View File

@ -1,6 +1,6 @@
'use client'
import { Cookies, XVideosOrientations } from '@/meta/settings';
import { Cookies, Platforms, XVideosOrientations, PornHubOrientations } from '@/meta/settings';
import css from './Orientation.module.scss'
@ -16,11 +16,21 @@ interface Props {
}
}
const getOrientations = (platform: Platforms):Object => {
if ([Platforms.xnxx, Platforms.xvideos].includes(platform)) {
return XVideosOrientations
}
return PornHubOrientations
}
const Orientation: React.FC<Props> = (props) => {
const { labels, handleClose } = props
const [cookies] = useCookies([Cookies.orientation]);
const [cookies] = useCookies([Cookies.orientation, Cookies.platform]);
const orientationsList = cookies.platform ? getOrientations(cookies.platform ) : XVideosOrientations
const handleChange = async (event: React.ChangeEvent<HTMLSelectElement>) => {
const value = event.target.value;
@ -34,7 +44,7 @@ const Orientation: React.FC<Props> = (props) => {
<div className={css.container}>
<div className={css.title}>{labels.title}</div>
<select defaultValue={ cookies.orientation ?? XVideosOrientations.etero } onChange={handleChange} name={'orientation'} aria-label={labels.title}>
{Object.keys(XVideosOrientations).map((elem, key) => {
{Object.keys(orientationsList).map((elem, key) => {
return <option className={css.option} key={key} value={elem}>{elem.toUpperCase()}</option>
})}
</select>

View File

@ -1,6 +1,6 @@
'use client'
import { Cookies, Platforms } from '@/meta/settings';
import { Cookies, Platforms, PornHubOrientations, XVideosOrientations } from '@/meta/settings';
import css from './Platform.module.scss'
@ -16,24 +16,41 @@ interface Props {
}
}
const mapOrientationToPlatform = (platform: string, orientation: string): string | undefined => {
if ([String(Platforms.xnxx), String(Platforms.xvideos)].includes(platform)) {
return Object.keys(XVideosOrientations).includes(orientation) ? orientation : String(XVideosOrientations.etero)
}
if ([String(Platforms.pornhub)].includes(platform)) {
return Object.keys(PornHubOrientations).includes(orientation) ? orientation : String(PornHubOrientations.generic)
}
}
const Platform: React.FC<Props> = (props) => {
const { labels, handleClose } = props
const [cookies] = useCookies([Cookies.platform]);
const [cookies] = useCookies([Cookies.platform, Cookies.orientation]);
const handleChange = async (event: React.ChangeEvent<HTMLSelectElement>) => {
const value = event.target.value;
await setCookie(Cookies.platform, value)
if (cookies.orientation) {
const newOrientation = mapOrientationToPlatform(value, cookies.orientation)
newOrientation && await setCookie(Cookies.orientation, newOrientation)
}
handleClose()
}
return (
<div className={css.container}>
<div className={css.title}>{labels.title}</div>
<select defaultValue={ cookies.platform ?? Platforms.xvideos } onChange={handleChange} name={'platform'} aria-label={labels.title}>
<select defaultValue={cookies.platform ?? Platforms.xvideos} onChange={handleChange} name={'platform'} aria-label={labels.title}>
{Object.keys(Platforms).map((elem, key) => {
return <option className={css.option} key={key} value={elem}>{elem.toUpperCase()}</option>
})}

View File

@ -19,3 +19,6 @@ export const XNXX_BASE_SEARCH: string = 'https://www.xnxx.com/search'
export const PORNHUB_BASE_URL: string = 'https://www.pornhub.com'
export const PORNHUB_BASE_URL_VIDEO: string = 'https://www.pornhub.com/view_video.php?viewkey='
export const PORNHUB_BASE_URL_GAY: string = 'https://www.pornhub.com/gayporn'
export const PORNHUB_BASE_URL_GAY_SEARCH: string = 'https://www.pornhub.com/gay'

View File

@ -22,6 +22,11 @@ export enum XVideosOrientations {
trans= 'trans'
}
export enum PornHubOrientations {
generic= 'generic',
gay= 'gay'
}
export enum Themes {
light= 'light',
dark= 'dark',

View File

@ -2,7 +2,7 @@ import { PORNHUB_BASE_URL } from "@/constants/urls";
import { FetchParams, GalleryData } from "@/meta/data";
import { getHeaders } from "../common/headers";
import { getDataFromRedis, storeDataIntoRedis } from "@/redis/client";
import { getPornHubQueryUrl } from "./url";
import { getPornHubQueryUrl, getPornHubResultsWrapperId } from "./url";
import * as cheerio from "cheerio";
@ -33,7 +33,7 @@ export const fetchPornHubGalleryData = async (params?: FetchParams): Promise<Gal
const $ = cheerio.load(html);
const wrapperId = params?.query ? "#videoSearchResult li" : "#singleFeedSection li"
const wrapperId = await getPornHubResultsWrapperId(params?.query)
const thumbs = $(wrapperId);

View File

@ -1,8 +1,9 @@
import { PORNHUB_BASE_URL } from "@/constants/urls"
import { PORNHUB_BASE_URL, PORNHUB_BASE_URL_GAY, PORNHUB_BASE_URL_GAY_SEARCH } from "@/constants/urls"
import axios, { AxiosHeaders } from "axios"
import { getHeadersWithCookie } from "../common/headers"
import { GalleryData, VideoSourceItem } from "@/meta/data"
import { Platforms } from "@/meta/settings"
import { Cookies, Platforms, PornHubOrientations } from "@/meta/settings"
import { getCookie } from "@/utils/cookies/read"
interface PornHubVideoSrcElem {
videoUrl: string
@ -10,11 +11,29 @@ interface PornHubVideoSrcElem {
}
export const getPornHubQueryUrl = async (query?: string): Promise<string> => {
const orientation = await getCookie(Cookies.orientation)
if (query) {
return `${PORNHUB_BASE_URL}/video/search?search=${query}`
return `${orientation && orientation.value == PornHubOrientations.gay ?
PORNHUB_BASE_URL_GAY_SEARCH :
PORNHUB_BASE_URL}/video/search?search=${query}`
}
return PORNHUB_BASE_URL
return orientation && orientation.value == PornHubOrientations.gay ? PORNHUB_BASE_URL_GAY : PORNHUB_BASE_URL
}
export const getPornHubResultsWrapperId = async (query?: string): Promise<string> => {
const orientation = await getCookie(Cookies.orientation)
if (query) {
return "#videoSearchResult li"
}
if (orientation && orientation.value == PornHubOrientations.gay) {
return "#videoCategory li"
}
return "#singleFeedSection li"
}
export const getPornHubMediaUrlList = async (url: string, sessionCookie: string): Promise<VideoSourceItem[]> => {
@ -47,10 +66,10 @@ export const getPornHubMediaUrlList = async (url: string, sessionCookie: string)
}
function containsAtLeastThreeSpaces(input: string): boolean {
// Conta il numero di spazi nella stringa
const spaceCount = (input.match(/ /g) || []).length;
// Verifica se ci sono almeno tre spazi
return spaceCount >= 3;
// Conta il numero di spazi nella stringa
const spaceCount = (input.match(/ /g) || []).length;
// Verifica se ci sono almeno tre spazi
return spaceCount >= 3;
}
export const getPornHubRelatedVideoData = async (url: string, sessionCookie: string): Promise<GalleryData[]> => {