proxyraye-nextjs/src/utils/scrape/redtube/url.ts

71 lines
2.1 KiB
TypeScript

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"
import { getHeadersWithCookie } from "../common/headers"
import { MindGeekVideoSrcElem, VideoSourceItem } from "@/meta/data"
import axios from "axios"
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"
}
export const getRedTubeMediaUrlList = async (url: string, sessionCookie: string): Promise<VideoSourceItem[]> => {
const headersWithCookie = getHeadersWithCookie(REDTUBE_BASE_URL, sessionCookie)
let videos: VideoSourceItem[] = []
await axios.get(url, headersWithCookie)
.then(async response => {
if (response.data) {
videos = await response.data.map((elem: MindGeekVideoSrcElem) => ({
src: elem?.videoUrl,
type: 'video/mp4',
size: elem?.quality
})) as VideoSourceItem[]
return videos
} else {
return []
}
})
.catch(error => console.log(error))
return videos
}