support cookies, but with bugs
This commit is contained in:
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
use anyhow::{Result, anyhow};
|
||||
use regex::Regex;
|
||||
use crate::binary_manager;
|
||||
use crate::storage;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct VideoMetadata {
|
||||
@@ -38,6 +39,7 @@ pub struct DownloadOptions {
|
||||
pub quality: String, // e.g., "1080", "720", "best"
|
||||
pub output_path: String, // Directory
|
||||
pub output_format: String, // "original", "mp4", "webm", "mkv", "m4a", "aac", "opus", "vorbis", "wav", etc.
|
||||
pub cookies_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
@@ -67,6 +69,9 @@ pub async fn fetch_metadata(app: &AppHandle, url: &str, parse_mix_playlist: bool
|
||||
let ytdlp_path = binary_manager::get_ytdlp_path(app)?;
|
||||
let qjs_path = binary_manager::get_qjs_path(app)?; // Get absolute path to quickjs
|
||||
|
||||
// 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);
|
||||
@@ -75,6 +80,12 @@ pub async fn fetch_metadata(app: &AppHandle, url: &str, parse_mix_playlist: bool
|
||||
// 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()));
|
||||
|
||||
if let Some(cookies) = settings.cookies_path {
|
||||
if !cookies.is_empty() {
|
||||
cmd.arg("--cookies").arg(cookies);
|
||||
}
|
||||
}
|
||||
|
||||
cmd.arg("--dump-single-json")
|
||||
.arg("--flat-playlist")
|
||||
.arg("--no-warnings");
|
||||
@@ -185,6 +196,13 @@ pub async fn download_video(
|
||||
args.push("--ffmpeg-location".to_string());
|
||||
args.push(ffmpeg_path.to_string_lossy().to_string());
|
||||
|
||||
if let Some(cookies) = &options.cookies_path {
|
||||
if !cookies.is_empty() {
|
||||
args.push("--cookies".to_string());
|
||||
args.push(cookies.clone());
|
||||
}
|
||||
}
|
||||
|
||||
args.push(url);
|
||||
|
||||
// Output template
|
||||
|
||||
@@ -9,6 +9,7 @@ use chrono::{DateTime, Utc};
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Settings {
|
||||
pub download_path: String,
|
||||
pub cookies_path: Option<String>,
|
||||
pub theme: String, // 'light', 'dark', 'system'
|
||||
pub last_updated: Option<DateTime<Utc>>,
|
||||
}
|
||||
@@ -19,6 +20,7 @@ impl Default for Settings {
|
||||
// but for default struct we can keep it empty or a placeholder.
|
||||
Self {
|
||||
download_path: "".to_string(),
|
||||
cookies_path: None,
|
||||
theme: "system".to_string(),
|
||||
last_updated: None,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user