46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { PORNHUB_BASE_URL } from "@/constants/urls"
|
|
import axios, { AxiosHeaders } from "axios"
|
|
import { getHeadersWithCookie } from "../common/headers"
|
|
import { VideoSourceItem } from "@/meta/data"
|
|
|
|
interface PornHubVideoSrcElem {
|
|
videoUrl: string
|
|
quality: string
|
|
}
|
|
|
|
export const getPornHubQueryUrl = async (query?: string): Promise<string> => {
|
|
if (query) {
|
|
return `${PORNHUB_BASE_URL}/video/search?search=${query}`
|
|
}
|
|
|
|
return PORNHUB_BASE_URL
|
|
}
|
|
|
|
export const getPornHubMediaUrlList = async (url: string, sessionCookie: string): Promise<VideoSourceItem[]> => {
|
|
|
|
const headersWithCookie = getHeadersWithCookie(PORNHUB_BASE_URL, sessionCookie)
|
|
|
|
let videos: VideoSourceItem[] = []
|
|
|
|
await axios.get(url, headersWithCookie)
|
|
.then(async response => {
|
|
|
|
if (response.data) {
|
|
|
|
videos = await response.data.map((elem: PornHubVideoSrcElem) => ({
|
|
src: elem?.videoUrl,
|
|
type: 'video/mp4',
|
|
size: elem?.quality
|
|
})) as VideoSourceItem[]
|
|
|
|
return videos
|
|
|
|
} else {
|
|
return []
|
|
}
|
|
|
|
})
|
|
.catch(error => console.log(error))
|
|
|
|
return videos
|
|
} |