sxyprn fix

This commit is contained in:
Simon
2026-05-04 16:18:54 +00:00
committed by ForgeCode
parent 275c89efef
commit 60d29ca905
2 changed files with 85 additions and 20 deletions

View File

@@ -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<T: Clone>(lists: &[Vec<T>]) -> Vec<T> {
result
}
pub fn get_redirect_location(url: &str) -> Result<Option<String>, Box<dyn Error>> {
// 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)
}