From 4d5cac7a464e39c37da9ccb11cdf32b40ed9e826 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Tue, 13 Jan 2026 18:46:56 -0400 Subject: [PATCH] support cookies, fix bugs --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/downloader.rs | 71 ++++++++++++++++++++++++++++--------- src-tauri/tauri.conf.json | 4 +-- src/views/Settings.vue | 2 +- 6 files changed, 60 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 5a4d808..f4d9887 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stream-capture", "private": true, - "version": "1.1.0", + "version": "1.2.0", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index fcfccab..bec9c95 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3971,7 +3971,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stream-capture" -version = "1.1.0" +version = "1.2.0" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b16a605..b3eddd8 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stream-capture" -version = "1.1.0" +version = "1.2.0" description = "A Tauri App" authors = ["you"] edition = "2021" diff --git a/src-tauri/src/downloader.rs b/src-tauri/src/downloader.rs index e3148ba..9a358a9 100644 --- a/src-tauri/src/downloader.rs +++ b/src-tauri/src/downloader.rs @@ -72,35 +72,72 @@ pub async fn fetch_metadata(app: &AppHandle, url: &str, parse_mix_playlist: bool // Load settings to check for cookies let settings = storage::load_settings(app)?; - let mut cmd = Command::new(ytdlp_path); - #[cfg(target_os = "windows")] - cmd.creation_flags(0x08000000); - + let mut args = Vec::new(); + // Pass the runtime and its absolute path to --js-runtimes // Rust's Command automatically handles spaces in arguments, so we should NOT quote the path here. - cmd.arg("--js-runtimes").arg(format!("quickjs:{}", qjs_path.to_string_lossy())); + args.push("--js-runtimes".to_string()); + args.push(format!("quickjs:{}", qjs_path.to_string_lossy())); - if let Some(cookies) = settings.cookies_path { + let mut has_cookies = false; + if let Some(cookies) = &settings.cookies_path { if !cookies.is_empty() { - cmd.arg("--cookies").arg(cookies); + if std::path::Path::new(cookies).exists() { + args.push("--cookies".to_string()); + args.push(cookies.clone()); + has_cookies = true; + app.emit("download-log", LogEvent { + id: "Analysis".to_string(), + message: format!("已加载 Cookies: {}", cookies), + level: "info".to_string(), + }).ok(); + } else { + app.emit("download-log", LogEvent { + id: "Analysis".to_string(), + message: format!("Cookies 文件不存在: {}", cookies), + level: "error".to_string(), + }).ok(); + } } } - cmd.arg("--dump-single-json") - .arg("--flat-playlist") - .arg("--no-warnings"); + args.push("--dump-single-json".to_string()); + args.push("--flat-playlist".to_string()); + args.push("--no-warnings".to_string()); - // Optimize metadata fetching: skip heavy manifests and player JS execution. - // Skipping JS prevents slow QuickJS spin-up and signature decryption, drastically speeding up single video parsing. - cmd.arg("--extractor-args").arg("youtube:skip=dash,hls,translated_subs;player_skip=js"); - - if parse_mix_playlist { - cmd.arg("--playlist-end").arg("20"); + if has_cookies { + // When using cookies, avoid skipping JS player to prevent challenge errors + args.push("--extractor-args".to_string()); + args.push("youtube:skip=dash,hls,translated_subs".to_string()); + } else { + // Optimize metadata fetching: skip heavy manifests and player JS execution. + // Skipping JS prevents slow QuickJS spin-up and signature decryption, drastically speeding up single video parsing. + args.push("--extractor-args".to_string()); + args.push("youtube:skip=dash,hls,translated_subs;player_skip=js".to_string()); } - cmd.arg(url); + if parse_mix_playlist { + args.push("--playlist-end".to_string()); + args.push("20".to_string()); + } + + args.push(url.to_string()); + + let mut cmd = Command::new(&ytdlp_path); + #[cfg(target_os = "windows")] + cmd.creation_flags(0x08000000); + + cmd.args(&args); cmd.stderr(Stdio::piped()); + // Log the full command + let full_cmd_str = format!("{} {}", ytdlp_path.to_string_lossy(), args.join(" ")); + app.emit("download-log", LogEvent { + id: "Analysis".to_string(), + message: format!("正在执行分析命令: {}", full_cmd_str), + level: "info".to_string(), + }).ok(); + let output = cmd.output().await?; if !output.status.success() { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index d15743a..db14984 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "StreamCapture", - "version": "1.1.0", + "version": "1.2.0", "identifier": "top.volan.stream-capture", "build": { "beforeDevCommand": "pnpm dev", @@ -13,7 +13,7 @@ "windows": [ { "label": "main", - "title": "流萤 - 视频下载 v1.1.0", + "title": "流萤 - 视频下载 v1.2.0", "width": 1300, "height": 900, "visible": false diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 62ac315..c9607bc 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -142,7 +142,7 @@ function setTheme(theme: 'light' | 'dark' | 'system') { 选择 -

选填。如果遇到需要登录的视频(如会员专享),请指定包含 cookies 的文本文件(Netscape 格式)。

+

选填。请指定包含 cookies 的文本文件(Netscape 格式)。频繁使用 cookies 下载视频可能导致封号,慎用。