more bugfixes

This commit is contained in:
Simon
2025-07-16 18:48:00 +00:00
parent 7008e38838
commit 9e1a2a65c9

View File

@@ -8,7 +8,7 @@ use error_chain::error_chain;
use htmlentity::entity::{ICodedDataTrait, decode}; use htmlentity::entity::{ICodedDataTrait, decode};
use std::env; use std::env;
use std::vec; use std::vec;
use wreq::Client; use wreq::{Client, Proxy};
use wreq_util::Emulation; use wreq_util::Emulation;
error_chain! { error_chain! {
@@ -100,10 +100,10 @@ impl PornhubProvider {
page: u8, page: u8,
query: &str, query: &str,
) -> Result<Vec<VideoItem>> { ) -> Result<Vec<VideoItem>> {
let search_string = query.replace(" ", "+"); let search_string = query.to_lowercase().trim().replace(" ", "+");
let mut url = format!("{}/video?search={}&page={}", self.url, search_string, page); let mut url = format!("{}/video/search?search={}&page={}", self.url, search_string, page);
if page == 1 { if page == 1 {
url = format!("{}/video?search={}", self.url, search_string); url = format!("{}/video/search?search={}", self.url, search_string);
} }
// 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.
@@ -120,9 +120,11 @@ impl PornhubProvider {
vec![] vec![]
} }
}; };
let client = Client::builder().emulation(Emulation::Firefox136).build()?;
let response = client.get(url.clone()).send().await?; let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
let response = client.get(url.clone()).proxy(proxy).send().await?;
if response.status().is_success() { if response.status().is_success() {
let text = response.text().await?; let text = response.text().await?;
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone()); let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
@@ -166,36 +168,40 @@ impl PornhubProvider {
return vec![]; return vec![];
} }
let mut items: Vec<VideoItem> = Vec::new(); let mut items: Vec<VideoItem> = Vec::new();
let video_listing_content = html.split("<ul id=\"videoCategory\"").collect::<Vec<&str>>()[1]; println!("{}", html.contains("<ul id=\"video"));
let video_listing_content = html.split("<ul id=\"video").collect::<Vec<&str>>()[1];
let raw_videos = video_listing_content let raw_videos = video_listing_content
.split("class=\"pcVideoListItem ") .split("class=\"pcVideoListItem ")
.collect::<Vec<&str>>()[1..] .collect::<Vec<&str>>()[1..]
.to_vec(); .to_vec();
for video_segment in &raw_videos { for video_segment in &raw_videos {
let vid = video_segment.split("\n").collect::<Vec<&str>>(); // let vid = video_segment.split("\n").collect::<Vec<&str>>();
// for (index, line) in vid.iter().enumerate() { // for (index, line) in vid.iter().enumerate() {
// println!("Line {}: {}", index, line); // println!("Line {}: {}", index, line);
// } // }
let mut title = vid[16].split("title=\"").collect::<Vec<&str>>()[1] let url = format!("{}{}", self.url, video_segment.split("<a href=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0]);
if url == "https://www.pornhub.comjavascript:void(0)".to_string() {
continue;
}
let mut title = video_segment.split("\" title=\"").collect::<Vec<&str>>()[1]
.split("") .split("")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
// html decode // html decode
title = decode(title.as_bytes()).to_string().unwrap_or(title); title = decode(title.as_bytes()).to_string().unwrap_or(title);
let url = format!("{}{}", self.url, vid[16].split("href=\"").collect::<Vec<&str>>()[1] let id = video_segment.split("data-video-id=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0]);
let id = vid[2].split("data-video-id=\"").collect::<Vec<&str>>()[1]
.split("\"") .split("\"")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
let raw_duration = vid[29].split("<var class=\"duration\">").collect::<Vec<&str>>()[1] let raw_duration = video_segment.split("duration").collect::<Vec<&str>>()[1].split(">").collect::<Vec<&str>>()[1]
.split("<") .split("<")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32; let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
let thumb = vid[20].split("src=\"").collect::<Vec<&str>>()[1] let thumb = video_segment.split("src=\"").collect::<Vec<&str>>()[1]
.split("\"") .split("\"")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();