cleanup and fixed faulty perverzija urls
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#![warn(unused_extern_crates)]
|
||||
#![allow(non_snake_case)]
|
||||
extern crate diesel;
|
||||
|
||||
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
|
||||
use dotenvy::dotenv;
|
||||
@@ -19,7 +19,7 @@ type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
#[ntex::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_BACKTRACE", "1");
|
||||
// std::env::set_var("RUST_BACKTRACE", "1");
|
||||
env_logger::init(); // You need this to actually see logs
|
||||
dotenv().ok();
|
||||
|
||||
|
||||
@@ -307,6 +307,7 @@ impl PerverzijaProvider {
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.collect();
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -316,10 +317,6 @@ impl PerverzijaProvider {
|
||||
return Err("Unexpected video snippet length".into());
|
||||
}
|
||||
|
||||
// for (index,line) in vid.iter().enumerate() {
|
||||
// println!("Line {}: {}", index, line.to_string().trim());
|
||||
// }
|
||||
|
||||
let mut title = vid[5].split(" title=\"").collect::<Vec<&str>>()[1]
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
@@ -350,6 +347,9 @@ impl PerverzijaProvider {
|
||||
let db_result = db::get_video(&mut conn,lookup_url.clone());
|
||||
match db_result {
|
||||
Ok(Some(url)) => {
|
||||
if url.starts_with("!"){
|
||||
return Err("Video was removed".into());
|
||||
}
|
||||
let mut id = url.split("data=").collect::<Vec<&str>>()[1]
|
||||
.to_string();
|
||||
if id.contains("&"){
|
||||
@@ -373,13 +373,16 @@ impl PerverzijaProvider {
|
||||
}
|
||||
return Ok(video_item);
|
||||
}
|
||||
Ok(None) => (),
|
||||
Ok(None) => {
|
||||
println!("Couldnt find {}", lookup_url);
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error fetching video from database: {}", e);
|
||||
// return Err(format!("Error fetching video from database: {}", e).into());
|
||||
}
|
||||
}
|
||||
drop(conn);
|
||||
|
||||
|
||||
let client = match env::var("BURP_URL").as_deref() {
|
||||
Ok(burp_url) =>
|
||||
@@ -398,21 +401,27 @@ impl PerverzijaProvider {
|
||||
let text = match response.status().is_success(){
|
||||
true => response.text().await?,
|
||||
false => {
|
||||
println!("Failed to fetch video details");
|
||||
return Err("Failed to fetch video details".into());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let url = text.split("<iframe src=\"").collect::<Vec<&str>>()[1]
|
||||
let mut url = text.split("<iframe src=\"").collect::<Vec<&str>>()[1]
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string().replace("index.php","xs1.php");
|
||||
println!("new_url = {:?}", url);
|
||||
if url.starts_with("https://discord.com"){
|
||||
return Err("Discord link found, skipping video".into());
|
||||
url = "!".to_string()
|
||||
}
|
||||
|
||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||
let _ = db::insert_video(&mut conn, &lookup_url, &url);
|
||||
let insert_result = db::insert_video(&mut conn, &lookup_url, &url);
|
||||
match insert_result{
|
||||
Ok(x) => (),
|
||||
Err(e) => {println!("{:?}", e); }
|
||||
}
|
||||
drop(conn);
|
||||
if !url.contains("xtremestream.xyz"){
|
||||
return Err("Video URL does not contain xtremestream.xyz".into());
|
||||
|
||||
Reference in New Issue
Block a user