cleanup and fixed query
This commit is contained in:
34
src/api.rs
34
src/api.rs
@@ -38,68 +38,68 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
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<impl web::Responder, web::Error> {
|
||||
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(),
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<Video_Item> = 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<Vec<Video_Item>> {
|
||||
@@ -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<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 = 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::<Vec<&str>>()[0]
|
||||
.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("'")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
@@ -287,7 +287,7 @@ impl PerverzijaProvider {
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.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("'")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
@@ -330,6 +330,7 @@ impl Provider for PerverzijaProvider {
|
||||
per_page: String,
|
||||
featured: String,
|
||||
) -> Vec<Video_Item> {
|
||||
let _ = per_page;
|
||||
let _ = sort;
|
||||
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
||||
Some(q) => self.query(&page.parse::<u8>().unwrap_or(1), &q).await,
|
||||
|
||||
@@ -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<String>, //[],
|
||||
pub options: Vec<Channel_Option>,
|
||||
pub options: Vec<ChannelOption>,
|
||||
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<Filter_Option>, //[],
|
||||
pub options: Vec<FilterOption>, //[],
|
||||
pub multiSelect: bool, //true
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct Filter_Option{
|
||||
pub struct FilterOption{
|
||||
pub id: String, //"sort",
|
||||
pub title: String, //"Sort",
|
||||
}
|
||||
|
||||
@@ -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<FlaresolverrCookie>,
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user