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