support cookies, fix bugs

This commit is contained in:
Julian Freeman
2026-01-13 18:46:56 -04:00
parent bbcb10b3ca
commit 4d5cac7a46
6 changed files with 60 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "stream-capture", "name": "stream-capture",
"private": true, "private": true,
"version": "1.1.0", "version": "1.2.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

2
src-tauri/Cargo.lock generated
View File

@@ -3971,7 +3971,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "stream-capture" name = "stream-capture"
version = "1.1.0" version = "1.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.22.1", "base64 0.22.1",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "stream-capture" name = "stream-capture"
version = "1.1.0" version = "1.2.0"
description = "A Tauri App" description = "A Tauri App"
authors = ["you"] authors = ["you"]
edition = "2021" edition = "2021"

View File

@@ -72,35 +72,72 @@ pub async fn fetch_metadata(app: &AppHandle, url: &str, parse_mix_playlist: bool
// Load settings to check for cookies // Load settings to check for cookies
let settings = storage::load_settings(app)?; let settings = storage::load_settings(app)?;
let mut cmd = Command::new(ytdlp_path); let mut args = Vec::new();
#[cfg(target_os = "windows")]
cmd.creation_flags(0x08000000);
// Pass the runtime and its absolute path to --js-runtimes // 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. // 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() { 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") args.push("--dump-single-json".to_string());
.arg("--flat-playlist") args.push("--flat-playlist".to_string());
.arg("--no-warnings"); args.push("--no-warnings".to_string());
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. // 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. // 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"); args.push("--extractor-args".to_string());
args.push("youtube:skip=dash,hls,translated_subs;player_skip=js".to_string());
if parse_mix_playlist {
cmd.arg("--playlist-end").arg("20");
} }
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()); 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?; let output = cmd.output().await?;
if !output.status.success() { if !output.status.success() {

View File

@@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "StreamCapture", "productName": "StreamCapture",
"version": "1.1.0", "version": "1.2.0",
"identifier": "top.volan.stream-capture", "identifier": "top.volan.stream-capture",
"build": { "build": {
"beforeDevCommand": "pnpm dev", "beforeDevCommand": "pnpm dev",
@@ -13,7 +13,7 @@
"windows": [ "windows": [
{ {
"label": "main", "label": "main",
"title": "流萤 - 视频下载 v1.1.0", "title": "流萤 - 视频下载 v1.2.0",
"width": 1300, "width": 1300,
"height": 900, "height": 900,
"visible": false "visible": false

View File

@@ -142,7 +142,7 @@ function setTheme(theme: 'light' | 'dark' | 'system') {
选择 选择
</button> </button>
</div> </div>
<p class="text-xs text-gray-400 mt-2">选填如果遇到需要登录的视频如会员专享请指定包含 cookies 的文本文件Netscape 格式</p> <p class="text-xs text-gray-400 mt-2">选填请指定包含 cookies 的文本文件Netscape 格式频繁使用 cookies 下载视频可能导致封号慎用</p>
</section> </section>
<!-- Theme --> <!-- Theme -->