π Problem Statement
Knowte's YouTube import feature accepts a URL pasted by the user and passes it directly to the bundled yt-dlp binary. If the user pastes:
- A non-URL string (
my lecture notes)
- A non-YouTube URL (
https://vimeo.com/123456)
- A private/unavailable video URL
...yt-dlp exits with a non-zero code. Without explicit error handling on the yt-dlp process exit, this either panics in Rust or returns an opaque error to the frontend.
π‘ Proposed Fix
1. Validate URL format and domain before invoking yt-dlp (Rust)
// src-tauri/src/downloader.rs
use url::Url; // add `url` crate to Cargo.toml
const ALLOWED_DOMAINS: &[&str] = &[
"youtube.com",
"youtu.be",
"www.youtube.com",
"m.youtube.com",
];
pub fn validate_youtube_url(raw_url: &str) -> Result<String, String> {
let parsed = Url::parse(raw_url)
.map_err(|_| "Invalid URL format. Please paste a valid YouTube link.".to_string())?;
let host = parsed
.host_str()
.unwrap_or("")
.trim_start_matches("www.");
if !ALLOWED_DOMAINS.iter().any(|d| d.trim_start_matches("www.") == host) {
return Err(format!(
"'{}' is not a supported source. Only YouTube URLs are currently supported.",
host
));
}
Ok(raw_url.to_string())
}
2. Handle yt-dlp non-zero exit codes explicitly
let output = Command::new(&yt_dlp_path)
.args(["-x", "--audio-format", "mp3", "-o", &output_path, &validated_url])
.output()
.map_err(|e| format!("Failed to launch yt-dlp: {}", e))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(format!("Download failed: {}", stderr));
}
π Files to Modify
| File |
Change |
src-tauri/src/downloader.rs |
Add URL validation + yt-dlp exit code handling |
src-tauri/Cargo.toml |
Add url crate dependency |
src/ |
Display user-friendly error message from Tauri |
Suggested labels: bug, tauri, ux, validation
I would like to work on this. Could you please assign it to me?
π Problem Statement
Knowte's YouTube import feature accepts a URL pasted by the user and passes it directly to the bundled
yt-dlpbinary. If the user pastes:my lecture notes)https://vimeo.com/123456)...
yt-dlpexits with a non-zero code. Without explicit error handling on theyt-dlpprocess exit, this either panics in Rust or returns an opaque error to the frontend.π‘ Proposed Fix
1. Validate URL format and domain before invoking yt-dlp (Rust)
2. Handle yt-dlp non-zero exit codes explicitly
π Files to Modify
src-tauri/src/downloader.rssrc-tauri/Cargo.tomlurlcrate dependencysrc/Suggested labels:
bug,tauri,ux,validationI would like to work on this. Could you please assign it to me?