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",
"private": true,
"version": "1.1.0",
"version": "1.2.0",
"type": "module",
"scripts": {
"dev": "vite",

2
src-tauri/Cargo.lock generated
View File

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

View File

@@ -1,6 +1,6 @@
[package]
name = "stream-capture"
version = "1.1.0"
version = "1.2.0"
description = "A Tauri App"
authors = ["you"]
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
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() {

View File

@@ -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

View File

@@ -142,7 +142,7 @@ function setTheme(theme: 'light' | 'dark' | 'system') {
选择
</button>
</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>
<!-- Theme -->