cleanup and fixed faulty perverzija urls

This commit is contained in:
Simon
2025-06-06 08:51:24 +00:00
parent 60a07269f6
commit ec1d7b8eef
4 changed files with 21 additions and 16 deletions

View File

@@ -1,11 +1,9 @@
[package] [package]
name = "hottub" name = "hottub"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2024"
[dependencies] [dependencies]
async-trait = "0.1.88"
awc = "3.7.0"
diesel = { version = "2.2.10", features = ["sqlite", "r2d2"] } diesel = { version = "2.2.10", features = ["sqlite", "r2d2"] }
dotenvy = "0.15.7" dotenvy = "0.15.7"
env_logger = "0.11.8" env_logger = "0.11.8"
@@ -14,9 +12,7 @@ futures = "0.3.31"
htmlentity = "1.3.2" htmlentity = "1.3.2"
ntex = { version = "2.0", features = ["tokio"] } ntex = { version = "2.0", features = ["tokio"] }
ntex-files = "2.0.0" ntex-files = "2.0.0"
once_cell = "1.21.3"
reqwest = { version = "0.12.18", features = ["blocking", "json", "rustls-tls"] } reqwest = { version = "0.12.18", features = ["blocking", "json", "rustls-tls"] }
serde = "1.0.219" serde = "1.0.219"
serde_json = "1.0.140" serde_json = "1.0.140"
tokio = { version = "1.45.1", features = ["full"] }

View File

@@ -1,7 +1,7 @@
-- Your SQL goes here -- Your SQL goes here
CREATE TABLE videos ( CREATE TABLE videos (
id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video
url TEXT NOT NULL UNIQUE--, url TEXT NOT NULL--,
--views INTEGER, --views INTEGER,
--rating INTEGER, --rating INTEGER,
--uploader TEXT --uploader TEXT

View File

@@ -1,5 +1,5 @@
#![warn(unused_extern_crates)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
extern crate diesel;
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection}; use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
use dotenvy::dotenv; use dotenvy::dotenv;
@@ -19,7 +19,7 @@ type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
#[ntex::main] #[ntex::main]
async fn main() -> std::io::Result<()> { 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 env_logger::init(); // You need this to actually see logs
dotenv().ok(); dotenv().ok();

View File

@@ -307,6 +307,7 @@ impl PerverzijaProvider {
.into_iter() .into_iter()
.filter_map(Result::ok) .filter_map(Result::ok)
.collect(); .collect();
return items; return items;
} }
@@ -316,10 +317,6 @@ impl PerverzijaProvider {
return Err("Unexpected video snippet length".into()); 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] let mut title = vid[5].split(" title=\"").collect::<Vec<&str>>()[1]
.split("\"") .split("\"")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
@@ -350,6 +347,9 @@ impl PerverzijaProvider {
let db_result = db::get_video(&mut conn,lookup_url.clone()); let db_result = db::get_video(&mut conn,lookup_url.clone());
match db_result { match db_result {
Ok(Some(url)) => { Ok(Some(url)) => {
if url.starts_with("!"){
return Err("Video was removed".into());
}
let mut id = url.split("data=").collect::<Vec<&str>>()[1] let mut id = url.split("data=").collect::<Vec<&str>>()[1]
.to_string(); .to_string();
if id.contains("&"){ if id.contains("&"){
@@ -373,13 +373,16 @@ impl PerverzijaProvider {
} }
return Ok(video_item); return Ok(video_item);
} }
Ok(None) => (), Ok(None) => {
println!("Couldnt find {}", lookup_url);
},
Err(e) => { Err(e) => {
println!("Error fetching video from database: {}", e); println!("Error fetching video from database: {}", e);
// return Err(format!("Error fetching video from database: {}", e).into()); // return Err(format!("Error fetching video from database: {}", e).into());
} }
} }
drop(conn); drop(conn);
let client = match env::var("BURP_URL").as_deref() { let client = match env::var("BURP_URL").as_deref() {
Ok(burp_url) => Ok(burp_url) =>
@@ -398,21 +401,27 @@ impl PerverzijaProvider {
let text = match response.status().is_success(){ let text = match response.status().is_success(){
true => response.text().await?, true => response.text().await?,
false => { false => {
println!("Failed to fetch video details");
return Err("Failed to fetch video details".into()); 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("\"") .split("\"")
.collect::<Vec<&str>>()[0] .collect::<Vec<&str>>()[0]
.to_string().replace("index.php","xs1.php"); .to_string().replace("index.php","xs1.php");
println!("new_url = {:?}", url);
if url.starts_with("https://discord.com"){ 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 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); drop(conn);
if !url.contains("xtremestream.xyz"){ if !url.contains("xtremestream.xyz"){
return Err("Video URL does not contain xtremestream.xyz".into()); return Err("Video URL does not contain xtremestream.xyz".into());