From 4e789ddce11068e8444edbe1b75d75c880e94c5d Mon Sep 17 00:00:00 2001 From: La macchina desiderante Date: Sat, 11 May 2024 19:46:51 +0200 Subject: [PATCH] now category filter is working properly --- .../Menu/Settings/Modal/Category/index.tsx | 6 +-- .../Menu/Settings/Modal/Platform/index.tsx | 6 +-- .../Layout/Header/Menu/Theme/index.tsx | 6 +-- src/constants/urls.ts | 4 +- src/meta/settings.ts | 12 ++++++ src/utils/scrape/xvideos/gallery.ts | 4 +- src/utils/scrape/xvideos/url.ts | 40 +++++++++++++++++++ 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/utils/scrape/xvideos/url.ts diff --git a/src/components/Layout/Header/Menu/Settings/Modal/Category/index.tsx b/src/components/Layout/Header/Menu/Settings/Modal/Category/index.tsx index bece1e6..4e2552d 100644 --- a/src/components/Layout/Header/Menu/Settings/Modal/Category/index.tsx +++ b/src/components/Layout/Header/Menu/Settings/Modal/Category/index.tsx @@ -1,6 +1,6 @@ 'use client' -import { XVideosCategories } from '@/meta/settings'; +import { Cookies, XVideosCategories } from '@/meta/settings'; import css from './Category.module.scss' @@ -19,12 +19,12 @@ const Category: React.FC = (props) => { const { labels } = props - const [cookies] = useCookies(['category']); + const [cookies] = useCookies([Cookies.category]); const handleChange = async (event: React.ChangeEvent) => { const value = event.target.value; - await setCookie('category', value) + await setCookie(Cookies.category, value) } return ( diff --git a/src/components/Layout/Header/Menu/Settings/Modal/Platform/index.tsx b/src/components/Layout/Header/Menu/Settings/Modal/Platform/index.tsx index 37d4738..4a19f4f 100644 --- a/src/components/Layout/Header/Menu/Settings/Modal/Platform/index.tsx +++ b/src/components/Layout/Header/Menu/Settings/Modal/Platform/index.tsx @@ -1,6 +1,6 @@ 'use client' -import { Platforms } from '@/meta/settings'; +import { Cookies, Platforms } from '@/meta/settings'; import css from './Platform.module.scss' @@ -19,12 +19,12 @@ const Platform: React.FC = (props) => { const { labels } = props - const [cookies] = useCookies(['platform']); + const [cookies] = useCookies([Cookies.platform]); const handleChange = async (event: React.ChangeEvent) => { const value = event.target.value; - await setCookie('platform', value) + await setCookie(Cookies.platform, value) } return ( diff --git a/src/components/Layout/Header/Menu/Theme/index.tsx b/src/components/Layout/Header/Menu/Theme/index.tsx index 142273a..94bcbca 100644 --- a/src/components/Layout/Header/Menu/Theme/index.tsx +++ b/src/components/Layout/Header/Menu/Theme/index.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { TbMoon, TbSun } from 'react-icons/tb'; -import { DEFAULT_THEME, Themes } from '@/meta/settings'; +import { Cookies, DEFAULT_THEME, Themes } from '@/meta/settings'; import Icon from '../Icon'; import { setCookie } from '@/utils/cookies/write'; @@ -11,13 +11,13 @@ import { useCookies } from 'react-cookie'; const Theme: React.FC = () => { - const [cookies] = useCookies(['theme']); + const [cookies] = useCookies([Cookies.theme]); const theme = cookies.theme ?? DEFAULT_THEME const handleClick = async () => { const newTheme = theme == Themes.dark ? Themes.light : Themes.dark - await setCookie('theme', newTheme) + await setCookie(Cookies.theme, newTheme) } return ( diff --git a/src/constants/urls.ts b/src/constants/urls.ts index 87953cd..358e6b4 100644 --- a/src/constants/urls.ts +++ b/src/constants/urls.ts @@ -1 +1,3 @@ -export const XVIDEOS_BASE_URL: string = "https://www.xvideos.com" \ No newline at end of file +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" \ No newline at end of file diff --git a/src/meta/settings.ts b/src/meta/settings.ts index ffb8ad6..1326ecd 100644 --- a/src/meta/settings.ts +++ b/src/meta/settings.ts @@ -1,8 +1,20 @@ +export enum Cookies { + theme= 'theme', + category= 'category', + platform= 'platform' +} + export enum Platforms { xvideos= 'xvideos', xnxx= 'xnxx' } +export enum XVideosCatQueryMap { + etero= 'straight', + gay= 'gay', + trans= 'shemale' +} + export enum XVideosCategories { etero= 'etero', gay= 'gay', diff --git a/src/utils/scrape/xvideos/gallery.ts b/src/utils/scrape/xvideos/gallery.ts index 51d617b..6efbe55 100644 --- a/src/utils/scrape/xvideos/gallery.ts +++ b/src/utils/scrape/xvideos/gallery.ts @@ -1,9 +1,9 @@ -import { XVIDEOS_BASE_URL } from '@/constants/urls'; import { GalleryData } from '@/meta/data'; import axios, { AxiosError } from 'axios'; import * as cheerio from "cheerio"; import { getHeaders } from '../headers'; +import { getXVideosQueryUrl } from './url'; interface FetchParams { baseUrl?: string @@ -16,7 +16,7 @@ export const fetchGalleryData = async (params?: FetchParams): Promise { + + const category = await getCookie(Cookies.category) + + if (!category && !query) { + return XVIDEOS_BASE_URL + } + + if (!category && query) { + return `${XVIDEOS_BASE_URL}/?k=${query}` + } + + if (category && !Object.values(XVideosCategories).includes(category.value as XVideosCategories)) { + return XVIDEOS_BASE_URL + } + + if (category && !query) { + switch (category.value) { + case XVideosCategories.etero: + return XVIDEOS_BASE_URL + case XVideosCategories.gay: + return XVIDEOS_BASE_URL_GAY + case XVideosCategories.trans: + return XVIDEOS_BASE_URL_TRANS + default: + return XVIDEOS_BASE_URL; + } + } + + if (category && query) { + return `${XVIDEOS_BASE_URL}/?k=${query}&typef=${XVideosCatQueryMap[category.value as XVideosCategories]}` + } + + return XVIDEOS_BASE_URL + +} \ No newline at end of file