diff --git a/src/api.rs b/src/api.rs index 6081348..14d489e 100644 --- a/src/api.rs +++ b/src/api.rs @@ -124,7 +124,33 @@ async fn status(req: HttpRequest) -> Result { favicon: "https://www.google.com/s2/favicons?sz=64&domain=pornhub.com".to_string(), status: "active".to_string(), categories: vec![], - options: vec![], + options: vec![ + ChannelOption { + id: "sort".to_string(), + title: "Sort".to_string(), + description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), + systemImage: "list.number".to_string(), + colorName: "blue".to_string(), + options: vec![ + FilterOption { + id: "mr".to_string(), + title: "Most Recent".to_string(), + }, + FilterOption { + id: "mv".to_string(), + title: "Most Viewed".to_string(), + }, + FilterOption { + id: "tr".to_string(), + title: "Top Rated".to_string(), + }, + FilterOption { + id: "lg".to_string(), + title: "Longest".to_string(), + }, + ], + multiSelect: false, + },], nsfw: true, }); // pmvhaven diff --git a/src/providers/pornhub.rs b/src/providers/pornhub.rs index a21974b..bdd713e 100644 --- a/src/providers/pornhub.rs +++ b/src/providers/pornhub.rs @@ -34,12 +34,10 @@ impl PornhubProvider { &self, cache: VideoCache, page: u8, + sort: &str, ) -> Result> { 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> { let mut split_string = "
    >(); 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 { let _ = category; let _ = per_page; - let _ = sort; let _ = featured; // Ignored in this implementation let _ = pool; // Ignored in this implementation let videos: std::result::Result, Error> = match query { Some(q) => { - self.query(cache, page.parse::().unwrap_or(1), &q) + self.query(cache, page.parse::().unwrap_or(1), &q, &sort) .await } None => { - self.get(cache, page.parse::().unwrap_or(1)) + self.get(cache, page.parse::().unwrap_or(1), &sort) .await } };