From 079e464b98303c343e3520c31ac835e3d1b4c040 Mon Sep 17 00:00:00 2001 From: 4gray Date: Fri, 20 Dec 2024 22:56:30 +0100 Subject: [PATCH] feat(media): add support for custom user-agent, referer, and origin headers in MPV command --- src-tauri/src/commands/media.rs | 46 +++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/commands/media.rs b/src-tauri/src/commands/media.rs index 2dcf99640..a63f8b74a 100644 --- a/src-tauri/src/commands/media.rs +++ b/src-tauri/src/commands/media.rs @@ -29,6 +29,9 @@ pub async fn open_in_mpv( path: String, title: String, thumbnail: Option, + user_agent: Option, + referer: Option, + origin: Option, app_handle: tauri::AppHandle, ) -> Result { info!("Custom MVP path: {}", path); @@ -68,11 +71,43 @@ pub async fn open_in_mpv( .as_secs() ); - let child = Command::new(mpv_path) - .arg(format!("--input-ipc-server={}", ipc_socket)) - .arg(&url) - .spawn() - .map_err(|e| e.to_string())?; + let mut command = Command::new(mpv_path.clone()); + command.arg(format!("--input-ipc-server={}", ipc_socket)); + + // Add headers if they are provided + if let Some(ua) = user_agent { + if !ua.is_empty() { + command.arg(format!("--user-agent={}", ua)); + } + } + + if let Some(ref_url) = referer { + if !ref_url.is_empty() { + command.arg(format!("--referrer={}", ref_url)); + } + } + + if let Some(origin_url) = origin { + if !origin_url.is_empty() { + command.arg(format!("--http-header-fields=Origin: {}", origin_url)); + } + } + + command.arg(&url); + + // Log the complete command line + let command_str = format!( + "{} {}", + mpv_path, + command + .get_args() + .map(|arg| arg.to_string_lossy()) + .collect::>() + .join(" ") + ); + info!("Complete MPV command: {}", command_str); + + let child = command.spawn().map_err(|e| e.to_string())?; let process_id = child.id(); @@ -187,3 +222,4 @@ pub async fn open_in_vlc( Ok(()) } +