Skip to content

Commit a6b56d3

Browse files
committed
fixed important issue, last changes made subtitle format unsuable
1 parent 540affc commit a6b56d3

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

.vscode/extensions.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
3-
}
1+
{}

src-tauri/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,12 @@ async fn start_download(
418418

419419
let output_template = "%(title)s.%(ext)s".to_string();
420420
let home_path = format!("home:{}", download_dir);
421-
let temp_dir = PathBuf::from(&download_dir).join("_dlpgui_temp");
422-
if let Err(err) = std::fs::create_dir_all(&temp_dir) {
423-
println!("[WARN] Failed to create yt-dlp temp directory {:?}: {}", temp_dir, err);
421+
let download_temp_dir = PathBuf::from(&download_dir).join("_dlpgui_temp").join(&id);
422+
if let Err(err) = std::fs::create_dir_all(&download_temp_dir) {
423+
println!("[WARN] Failed to create yt-dlp temp directory {:?}: {}", download_temp_dir, err);
424424
}
425-
let temp_path = format!("temp:{}", temp_dir.to_string_lossy());
425+
let temp_path = format!("temp:{}", download_temp_dir.to_string_lossy());
426+
let subtitle_path = format!("subtitle:{}", download_temp_dir.to_string_lossy());
426427

427428
// Build args based on whether aria2c is enabled
428429
// aria2c cannot download HLS streams, so:
@@ -447,6 +448,8 @@ async fn start_download(
447448
home_path,
448449
"-P".to_string(),
449450
temp_path,
451+
"-P".to_string(),
452+
subtitle_path,
450453
"-o".to_string(),
451454
output_template,
452455
];
@@ -490,9 +493,6 @@ async fn start_download(
490493
args.push("--write-subs".to_string());
491494
args.push("--write-auto-sub".to_string());
492495
args.push("--embed-subs".to_string());
493-
// Remove subtitle sidecars after embedding to avoid .vtt file clutter.
494-
args.push("--compat-options".to_string());
495-
args.push("no-keep-subs".to_string());
496496
args.push("--sub-langs".to_string());
497497
// Limit subtitle downloads to English variants to avoid fetching dozens of auto-translated tracks.
498498
args.push("en.*,en,-live_chat".to_string());
@@ -525,6 +525,7 @@ async fn start_download(
525525

526526
let app_clone = app.clone();
527527
let id_clone = id.clone();
528+
let temp_dir_for_cleanup = download_temp_dir.clone();
528529

529530
// Spawn the event handler in a separate task
530531
tokio::spawn(async move {
@@ -767,6 +768,14 @@ async fn start_download(
767768
downloads.remove(&id_clone);
768769
println!("[DEBUG] Removed download from ACTIVE_DOWNLOADS");
769770
}
771+
772+
if temp_dir_for_cleanup.exists() {
773+
if let Err(err) = std::fs::remove_dir_all(&temp_dir_for_cleanup) {
774+
println!("[WARN] Failed to clean temp directory {:?}: {}", temp_dir_for_cleanup, err);
775+
} else {
776+
println!("[DEBUG] Cleaned temp directory {:?}", temp_dir_for_cleanup);
777+
}
778+
}
770779
});
771780

772781
Ok(())

0 commit comments

Comments
 (0)