Release v0.4.1 #118
|
@ -15,4 +15,7 @@ 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_XHAMSTER_GALLERY_EXPIRY = { EX: EX_HOURLY };
|
||||
export const DEFAULT_XHAMSTER_VIDEO_EXPIRY = { EX: EX_MIN };
|
||||
|
||||
export const DEFAULT_RELATED_VIDEO_KEY_PATH = '/related/'
|
|
@ -37,4 +37,16 @@ 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='
|
||||
export const REDTUBE_BASE_GAY_SEARCH: string = 'https://www.redtube.com/gay?search='
|
||||
|
||||
// XHAMSTER
|
||||
export const XHAMSTER_BASE_URL = 'https://xhamster.com'
|
||||
export const XHAMSTER_BASE_URL_VIDEOS = 'https://xhamster.com/videos'
|
||||
|
||||
export const XHAMSTER_BASE_URL_ETERO = 'https://xhamster.com/newest'
|
||||
export const XHAMSTER_BASE_URL_GAY = 'https://xhamster.com/gay/newest'
|
||||
export const XHAMSTER_BASE_URL_TRANS = 'https://xhamster.com/shemale/newest'
|
||||
|
||||
export const XHAMSTER_BASE_SEARCH = 'https://xhamster.com/search/'
|
||||
export const XHAMSTER_BASE_SEARCH_GAY = 'https://xhamster.com/gay/search/'
|
||||
export const XHAMSTER_BASE_SEARCH_TRANS = 'https://xhamster.com/shemale/search/'
|
|
@ -1,8 +1,62 @@
|
|||
import { XHAMSTER_BASE_URL, XHAMSTER_BASE_URL_VIDEOS } from "@/constants/urls";
|
||||
import { FetchParams, GalleryData } from "@/meta/data";
|
||||
import { getHeaders } from "../common/headers";
|
||||
import { getXHamsterQueryUrl } from "./url";
|
||||
import { getDataFromRedis, storeDataIntoRedis } from "@/redis/client";
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
|
||||
import axios, { AxiosError } from "axios";
|
||||
import { DEFAULT_XHAMSTER_GALLERY_EXPIRY } from "@/constants/redis";
|
||||
import { Platforms } from "@/meta/settings";
|
||||
|
||||
export const fetchXHamsterGalleryData = async (params?: FetchParams): Promise<GalleryData[]> => {
|
||||
|
||||
let data: GalleryData[] = [];
|
||||
|
||||
const reqHeaders = getHeaders(XHAMSTER_BASE_URL)
|
||||
|
||||
const queryUrl = await getXHamsterQueryUrl(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 = '.thumb-list .thumb-list__item'
|
||||
|
||||
const thumbs = $(wrapperId);
|
||||
|
||||
thumbs.map((key, thumb) => {
|
||||
|
||||
const videoUrl = $(thumb).find("a.video-thumb__image-container").attr("href")?.replace(XHAMSTER_BASE_URL_VIDEOS, '')
|
||||
const imgUrl = $(thumb).find("a.video-thumb__image-container img").attr("src")
|
||||
const text = $(thumb).find("a.video-thumb-info__name").attr("title")
|
||||
|
||||
videoUrl && imgUrl && text && data.push({
|
||||
videoUrl,
|
||||
imgUrl,
|
||||
text,
|
||||
platform: Platforms.xhamster
|
||||
})
|
||||
})
|
||||
|
||||
if (data.length > 0) {
|
||||
await storeDataIntoRedis(queryUrl, data, DEFAULT_XHAMSTER_GALLERY_EXPIRY);
|
||||
}
|
||||
|
||||
}).catch((error: AxiosError) => {
|
||||
// handle errors
|
||||
});
|
||||
|
||||
return data
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { XHAMSTER_BASE_SEARCH, XHAMSTER_BASE_SEARCH_GAY, XHAMSTER_BASE_SEARCH_TRANS, XHAMSTER_BASE_URL_ETERO, XHAMSTER_BASE_URL_GAY, XHAMSTER_BASE_URL_TRANS } from "@/constants/urls"
|
||||
import { Cookies, XHamsterOrientations } from "@/meta/settings"
|
||||
import { getCookie } from "@/utils/cookies/read"
|
||||
|
||||
export const getXHamsterQueryUrl = async (query?: string): Promise<string> => {
|
||||
const orientation = await getCookie(Cookies.orientation)
|
||||
|
||||
if (query) {
|
||||
if (orientation && orientation.value == XHamsterOrientations.gay) {
|
||||
return XHAMSTER_BASE_SEARCH_GAY + query + '?revert=orientation'
|
||||
}
|
||||
|
||||
if (orientation && orientation.value == XHamsterOrientations.trans) {
|
||||
return XHAMSTER_BASE_SEARCH_TRANS + query + '?revert=orientation'
|
||||
}
|
||||
|
||||
return XHAMSTER_BASE_SEARCH + query
|
||||
|
||||
} else {
|
||||
if (orientation && orientation.value == XHamsterOrientations.gay) {
|
||||
return XHAMSTER_BASE_URL_GAY
|
||||
}
|
||||
|
||||
if (orientation && orientation.value == XHamsterOrientations.trans) {
|
||||
return XHAMSTER_BASE_URL_TRANS
|
||||
}
|
||||
}
|
||||
|
||||
return XHAMSTER_BASE_URL_ETERO
|
||||
}
|
Loading…
Reference in New Issue