Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix: sanitize log lines to remove URLs from error messages

Tonho409c7604219a
diff --git a/src-tauri/src/core/ytdlp.rs b/src-tauri/src/core/ytdlp.rs
index 996821b0..4bad4ac7 100644
--- a/src-tauri/src/core/ytdlp.rs
+++ b/src-tauri/src/core/ytdlp.rs
@@ -687,11 +687,13 @@ pub async fn download_video(
}
}
+ let last_line = last_error.lines().last().unwrap_or("unknown error").trim();
+ let sanitized = sanitize_log_line(last_line);
tracing::warn!(
"[yt-dlp] attempt {}/{} failed: {}",
attempt + 1,
max_attempts,
- last_error.lines().last().unwrap_or("unknown error").trim()
+ sanitized
);
continue;
}
@@ -712,6 +714,37 @@ async fn cleanup_part_files(dir: &Path) {
}
}
+fn sanitize_log_line(line: &str) -> String {
+ let mut result = String::with_capacity(line.len());
+ let mut remaining = line;
+ loop {
+ let found = remaining
+ .find("https://")
+ .or_else(|| remaining.find("http://"));
+ match found {
+ Some(start) => {
+ result.push_str(&remaining[..start]);
+ let url_part = &remaining[start..];
+ let url_end = url_part
+ .find(|c: char| c.is_whitespace() || c == '"' || c == '\'' || c == '>')
+ .unwrap_or(url_part.len());
+ let url = &url_part[..url_end];
+ if let Some(q) = url.find('?') {
+ result.push_str(&url[..q]);
+ } else {
+ result.push_str(url);
+ }
+ remaining = &url_part[url_end..];
+ }
+ None => {
+ result.push_str(remaining);
+ break;
+ }
+ }
+ }
+ result
+}
+
fn translate_ytdlp_error(stderr: &str) -> anyhow::Error {
let lower = stderr.to_lowercase();