Skip to content

Commit 540affc

Browse files
committed
better folder opening + subs embedded in the video directly
1 parent 3857b61 commit 540affc

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

src-tauri/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
# Generated by Tauri
66
# will have schema files for capabilities auto-completion
77
/gen/schemas
8+
9+
README.md

src-tauri/src/lib.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ async fn start_download(
441441
ffmpeg_path,
442442
"--merge-output-format".to_string(),
443443
"mp4".to_string(),
444+
"--embed-thumbnail".to_string(),
444445
"--no-keep-fragments".to_string(),
445446
"-P".to_string(),
446447
home_path,
@@ -489,6 +490,9 @@ async fn start_download(
489490
args.push("--write-subs".to_string());
490491
args.push("--write-auto-sub".to_string());
491492
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());
492496
args.push("--sub-langs".to_string());
493497
// Limit subtitle downloads to English variants to avoid fetching dozens of auto-translated tracks.
494498
args.push("en.*,en,-live_chat".to_string());
@@ -984,14 +988,45 @@ async fn update_ytdlp(app: AppHandle) -> Result<String, String> {
984988
Ok(new_version)
985989
}
986990

991+
#[tauri::command]
992+
async fn open_folder(path: String) -> Result<(), String> {
993+
#[cfg(target_os = "windows")]
994+
{
995+
// Normalize: replace forward slashes with backslashes and strip any trailing separator
996+
let normalized = path.replace('/', "\\");
997+
let normalized = normalized.trim_end_matches('\\');
998+
tokio::process::Command::new("explorer.exe")
999+
.arg(normalized)
1000+
.spawn()
1001+
.map_err(|e| e.to_string())?;
1002+
return Ok(());
1003+
}
1004+
#[cfg(target_os = "macos")]
1005+
{
1006+
tokio::process::Command::new("open")
1007+
.arg(&path)
1008+
.spawn()
1009+
.map_err(|e| e.to_string())?;
1010+
return Ok(());
1011+
}
1012+
#[cfg(target_os = "linux")]
1013+
{
1014+
tokio::process::Command::new("xdg-open")
1015+
.arg(&path)
1016+
.spawn()
1017+
.map_err(|e| e.to_string())?;
1018+
return Ok(());
1019+
}
1020+
}
1021+
9871022
#[cfg_attr(mobile, tauri::mobile_entry_point)]
9881023
pub fn run() {
9891024
tauri::Builder::default()
9901025
.plugin(tauri_plugin_shell::init())
9911026
.plugin(tauri_plugin_dialog::init())
9921027
.plugin(tauri_plugin_fs::init())
9931028
.plugin(tauri_plugin_opener::init())
994-
.invoke_handler(tauri::generate_handler![start_download, fetch_formats, fetch_playlist_info, cancel_download, check_ytdlp_update, update_ytdlp])
1029+
.invoke_handler(tauri::generate_handler![start_download, fetch_formats, fetch_playlist_info, cancel_download, check_ytdlp_update, update_ytdlp, open_folder])
9951030
.run(tauri::generate_context!())
9961031
.expect("error while running tauri application");
9971032
}

src/App.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { twMerge } from "tailwind-merge";
55
import { invoke } from "@tauri-apps/api/core";
66
import { listen } from "@tauri-apps/api/event";
77
import { open } from "@tauri-apps/plugin-dialog";
8-
import { revealItemInDir } from "@tauri-apps/plugin-opener";
98
import { downloadDir } from "@tauri-apps/api/path";
109

1110
function cn(...inputs: ClassValue[]) {
@@ -448,12 +447,10 @@ export default function App() {
448447
setHistory(prev => prev.filter(h => h.id !== id));
449448
};
450449

451-
const openFolder = async (path: string) => {
452-
try {
453-
await revealItemInDir(path);
454-
} catch (error) {
450+
const openFolder = (path: string) => {
451+
invoke('open_folder', { path }).catch(error => {
455452
console.error('Failed to open folder:', error);
456-
}
453+
});
457454
};
458455

459456
// Handle TXT file import

0 commit comments

Comments
 (0)