Release v0.4.0 #110
|
@ -2,13 +2,14 @@ import { YOUPORN_BASE_URL, YOUPORN_BASE_URL_VIDEO } from "@/constants/urls";
|
|||
import { FetchParams, GalleryData, VideoData, VideoSourceItem } from "@/meta/data";
|
||||
import { getHeaders } from "../common/headers";
|
||||
import { getDataFromRedis, storeDataIntoRedis } from "@/redis/client";
|
||||
import { DEFAULT_RELATED_VIDEO_KEY_PATH, DEFAULT_YOUPORN_VIDEO_EXPIRY } from "@/constants/redis";
|
||||
import { DEFAULT_RELATED_VIDEO_KEY_PATH, DEFAULT_YOUPORN_VIDEO_EXPIRY, DEFAULT_YOUPORN_GALLERY_EXPIRY } from "@/constants/redis";
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
|
||||
import axios, { AxiosError } from "axios";
|
||||
import { createSessionCookie, findGetMediaUrlInTagblock, findGetRelatedUrlInTagblock } from "../common/mindgeek";
|
||||
import { createSessionCookie, findGetMediaUrlInTagblock } from "../common/mindgeek";
|
||||
import { getYouPornMediaUrlList } from "./url";
|
||||
import { Platforms } from "@/meta/settings";
|
||||
|
||||
export const fetchYouPornVideoData = async (videoId: string, params?: FetchParams): Promise<[VideoData, GalleryData[]]> => {
|
||||
|
||||
|
@ -19,7 +20,7 @@ export const fetchYouPornVideoData = async (videoId: string, params?: FetchParam
|
|||
|
||||
let relatedData: GalleryData[] = [];
|
||||
|
||||
let mediaUrl, relatedUrl, sessionCookie, convertedData: VideoSourceItem[]
|
||||
let mediaUrl, sessionCookie, convertedData: VideoSourceItem[]
|
||||
|
||||
let reqHeaders = getHeaders(YOUPORN_BASE_URL)
|
||||
|
||||
|
@ -53,13 +54,22 @@ export const fetchYouPornVideoData = async (videoId: string, params?: FetchParam
|
|||
|
||||
})
|
||||
|
||||
scriptTags.map((idx, elem) => {
|
||||
const getRelatedUrl = findGetRelatedUrlInTagblock($(elem).toString()) ?? null
|
||||
|
||||
if (getRelatedUrl) {
|
||||
relatedUrl = getRelatedUrl
|
||||
}
|
||||
|
||||
const wrapperId = "#relatedVideos .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 && relatedData.push({
|
||||
videoUrl,
|
||||
imgUrl,
|
||||
text,
|
||||
platform: Platforms.youporn
|
||||
})
|
||||
})
|
||||
|
||||
}).catch((error: AxiosError) => {
|
||||
|
@ -73,5 +83,9 @@ export const fetchYouPornVideoData = async (videoId: string, params?: FetchParam
|
|||
await storeDataIntoRedis(queryUrl, data, DEFAULT_YOUPORN_VIDEO_EXPIRY);
|
||||
}
|
||||
|
||||
if (relatedData.length > 0) {
|
||||
await storeDataIntoRedis(queryUrl + DEFAULT_RELATED_VIDEO_KEY_PATH, relatedData, DEFAULT_YOUPORN_GALLERY_EXPIRY);
|
||||
}
|
||||
|
||||
return [ data, relatedData ]
|
||||
}
|
Loading…
Reference in New Issue