From a7610e1bb3fd3002cfb62f65b657df50df87cda3 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 3 Jun 2025 12:59:31 +0000 Subject: [PATCH] cleanup and fixed query --- src/api.rs | 34 ++++++------- src/main.rs | 2 + src/providers/perverzija.rs | 95 +++++++++++++++++++------------------ src/status.rs | 8 ++-- src/util/flaresolverr.rs | 37 +++++++-------- 5 files changed, 89 insertions(+), 87 deletions(-) diff --git a/src/api.rs b/src/api.rs index 4cc7b46..96dc516 100644 --- a/src/api.rs +++ b/src/api.rs @@ -38,68 +38,68 @@ async fn status(req: HttpRequest) -> Result { status: "active".to_string(), categories: vec![], options: vec![ - Channel_Option { + ChannelOption { id: "channels".to_string(), title: "Sites".to_string(), description: "Websites included in search results.".to_string(), systemImage: "network".to_string(), colorName: "purple".to_string(), options: vec![ - Filter_Option { + FilterOption { id: "perverzija".to_string(), title: "Perverzija".to_string(), }, ], multiSelect: true, }, - Channel_Option { + 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![ - Filter_Option { + FilterOption { id: "date".to_string(), title: "Date".to_string(), }, - Filter_Option { + FilterOption { id: "name".to_string(), title: "Name".to_string(), }, ], multiSelect: false, }, - Channel_Option { + ChannelOption { id: "duration".to_string(), title: "Duration".to_string(), description: "Filter the videos by duration.".to_string(), systemImage: "timer".to_string(), colorName: "green".to_string(), options: vec![ - Filter_Option { + FilterOption { id: "short".to_string(), title: "< 1h".to_string(), }, - Filter_Option { + FilterOption { id: "long".to_string(), title: "> 1h".to_string(), }, ], multiSelect: true, }, - Channel_Option { + ChannelOption { id: "featured".to_string(), title: "Featured".to_string(), description: "Filter Featured Videos.".to_string(), systemImage: "star".to_string(), colorName: "red".to_string(), options: vec![ - Filter_Option { + FilterOption { id: "all".to_string(), title: "No".to_string(), }, - Filter_Option { + FilterOption { id: "featured".to_string(), title: "Yes".to_string(), }, @@ -118,36 +118,36 @@ async fn status(req: HttpRequest) -> Result { status: "active".to_string(), categories: vec![], options: vec![ - Channel_Option { + 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![ - Filter_Option { + FilterOption { id: "date".to_string(), title: "Date".to_string(), }, - Filter_Option { + FilterOption { id: "name".to_string(), title: "Name".to_string(), }, ], multiSelect: false, }, - Channel_Option { + ChannelOption { id: "duration".to_string(), title: "Duration".to_string(), description: "Filter the videos by duration.".to_string(), systemImage: "timer".to_string(), colorName: "green".to_string(), options: vec![ - Filter_Option { + FilterOption { id: "short".to_string(), title: "< 1h".to_string(), }, - Filter_Option { + FilterOption { id: "long".to_string(), title: "> 1h".to_string(), }, diff --git a/src/main.rs b/src/main.rs index 51e1a19..e138090 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(non_snake_case)] use ntex_files as fs; use ntex::web; @@ -7,6 +8,7 @@ mod videos; mod providers; mod util; + #[ntex::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "ntex=info"); diff --git a/src/providers/perverzija.rs b/src/providers/perverzija.rs index f0cc8ad..53a22cc 100644 --- a/src/providers/perverzija.rs +++ b/src/providers/perverzija.rs @@ -2,8 +2,7 @@ use std::vec; use std::env; use error_chain::error_chain; use htmlentity::entity::{decode, ICodedDataTrait}; -use reqwest::{header, Proxy}; -use serde_json::json; +use reqwest::{Proxy}; use crate::providers::Provider; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; @@ -47,13 +46,12 @@ impl PerverzijaProvider { let client = match env::var("BURP_URL").as_deref() { - Ok(burp_url) => { - println!("Using Burp Proxy: {}", burp_url); + Ok(burp_url) => reqwest::Client::builder() .user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15") .proxy(Proxy::https(burp_url).unwrap()) .danger_accept_invalid_certs(true) - .build()?}, + .build()?, Err(_) => reqwest::Client::builder() .user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15") .danger_accept_invalid_certs(true) @@ -87,29 +85,7 @@ impl PerverzijaProvider { return Err("Failed to solve FlareSolverr".into()); } }; - - - //########## - let flare_url = env::var("FLARE_URL").expect("FLARE_URL not set"); - let flare = Flaresolverr::new(flare_url); - - let req = FlareSolverrRequest { - cmd: "request.get".to_string(), - url: url.clone(), - maxTimeout: 60000, - }; - let response = flare.solve(req).await; - // println!("Response: {:?}", response); - match response { - Ok(html) => { - let video_items: Vec = self.get_video_items_from_html(html.solution.response.clone()); - Ok(video_items) - } - Err(e) => { - println!("Error solving FlareSolverr: {}", e); - return Err("Failed to solve FlareSolverr".into()); - } - } + Ok(video_items) } } async fn query(&self, page: &u8, query: &str) -> Result> { @@ -123,24 +99,48 @@ impl PerverzijaProvider { url = format!("{}advanced-search/?_sf_s={}", self.url, search_string); } - let flare_url = env::var("FLARE_URL").expect("FLARE_URL not set"); - let flare = Flaresolverr::new(flare_url); - - let req = FlareSolverrRequest { - cmd: "request.get".to_string(), - url: url.clone(), - maxTimeout: 60000, + + let client = match env::var("BURP_URL").as_deref() { + Ok(burp_url) => + reqwest::Client::builder() + .user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15") + .proxy(Proxy::https(burp_url).unwrap()) + .danger_accept_invalid_certs(true) + .build()?, + Err(_) => reqwest::Client::builder() + .user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15") + .danger_accept_invalid_certs(true) + .build()?, }; - let response = flare.solve(req).await; - match response { - Ok(html) => { - let video_items = self.get_video_items_from_html_query(html.solution.response.clone()); - Ok(video_items) - } - Err(e) => { - println!("Error solving FlareSolverr: {}", e); - return Err("Failed to solve FlareSolverr".into()); - } + + let response = client.get(url.clone()).send().await?; + // print!("Response: {:?}\n", response); + if response.status().is_success() { + let text = response.text().await?; + let video_items: Vec = self.get_video_items_from_html(text.clone()); + Ok(video_items) + } else { + let flare_url = env::var("FLARE_URL").expect("FLARE_URL not set"); + let flare = Flaresolverr::new(flare_url); + let result = flare + .solve(FlareSolverrRequest { + cmd: "request.get".to_string(), + url: url.clone(), + maxTimeout: 60000, + }) + .await; + println!("FlareSolverr result: {:?}", result); + let video_items = match result { + Ok(res) => { + // println!("FlareSolverr response: {}", res); + self.get_video_items_from_html_query(res.solution.response) + } + Err(e) => { + println!("Error solving FlareSolverr: {}", e); + return Err("Failed to solve FlareSolverr".into()); + } + }; + Ok(video_items) } } @@ -199,7 +199,7 @@ impl PerverzijaProvider { .collect::>()[0] .to_string(), }; - let mut embed_html = vid[1].split("data-embed='").collect::>()[1] + let embed_html = vid[1].split("data-embed='").collect::>()[1] .split("'") .collect::>()[0] .to_string(); @@ -287,7 +287,7 @@ impl PerverzijaProvider { .collect::>()[0] .to_string(), }; - let mut embed_html = vid[4].split("data-embed='").collect::>()[1] + let embed_html = vid[4].split("data-embed='").collect::>()[1] .split("'") .collect::>()[0] .to_string(); @@ -330,6 +330,7 @@ impl Provider for PerverzijaProvider { per_page: String, featured: String, ) -> Vec { + let _ = per_page; let _ = sort; let videos: std::result::Result, Error> = match query { Some(q) => self.query(&page.parse::().unwrap_or(1), &q).await, diff --git a/src/status.rs b/src/status.rs index b67983a..e3cc71c 100644 --- a/src/status.rs +++ b/src/status.rs @@ -16,23 +16,23 @@ pub struct Channel { pub favicon: String, //"https:\/\/www.google.com/s2/favicons?sz=64&domain=https:\/\/hottubapp.io", pub status: String, //"active", pub categories: Vec, //[], - pub options: Vec, + pub options: Vec, pub nsfw: bool, //true } #[derive(serde::Serialize)] -pub struct Channel_Option { +pub struct ChannelOption { pub id: String, //"channels", pub title: String, //"Sites", pub description: String, //"Websites included in search results.", pub systemImage: String, //"network", pub colorName: String, //"purple", - pub options: Vec, //[], + pub options: Vec, //[], pub multiSelect: bool, //true } #[derive(serde::Serialize)] -pub struct Filter_Option{ +pub struct FilterOption{ pub id: String, //"sort", pub title: String, //"Sort", } diff --git a/src/util/flaresolverr.rs b/src/util/flaresolverr.rs index ed11cee..7169f40 100644 --- a/src/util/flaresolverr.rs +++ b/src/util/flaresolverr.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use reqwest::{header, Client, Proxy}; +use reqwest::{Client, Proxy}; use serde_json::json; #[derive(serde::Serialize, serde::Deserialize, Debug)] @@ -38,23 +38,22 @@ pub struct FlareSolverrSolution { cookies: Vec, userAgent: String, } -impl FlareSolverrSolution { - fn to_client(&self,){ - let mut headers = header::HeaderMap::new(); - for (h, v) in &self.headers { - println!("{}: {}", h, v); - headers.insert( - header::HeaderName::from_bytes(h.as_bytes()).unwrap(), - header::HeaderValue::from_str(v).unwrap(), - ); - } - - // let client = reqwest::Client::builder() - // .danger_accept_invalid_certs(true) - // . - // .build().unwrap(); - } -} +// impl FlareSolverrSolution { +// fn to_client(&self,){ +// let mut headers = header::HeaderMap::new(); +// for (h, v) in &self.headers { +// println!("{}: {}", h, v); +// headers.insert( +// header::HeaderName::from_bytes(h.as_bytes()).unwrap(), +// header::HeaderValue::from_str(v).unwrap(), +// ); +// } +// // let client = reqwest::Client::builder() +// // .danger_accept_invalid_certs(true) +// // . +// // .build().unwrap(); +// } +// } #[derive(serde::Serialize, serde::Deserialize, Debug)] pub struct FlareSolverrResponse { status: String, @@ -85,7 +84,7 @@ impl Flaresolverr { .build()?; let response = client - .post("http://192.168.0.103:8191/v1") + .post(&self.url) .header("Content-Type", "application/json") .json(&json!({ "cmd": request.cmd,