Release v0.4.0: Add Redtube support #103
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Cookies, Platforms, XVideosOrientations, PornHubOrientations, YouPornOrientations } from '@/meta/settings';
|
import { Cookies, Platforms, XVideosOrientations, PornHubOrientations, YouPornOrientations, RedTubeOrientations } from '@/meta/settings';
|
||||||
|
|
||||||
import css from './Orientation.module.scss'
|
import css from './Orientation.module.scss'
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@ const getOrientations = (platform: Platforms):Object => {
|
||||||
return YouPornOrientations
|
return YouPornOrientations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if([Platforms.redtube].includes(platform)) {
|
||||||
|
return RedTubeOrientations
|
||||||
|
}
|
||||||
|
|
||||||
return PornHubOrientations
|
return PornHubOrientations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Cookies, Platforms, PornHubOrientations, XVideosOrientations, YouPornOrientations } from '@/meta/settings';
|
import { Cookies, Platforms, PornHubOrientations, RedTubeOrientations, XVideosOrientations, YouPornOrientations } from '@/meta/settings';
|
||||||
|
|
||||||
import css from './Platform.module.scss'
|
import css from './Platform.module.scss'
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@ const mapOrientationToPlatform = (platform: string, orientation: string): string
|
||||||
return Object.keys(PornHubOrientations).includes(orientation) ? orientation : String(PornHubOrientations.generic)
|
return Object.keys(PornHubOrientations).includes(orientation) ? orientation : String(PornHubOrientations.generic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([String(Platforms.redtube)].includes(platform)) {
|
||||||
|
return Object.keys(RedTubeOrientations).includes(orientation) ? orientation : String(RedTubeOrientations.etero)
|
||||||
|
}
|
||||||
|
|
||||||
if ([String(Platforms.youporn)].includes(platform)) {
|
if ([String(Platforms.youporn)].includes(platform)) {
|
||||||
return String(YouPornOrientations.generic)
|
return String(YouPornOrientations.generic)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,7 @@ export const DEFAULT_XNXX_CONTENT_EXPIRY = { EX: EX_HOURLY };
|
||||||
export const DEFAULT_YOUPORN_GALLERY_EXPIRY = { EX: EX_HOURLY };
|
export const DEFAULT_YOUPORN_GALLERY_EXPIRY = { EX: EX_HOURLY };
|
||||||
export const DEFAULT_YOUPORN_VIDEO_EXPIRY = { EX: EX_HOURLY };
|
export const DEFAULT_YOUPORN_VIDEO_EXPIRY = { EX: EX_HOURLY };
|
||||||
|
|
||||||
|
export const DEFAULT_REDTUBE_GALLERY_EXPIRY = { EX: EX_HOURLY };
|
||||||
|
export const DEFAULT_REDTUBE_VIDEO_EXPIRY = { EX: EX_HOURLY };
|
||||||
|
|
||||||
export const DEFAULT_RELATED_VIDEO_KEY_PATH = '/related/'
|
export const DEFAULT_RELATED_VIDEO_KEY_PATH = '/related/'
|
|
@ -29,3 +29,12 @@ export const YOUPORN_BASE_URL: string = 'https://www.youporn.com'
|
||||||
export const YOUPORN_BASE_URL_VIDEO: string = 'https://www.youporn.com/watch'
|
export const YOUPORN_BASE_URL_VIDEO: string = 'https://www.youporn.com/watch'
|
||||||
|
|
||||||
export const YOUPORN_BASE_SEARCH: string = 'https://www.youporn.com/search/?search-btn=&query='
|
export const YOUPORN_BASE_SEARCH: string = 'https://www.youporn.com/search/?search-btn=&query='
|
||||||
|
|
||||||
|
// REDTUBE
|
||||||
|
|
||||||
|
export const REDTUBE_BASE_URL: string = 'https://www.redtube.com'
|
||||||
|
export const REDTUBE_BASE_URL_GAY: string = 'https://www.redtube.com/gay'
|
||||||
|
export const REDTUBE_BASE_URL_TRANS: string = 'https://www.redtube.com/redtube/transgender'
|
||||||
|
|
||||||
|
export const REDTUBE_BASE_SEARCH: string = 'https://www.redtube.com/?search='
|
||||||
|
export const REDTUBE_BASE_GAY_SEARCH: string = 'https://www.redtube.com/gay?search='
|
|
@ -33,6 +33,12 @@ export enum YouPornOrientations {
|
||||||
generic= 'generic'
|
generic= 'generic'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum RedTubeOrientations {
|
||||||
|
etero= 'etero',
|
||||||
|
gay= 'gay',
|
||||||
|
trans= 'trans'
|
||||||
|
}
|
||||||
|
|
||||||
export enum Themes {
|
export enum Themes {
|
||||||
light= 'light',
|
light= 'light',
|
||||||
dark= 'dark',
|
dark= 'dark',
|
||||||
|
|
|
@ -1,8 +1,60 @@
|
||||||
import { FetchParams, GalleryData } from "@/meta/data";
|
import { FetchParams, GalleryData } from "@/meta/data";
|
||||||
|
import { getHeaders } from "../common/headers";
|
||||||
|
import { REDTUBE_BASE_URL } from "@/constants/urls";
|
||||||
|
import { getRedTubeQueryUrl, getRedTubeResultsWrapperId } from "./url";
|
||||||
|
import { getDataFromRedis, storeDataIntoRedis } from "@/redis/client";
|
||||||
|
|
||||||
|
import * as cheerio from "cheerio";
|
||||||
|
|
||||||
|
import axios, { AxiosError } from "axios";
|
||||||
|
import { Platforms } from "@/meta/settings";
|
||||||
|
import { DEFAULT_REDTUBE_GALLERY_EXPIRY } from "@/constants/redis";
|
||||||
|
|
||||||
export const fetchRedTubeGalleryData = async (params?: FetchParams): Promise<GalleryData[]> => {
|
export const fetchRedTubeGalleryData = async (params?: FetchParams): Promise<GalleryData[]> => {
|
||||||
|
|
||||||
let data: GalleryData[] = [];
|
let data: GalleryData[] = [];
|
||||||
|
|
||||||
|
const reqHeaders = getHeaders(REDTUBE_BASE_URL)
|
||||||
|
|
||||||
|
const queryUrl = await getRedTubeQueryUrl(params?.query)
|
||||||
|
|
||||||
|
const cachedData = await getDataFromRedis(queryUrl)
|
||||||
|
|
||||||
|
if (cachedData) {
|
||||||
|
return cachedData as GalleryData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.get(queryUrl, reqHeaders)
|
||||||
|
|
||||||
|
.then(async response => {
|
||||||
|
|
||||||
|
const html = response.data;
|
||||||
|
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
const wrapperId = await getRedTubeResultsWrapperId(params?.query)
|
||||||
|
|
||||||
|
const thumbs = $(wrapperId);
|
||||||
|
|
||||||
|
thumbs.map((key, thumb) => {
|
||||||
|
|
||||||
|
const videoUrl = $(thumb).find("a.video_link").attr("href")?.split('/')[1];
|
||||||
|
const imgUrl = $(thumb).find("img.js_thumbImageTag").attr("data-src")
|
||||||
|
const text = $(thumb).find("a.tm_video_title").attr("title");
|
||||||
|
|
||||||
|
videoUrl && imgUrl && text && data.push({
|
||||||
|
videoUrl,
|
||||||
|
imgUrl,
|
||||||
|
text,
|
||||||
|
platform: Platforms.redtube
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
await storeDataIntoRedis(queryUrl, data, DEFAULT_REDTUBE_GALLERY_EXPIRY);
|
||||||
|
|
||||||
|
}).catch((error: AxiosError) => {
|
||||||
|
// handle errors
|
||||||
|
});
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { getCookie } from "@/utils/cookies/read"
|
||||||
|
|
||||||
|
import { Cookies, RedTubeOrientations } from "@/meta/settings"
|
||||||
|
import { REDTUBE_BASE_SEARCH, REDTUBE_BASE_GAY_SEARCH, REDTUBE_BASE_URL_GAY, REDTUBE_BASE_URL, REDTUBE_BASE_URL_TRANS } from "@/constants/urls"
|
||||||
|
|
||||||
|
export const getRedTubeQueryUrl = async (query?: string): Promise<string> => {
|
||||||
|
const orientation = await getCookie(Cookies.orientation)
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
return `${orientation && orientation.value == RedTubeOrientations.gay ?
|
||||||
|
REDTUBE_BASE_GAY_SEARCH :
|
||||||
|
REDTUBE_BASE_SEARCH}${query}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation && orientation.value == RedTubeOrientations.gay ) {
|
||||||
|
return REDTUBE_BASE_URL_GAY
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation && orientation.value == RedTubeOrientations.trans ) {
|
||||||
|
return REDTUBE_BASE_URL_TRANS
|
||||||
|
}
|
||||||
|
|
||||||
|
return REDTUBE_BASE_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getRedTubeResultsWrapperId = async (query?: string): Promise<string> => {
|
||||||
|
const orientation = await getCookie(Cookies.orientation)
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
return ".videos_grid li"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation && ((orientation.value == RedTubeOrientations.gay) || (orientation.value == RedTubeOrientations.trans))) {
|
||||||
|
return "#block_browse li"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "#most_recent_videos li"
|
||||||
|
}
|
Loading…
Reference in New Issue