pornhub update

This commit is contained in:
Simon
2025-07-19 15:02:07 +00:00
parent 519f178dea
commit 9102a9f43f
2 changed files with 34 additions and 13 deletions

View File

@@ -34,12 +34,10 @@ impl PornhubProvider {
&self,
cache: VideoCache,
page: u8,
sort: &str,
) -> Result<Vec<VideoItem>> {
let mut url = format!("{}/video?page={}", self.url, page);
if page == 1 {
url = format!("{}/video", self.url);
}
url += format!("&o={}", sort).as_str();
let old_items = match cache.get(&url) {
Some((time, items)) => {
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
@@ -102,14 +100,11 @@ impl PornhubProvider {
cache: VideoCache,
page: u8,
query: &str,
sort: &str,
) -> 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);
if page == 1 {
url = format!("{}/video/search?search={}", self.url, search_string);
}
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("/");
@@ -120,9 +115,10 @@ impl PornhubProvider {
if query.contains("@channels"){
split_string = "dropdownHottestVideos";
}
println!("Query URL: {}", url);
}
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) {
Some((time, items)) => {
@@ -293,16 +289,15 @@ impl Provider for PornhubProvider {
) -> Vec<VideoItem> {
let _ = category;
let _ = per_page;
let _ = sort;
let _ = featured; // Ignored in this implementation
let _ = pool; // Ignored in this implementation
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
Some(q) => {
self.query(cache, page.parse::<u8>().unwrap_or(1), &q)
self.query(cache, page.parse::<u8>().unwrap_or(1), &q, &sort)
.await
}
None => {
self.get(cache, page.parse::<u8>().unwrap_or(1))
self.get(cache, page.parse::<u8>().unwrap_or(1), &sort)
.await
}
};