diff --git a/src/proxies/sxyprn.rs b/src/proxies/sxyprn.rs index a5d89d1..cc8774c 100644 --- a/src/proxies/sxyprn.rs +++ b/src/proxies/sxyprn.rs @@ -38,6 +38,7 @@ impl SxyprnProxy { ) -> String { let mut requester = requester.get_ref().clone(); let url = "https://sxyprn.com/".to_string() + &url; + println!("Fetching URL: {}", url); let text = requester.get(&url, None).await.unwrap_or("".to_string()); if text.is_empty() { return "".to_string(); @@ -48,44 +49,71 @@ impl SxyprnProxy { .split("\"}") .collect::>()[0] .replace("\\", ""); - //println!("src: {}",data_string); + println!("src: {}", data_string); let mut tmp = data_string .split("/") .map(|s| s.to_string()) .collect::>(); - //println!("tmp: {:?}",tmp); + println!("tmp: {:?}", tmp); tmp[1] = format!( "{}8/{}", tmp[1], boo(ssut51(tmp[6].as_str()), ssut51(tmp[7].as_str())) ); - //println!("tmp[1]: {:?}",tmp[1]); + println!("tmp[1]: {:?}", tmp[1]); //preda tmp[5] = format!( "{}", tmp[5].parse::().unwrap() - ssut51(tmp[6].as_str()) - ssut51(tmp[7].as_str()) ); - //println!("tmp: {:?}",tmp); + println!("tmp: {:?}", tmp); let sxyprn_video_url = format!("https://sxyprn.com{}", tmp.join("/")); + println!("sxyprn_video_url: {}", sxyprn_video_url); + // let response = requester.get_raw_with_headers(&sxyprn_video_url, vec![ + // ("Accept".to_string(), "*/*".to_string()), + // // ("Accept-Encoding".to_string(), "identity".to_string()), + // // ("Accept-Language".to_string(), "de,en-US;q=0.9,en;q=0.8".to_string()), + // // ("Cache-Control".to_string(), "no-cache".to_string()), + // // ("Connection".to_string(), "keep-alive".to_string()), + // ("Host".to_string(), "sxyprn.com".to_string()), + // // ("Pragma".to_string(), "no-cache".to_string()), + // // ("Priority".to_string(), "u=4".to_string()), + // // ("Range".to_string(), "bytes=0-".to_string()), + // // ("Referer".to_string(), url.clone()), + // // ("Sec-Fetch-Dest".to_string(), "video".to_string()), + // // ("Sec-Fetch-Mode".to_string(), "no-cors".to_string()), + // // ("Sec-Fetch-Site".to_string(), "same-origin".to_string()), + // // ("Sec-GPC".to_string(), "1".to_string()), + // // ("TE".to_string(), "trailers".to_string()), + // ("User-Agent".to_string(), "curl/8.5.0".to_string()) + // ]) + // .await; + // match response { + // Ok(resp) => { + // println!("Response headers: {:?}", resp.headers()); + // println!("Response status: {}", resp.status()); + // return format!( + // "https:{}", + // resp.headers() + // .get("location") + // .unwrap() + // .to_str() + // .unwrap_or("") + // .to_string() + // ); + // } + // Err(e) => { + // println!("Error fetching video URL: {}", e); + // } + // } - let response = requester.get_raw(&sxyprn_video_url).await; - match response { - Ok(resp) => { - return format!( - "https:{}", - resp.headers() - .get("Location") - .unwrap() - .to_str() - .unwrap_or("") - .to_string() - ); - } - Err(e) => { - println!("Error fetching video URL: {}", e); - } + match crate::util::get_redirect_location(&sxyprn_video_url) { + Ok(Some(loc)) => {println!("Redirect target found: {}", loc); return format!("https:{}", loc)}, + Ok(None) => println!("No redirect found for {}", sxyprn_video_url), + Err(e) => eprintln!("Request failed: {}", e), } + return "".to_string(); } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 957b3f7..eafc127 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,6 @@ +use std::error::Error; +use std::process::Command; + pub mod cache; pub mod discord; pub mod flaresolverr; @@ -50,3 +53,37 @@ pub fn interleave(lists: &[Vec]) -> Vec { result } + +pub fn get_redirect_location(url: &str) -> Result, Box> { +// 1. Execute curl: + // -s: Silent (no progress bar) + // -I: Fetch headers only (HEAD request) + let output = Command::new("curl") + .arg("-sI") + .arg(url) + .output()?; + + // Check if the command executed successfully + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + return Err(format!("curl command failed: {}", stderr).into()); + } + + // 2. Parse the stdout + let stdout = String::from_utf8_lossy(&output.stdout); + + // HTTP headers are separated by \r\n or \n + for line in stdout.lines() { + // Case-insensitive check for "Location:" + if line.to_lowercase().starts_with("location:") { + // Split "Location: https://example.com" into ["Location", " https://example.com"] + let parts: Vec<&str> = line.splitn(2, ':').collect(); + if parts.len() == 2 { + // Trim whitespace and potential carriage returns (\r) + return Ok(Some(parts[1].trim().to_string())); + } + } + } + + Ok(None) +} \ No newline at end of file