cleanup and fixed query

This commit is contained in:
Simon
2025-06-03 12:59:31 +00:00
parent 261c81e391
commit a7610e1bb3
5 changed files with 89 additions and 87 deletions

View File

@@ -38,68 +38,68 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
status: "active".to_string(), status: "active".to_string(),
categories: vec![], categories: vec![],
options: vec![ options: vec![
Channel_Option { ChannelOption {
id: "channels".to_string(), id: "channels".to_string(),
title: "Sites".to_string(), title: "Sites".to_string(),
description: "Websites included in search results.".to_string(), description: "Websites included in search results.".to_string(),
systemImage: "network".to_string(), systemImage: "network".to_string(),
colorName: "purple".to_string(), colorName: "purple".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "perverzija".to_string(), id: "perverzija".to_string(),
title: "Perverzija".to_string(), title: "Perverzija".to_string(),
}, },
], ],
multiSelect: true, multiSelect: true,
}, },
Channel_Option { ChannelOption {
id: "sort".to_string(), id: "sort".to_string(),
title: "Sort".to_string(), title: "Sort".to_string(),
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
systemImage: "list.number".to_string(), systemImage: "list.number".to_string(),
colorName: "blue".to_string(), colorName: "blue".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "date".to_string(), id: "date".to_string(),
title: "Date".to_string(), title: "Date".to_string(),
}, },
Filter_Option { FilterOption {
id: "name".to_string(), id: "name".to_string(),
title: "Name".to_string(), title: "Name".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
Channel_Option { ChannelOption {
id: "duration".to_string(), id: "duration".to_string(),
title: "Duration".to_string(), title: "Duration".to_string(),
description: "Filter the videos by duration.".to_string(), description: "Filter the videos by duration.".to_string(),
systemImage: "timer".to_string(), systemImage: "timer".to_string(),
colorName: "green".to_string(), colorName: "green".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "short".to_string(), id: "short".to_string(),
title: "< 1h".to_string(), title: "< 1h".to_string(),
}, },
Filter_Option { FilterOption {
id: "long".to_string(), id: "long".to_string(),
title: "> 1h".to_string(), title: "> 1h".to_string(),
}, },
], ],
multiSelect: true, multiSelect: true,
}, },
Channel_Option { ChannelOption {
id: "featured".to_string(), id: "featured".to_string(),
title: "Featured".to_string(), title: "Featured".to_string(),
description: "Filter Featured Videos.".to_string(), description: "Filter Featured Videos.".to_string(),
systemImage: "star".to_string(), systemImage: "star".to_string(),
colorName: "red".to_string(), colorName: "red".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "all".to_string(), id: "all".to_string(),
title: "No".to_string(), title: "No".to_string(),
}, },
Filter_Option { FilterOption {
id: "featured".to_string(), id: "featured".to_string(),
title: "Yes".to_string(), title: "Yes".to_string(),
}, },
@@ -118,36 +118,36 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
status: "active".to_string(), status: "active".to_string(),
categories: vec![], categories: vec![],
options: vec![ options: vec![
Channel_Option { ChannelOption {
id: "sort".to_string(), id: "sort".to_string(),
title: "Sort".to_string(), title: "Sort".to_string(),
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
systemImage: "list.number".to_string(), systemImage: "list.number".to_string(),
colorName: "blue".to_string(), colorName: "blue".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "date".to_string(), id: "date".to_string(),
title: "Date".to_string(), title: "Date".to_string(),
}, },
Filter_Option { FilterOption {
id: "name".to_string(), id: "name".to_string(),
title: "Name".to_string(), title: "Name".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
Channel_Option { ChannelOption {
id: "duration".to_string(), id: "duration".to_string(),
title: "Duration".to_string(), title: "Duration".to_string(),
description: "Filter the videos by duration.".to_string(), description: "Filter the videos by duration.".to_string(),
systemImage: "timer".to_string(), systemImage: "timer".to_string(),
colorName: "green".to_string(), colorName: "green".to_string(),
options: vec![ options: vec![
Filter_Option { FilterOption {
id: "short".to_string(), id: "short".to_string(),
title: "< 1h".to_string(), title: "< 1h".to_string(),
}, },
Filter_Option { FilterOption {
id: "long".to_string(), id: "long".to_string(),
title: "> 1h".to_string(), title: "> 1h".to_string(),
}, },

View File

@@ -1,3 +1,4 @@
#![allow(non_snake_case)]
use ntex_files as fs; use ntex_files as fs;
use ntex::web; use ntex::web;
@@ -7,6 +8,7 @@ mod videos;
mod providers; mod providers;
mod util; mod util;
#[ntex::main] #[ntex::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "ntex=info"); std::env::set_var("RUST_LOG", "ntex=info");

View File

@@ -2,8 +2,7 @@ use std::vec;
use std::env; use std::env;
use error_chain::error_chain; use error_chain::error_chain;
use htmlentity::entity::{decode, ICodedDataTrait}; use htmlentity::entity::{decode, ICodedDataTrait};
use reqwest::{header, Proxy}; use reqwest::{Proxy};
use serde_json::json;
use crate::providers::Provider; use crate::providers::Provider;
use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr};
@@ -47,13 +46,12 @@ impl PerverzijaProvider {
let client = match env::var("BURP_URL").as_deref() { let client = match env::var("BURP_URL").as_deref() {
Ok(burp_url) => { Ok(burp_url) =>
println!("Using Burp Proxy: {}", burp_url);
reqwest::Client::builder() 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") .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()) .proxy(Proxy::https(burp_url).unwrap())
.danger_accept_invalid_certs(true) .danger_accept_invalid_certs(true)
.build()?}, .build()?,
Err(_) => reqwest::Client::builder() 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") .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) .danger_accept_invalid_certs(true)
@@ -87,30 +85,8 @@ impl PerverzijaProvider {
return Err("Failed to solve FlareSolverr".into()); 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<Video_Item> = self.get_video_items_from_html(html.solution.response.clone());
Ok(video_items) Ok(video_items)
} }
Err(e) => {
println!("Error solving FlareSolverr: {}", e);
return Err("Failed to solve FlareSolverr".into());
}
}
}
} }
async fn query(&self, page: &u8, query: &str) -> Result<Vec<Video_Item>> { async fn query(&self, page: &u8, query: &str) -> Result<Vec<Video_Item>> {
println!("query: {}", query); println!("query: {}", query);
@@ -123,24 +99,48 @@ impl PerverzijaProvider {
url = format!("{}advanced-search/?_sf_s={}", self.url, search_string); url = format!("{}advanced-search/?_sf_s={}", self.url, search_string);
} }
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 = client.get(url.clone()).send().await?;
// print!("Response: {:?}\n", response);
if response.status().is_success() {
let text = response.text().await?;
let video_items: Vec<Video_Item> = 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_url = env::var("FLARE_URL").expect("FLARE_URL not set");
let flare = Flaresolverr::new(flare_url); let flare = Flaresolverr::new(flare_url);
let result = flare
let req = FlareSolverrRequest { .solve(FlareSolverrRequest {
cmd: "request.get".to_string(), cmd: "request.get".to_string(),
url: url.clone(), url: url.clone(),
maxTimeout: 60000, maxTimeout: 60000,
}; })
let response = flare.solve(req).await; .await;
match response { println!("FlareSolverr result: {:?}", result);
Ok(html) => { let video_items = match result {
let video_items = self.get_video_items_from_html_query(html.solution.response.clone()); Ok(res) => {
Ok(video_items) // println!("FlareSolverr response: {}", res);
self.get_video_items_from_html_query(res.solution.response)
} }
Err(e) => { Err(e) => {
println!("Error solving FlareSolverr: {}", e); println!("Error solving FlareSolverr: {}", e);
return Err("Failed to solve FlareSolverr".into()); return Err("Failed to solve FlareSolverr".into());
} }
};
Ok(video_items)
} }
} }
@@ -199,7 +199,7 @@ impl PerverzijaProvider {
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(), .to_string(),
}; };
let mut embed_html = vid[1].split("data-embed='").collect::<Vec<&str>>()[1] let embed_html = vid[1].split("data-embed='").collect::<Vec<&str>>()[1]
.split("'") .split("'")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
@@ -287,7 +287,7 @@ impl PerverzijaProvider {
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(), .to_string(),
}; };
let mut embed_html = vid[4].split("data-embed='").collect::<Vec<&str>>()[1] let embed_html = vid[4].split("data-embed='").collect::<Vec<&str>>()[1]
.split("'") .split("'")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string(); .to_string();
@@ -330,6 +330,7 @@ impl Provider for PerverzijaProvider {
per_page: String, per_page: String,
featured: String, featured: String,
) -> Vec<Video_Item> { ) -> Vec<Video_Item> {
let _ = per_page;
let _ = sort; let _ = sort;
let videos: std::result::Result<Vec<Video_Item>, Error> = match query { let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
Some(q) => self.query(&page.parse::<u8>().unwrap_or(1), &q).await, Some(q) => self.query(&page.parse::<u8>().unwrap_or(1), &q).await,

View File

@@ -16,23 +16,23 @@ pub struct Channel {
pub favicon: String, //"https:\/\/www.google.com/s2/favicons?sz=64&domain=https:\/\/hottubapp.io", pub favicon: String, //"https:\/\/www.google.com/s2/favicons?sz=64&domain=https:\/\/hottubapp.io",
pub status: String, //"active", pub status: String, //"active",
pub categories: Vec<String>, //[], pub categories: Vec<String>, //[],
pub options: Vec<Channel_Option>, pub options: Vec<ChannelOption>,
pub nsfw: bool, //true pub nsfw: bool, //true
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
pub struct Channel_Option { pub struct ChannelOption {
pub id: String, //"channels", pub id: String, //"channels",
pub title: String, //"Sites", pub title: String, //"Sites",
pub description: String, //"Websites included in search results.", pub description: String, //"Websites included in search results.",
pub systemImage: String, //"network", pub systemImage: String, //"network",
pub colorName: String, //"purple", pub colorName: String, //"purple",
pub options: Vec<Filter_Option>, //[], pub options: Vec<FilterOption>, //[],
pub multiSelect: bool, //true pub multiSelect: bool, //true
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
pub struct Filter_Option{ pub struct FilterOption{
pub id: String, //"sort", pub id: String, //"sort",
pub title: String, //"Sort", pub title: String, //"Sort",
} }

View File

@@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use reqwest::{header, Client, Proxy}; use reqwest::{Client, Proxy};
use serde_json::json; use serde_json::json;
#[derive(serde::Serialize, serde::Deserialize, Debug)] #[derive(serde::Serialize, serde::Deserialize, Debug)]
@@ -38,23 +38,22 @@ pub struct FlareSolverrSolution {
cookies: Vec<FlaresolverrCookie>, cookies: Vec<FlaresolverrCookie>,
userAgent: String, userAgent: String,
} }
impl FlareSolverrSolution { // impl FlareSolverrSolution {
fn to_client(&self,){ // fn to_client(&self,){
let mut headers = header::HeaderMap::new(); // let mut headers = header::HeaderMap::new();
for (h, v) in &self.headers { // for (h, v) in &self.headers {
println!("{}: {}", h, v); // println!("{}: {}", h, v);
headers.insert( // headers.insert(
header::HeaderName::from_bytes(h.as_bytes()).unwrap(), // header::HeaderName::from_bytes(h.as_bytes()).unwrap(),
header::HeaderValue::from_str(v).unwrap(), // header::HeaderValue::from_str(v).unwrap(),
); // );
} // }
// // let client = reqwest::Client::builder()
// let client = reqwest::Client::builder() // // .danger_accept_invalid_certs(true)
// .danger_accept_invalid_certs(true) // // .
// . // // .build().unwrap();
// .build().unwrap(); // }
} // }
}
#[derive(serde::Serialize, serde::Deserialize, Debug)] #[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct FlareSolverrResponse { pub struct FlareSolverrResponse {
status: String, status: String,
@@ -85,7 +84,7 @@ impl Flaresolverr {
.build()?; .build()?;
let response = client let response = client
.post("http://192.168.0.103:8191/v1") .post(&self.url)
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.json(&json!({ .json(&json!({
"cmd": request.cmd, "cmd": request.cmd,