add YouPorn gallery/search

This commit is contained in:
La macchina desiderante 2024-05-25 19:25:00 +02:00
parent 089dddd385
commit b84ad5127a
4 changed files with 68 additions and 0 deletions

View File

@ -6,5 +6,6 @@ export const DEFAULT_PORNHUB_GALLERY_EXPIRY = { EX: EX_HOURLY };
export const DEFAULT_PORNHUB_VIDEO_EXPIRY = { EX: EX_MIN };
export const DEFAULT_XVIDEOS_CONTENT_EXPIRY = { EX: EX_HOURLY };
export const DEFAULT_XNXX_CONTENT_EXPIRY = { EX: EX_HOURLY };
export const DEFAULT_YOUPORN_GALLERY_EXPIRY = { EX: EX_HOURLY };
export const DEFAULT_RELATED_VIDEO_KEY_PATH = '/related/'

View File

@ -22,3 +22,8 @@ export const PORNHUB_BASE_URL_VIDEO: string = 'https://www.pornhub.com/view_vide
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'
// YOUPORN
export const YOUPORN_BASE_URL: string = 'https://www.youporn.com'
export const YOUPORN_BASE_SEARCH: string = 'https://www.youporn.com/search/?search-btn=&query='

View File

@ -1,8 +1,60 @@
import { YOUPORN_BASE_URL } from "@/constants/urls";
import { FetchParams, GalleryData } from "@/meta/data";
import { getHeaders } from "../common/headers";
import { getYouPornQueryUrl } 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_YOUPORN_GALLERY_EXPIRY } from "@/constants/redis";
export const fetchYouPornGalleryData = async (params?: FetchParams): Promise<GalleryData[]> => {
let data: GalleryData[] = [];
const reqHeaders = getHeaders(YOUPORN_BASE_URL)
const queryUrl = await getYouPornQueryUrl(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 = params?.query ? ".searchResults .video-box" : ".tm_mostRecent_videos_section .video-box"
const thumbs = $(wrapperId);
thumbs.map((key, thumb) => {
const videoUrl = $(thumb).find("a.tm_video_link").attr("href")?.split('/')[2];
const imgUrl = $(thumb).find("img.thumb-image").attr("data-src")
const text = $(thumb).find("a.video-title").text();
videoUrl && imgUrl && text && data.push({
videoUrl,
imgUrl,
text,
platform: Platforms.youporn
})
})
await storeDataIntoRedis(queryUrl, data, DEFAULT_YOUPORN_GALLERY_EXPIRY);
}).catch((error: AxiosError) => {
// handle errors
});
return data
}

View File

@ -0,0 +1,10 @@
import { YOUPORN_BASE_SEARCH, YOUPORN_BASE_URL } from "@/constants/urls"
export const getYouPornQueryUrl = async (query?: string): Promise<string> => {
if (query) {
return `${YOUPORN_BASE_SEARCH}${query}`
}
return YOUPORN_BASE_URL
}