bugfix pornhub

This commit is contained in:
Simon
2025-08-01 18:48:42 +00:00
parent d1a4975aa3
commit 32eb704548

View File

@@ -1,3 +1,4 @@
use crate::schema::videos::url;
use crate::util::parse_abbreviated_number;
use crate::DbPool;
use crate::providers::Provider;
@@ -36,11 +37,11 @@ impl PornhubProvider {
page: u8,
sort: &str,
) -> Result<Vec<VideoItem>> {
let url = format!("{}/video?o={}&page={}", self.url, sort, page);
let old_items = match cache.get(&url) {
let video_url = format!("{}/video?o={}&page={}", self.url, sort, page);
let old_items = match cache.get(&video_url) {
Some((time, items)) => {
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
println!("Cache hit for URL: {}", url);
println!("Cache hit for URL: {}", video_url);
return Ok(items.clone());
} else {
items.clone()
@@ -54,7 +55,7 @@ impl PornhubProvider {
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
let mut response = client.get(url.clone())
let mut response = client.get(video_url.clone())
// .proxy(proxy.clone())
.send().await?;
if response.status().is_redirection(){
@@ -67,8 +68,8 @@ impl PornhubProvider {
let text = response.text().await?;
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone(),"<ul id=\"video");
if !video_items.is_empty() {
cache.remove(&url);
cache.insert(url.clone(), video_items.clone());
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
} else {
return Ok(old_items);
}
@@ -79,7 +80,7 @@ impl PornhubProvider {
let result = flare
.solve(FlareSolverrRequest {
cmd: "request.get".to_string(),
url: url.clone(),
url: video_url.clone(),
maxTimeout: 60000,
})
.await;
@@ -94,8 +95,8 @@ impl PornhubProvider {
}
};
if !video_items.is_empty() {
cache.remove(&url);
cache.insert(url.clone(), video_items.clone());
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
} else {
return Ok(old_items);
}
@@ -111,11 +112,11 @@ impl PornhubProvider {
) -> Result<Vec<VideoItem>> {
let mut split_string = "<ul id=\"video";
let search_string = query.to_lowercase().trim().replace(" ", "+");
let mut url = format!("{}/video/search?search={}&page={}", self.url, search_string, page);
let mut video_url = format!("{}/video/search?search={}&page={}", self.url, search_string, page);
if query.starts_with("@"){
let url_parts = query[1..].split(":").collect::<Vec<&str>>();
url = [self.url.to_string(), url_parts[0].to_string(), url_parts[1].replace(" ", "-").to_string(), "videos?page=".to_string()].join("/");
url += &page.to_string();
video_url = [self.url.to_string(), url_parts[0].to_string(), url_parts[1].replace(" ", "-").to_string(), "videos?page=".to_string()].join("/");
video_url += &page.to_string();
if query.contains("@model") || query.contains("@pornstar"){
split_string = "mostRecentVideosSection";
}
@@ -125,18 +126,18 @@ impl PornhubProvider {
}
if query.contains("@channels"){
url += match sort {
video_url += match sort {
"mr" => "",
"mv" => "&o=vi",
"tr" => "&o=ra",
_ => "",
}
} else{
url += format!("&o={}", sort).as_str();
video_url += format!("&o={}", sort).as_str();
}
// Check our Video Cache. If the result is younger than 1 hour, we return it.
let old_items = match cache.get(&url) {
let old_items = match cache.get(&video_url) {
Some((time, items)) => {
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
return Ok(items.clone());
@@ -153,7 +154,7 @@ impl PornhubProvider {
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
let mut response = client.get(url.clone())
let mut response = client.get(video_url.clone())
.proxy(proxy.clone())
.send().await?;
@@ -168,8 +169,8 @@ impl PornhubProvider {
let text = response.text().await?;
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone(),split_string);
if !video_items.is_empty() {
cache.remove(&url);
cache.insert(url.clone(), video_items.clone());
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
} else {
return Ok(old_items);
}
@@ -180,7 +181,7 @@ impl PornhubProvider {
let result = flare
.solve(FlareSolverrRequest {
cmd: "request.get".to_string(),
url: url.clone(),
url: video_url.clone(),
maxTimeout: 60000,
})
.await;
@@ -192,8 +193,8 @@ impl PornhubProvider {
}
};
if !video_items.is_empty() {
cache.remove(&url);
cache.insert(url.clone(), video_items.clone());
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
} else {
return Ok(old_items);
}
@@ -220,14 +221,23 @@ impl PornhubProvider {
if video_segment.contains("wrapVideoBlock"){
continue; // Skip if the segment is a wrapVideoBlock
}
let url_part = video_segment.split("<a href=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0];
if url_part.is_empty() || url_part == "javascript:void(0)" {
continue;
let mut video_url: String = String::new();
if !video_segment.contains("<a href=\"") {
let url_part = video_segment.split("data-video-vkey=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0];
video_url = format!("{}{}", self.url, url_part);
}
let url = format!("{}{}", self.url, url_part);
if url == "https://www.pornhub.comjavascript:void(0)".to_string() {
else{
let url_part = video_segment.split("<a href=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0];
if url_part.is_empty() || url_part == "javascript:void(0)" {
continue;
}
video_url = format!("{}{}", self.url, url_part);
}
if video_url == "https://www.pornhub.comjavascript:void(0)".to_string() {
continue;
}
let mut title = video_segment.split("\" title=\"").collect::<Vec<&str>>()[1]
@@ -281,7 +291,7 @@ impl PornhubProvider {
let mut video_item = VideoItem::new(
id,
title,
url.to_string(),
video_url.to_string(),
"pornhub".to_string(),
thumb,
duration,