add quickjs but has bugs
This commit is contained in:
@@ -6,7 +6,7 @@ use std::process::Stdio;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use anyhow::{Result, anyhow};
|
||||
use regex::Regex;
|
||||
use crate::ytdlp;
|
||||
use crate::binary_manager;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct VideoMetadata {
|
||||
@@ -54,9 +54,19 @@ pub struct LogEvent {
|
||||
}
|
||||
|
||||
pub async fn fetch_metadata(app: &AppHandle, url: &str, parse_mix_playlist: bool) -> Result<MetadataResult> {
|
||||
let ytdlp_path = ytdlp::get_ytdlp_path(app)?;
|
||||
let ytdlp_path = binary_manager::get_ytdlp_path(app)?; // Updated path call
|
||||
|
||||
// Inject PATH for QuickJS
|
||||
let bin_dir = binary_manager::get_bin_dir(app)?;
|
||||
let path_env = std::env::var("PATH").unwrap_or_default();
|
||||
let new_path_env = format!("{}{}{}", bin_dir.to_string_lossy(), if cfg!(windows) { ";" } else { ":" }, path_env);
|
||||
|
||||
let mut cmd = Command::new(ytdlp_path);
|
||||
|
||||
// Environment injection
|
||||
cmd.env("PATH", new_path_env);
|
||||
cmd.arg("--js-runtime").arg("qjs"); // Force QuickJS
|
||||
|
||||
cmd.arg("--dump-single-json")
|
||||
.arg("--flat-playlist")
|
||||
.arg("--no-warnings");
|
||||
@@ -124,9 +134,19 @@ pub async fn download_video(
|
||||
url: String,
|
||||
options: DownloadOptions,
|
||||
) -> Result<String> {
|
||||
let ytdlp_path = ytdlp::get_ytdlp_path(&app)?;
|
||||
let ytdlp_path = binary_manager::get_ytdlp_path(&app)?; // Updated path call
|
||||
|
||||
// Inject PATH for QuickJS
|
||||
let bin_dir = binary_manager::get_bin_dir(&app)?;
|
||||
let path_env = std::env::var("PATH").unwrap_or_default();
|
||||
let new_path_env = format!("{}{}{}", bin_dir.to_string_lossy(), if cfg!(windows) { ";" } else { ":" }, path_env);
|
||||
|
||||
let mut args = Vec::new();
|
||||
|
||||
// JS Runtime args must be passed via .arg(), env is set on command builder
|
||||
args.push("--js-runtime".to_string());
|
||||
args.push("quickjs".to_string());
|
||||
|
||||
args.push(url);
|
||||
|
||||
// Output template
|
||||
@@ -153,6 +173,7 @@ pub async fn download_video(
|
||||
args.push("--newline".to_string()); // Easier parsing
|
||||
|
||||
let mut child = Command::new(ytdlp_path)
|
||||
.env("PATH", new_path_env) // Inject PATH
|
||||
.args(&args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped()) // Capture stderr for logs
|
||||
@@ -229,4 +250,4 @@ pub async fn download_video(
|
||||
}).ok();
|
||||
Err(anyhow!("Download process failed"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user