make spawn function accept slice of &str instead of generics so joining into string for logging is easy
This commit is contained in:
parent
ae3c0a9557
commit
8ea0c31ff6
3 changed files with 10 additions and 8 deletions
|
|
@ -22,7 +22,7 @@ impl FFMpeg {
|
||||||
let bitrate = format!("{}k", bitrate);
|
let bitrate = format!("{}k", bitrate);
|
||||||
let output = spawn(
|
let output = spawn(
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
[
|
&[
|
||||||
"-i",
|
"-i",
|
||||||
input_path,
|
input_path,
|
||||||
"-codec:a",
|
"-codec:a",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::process::Output;
|
use std::process::Output;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
use tracing::{event, Level};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SpawnError {
|
pub enum SpawnError {
|
||||||
|
|
@ -36,11 +36,13 @@ impl fmt::Display for SpawnError {
|
||||||
|
|
||||||
/* !!! The argument list could be exploited in a way to inject malicious arguments !!!
|
/* !!! The argument list could be exploited in a way to inject malicious arguments !!!
|
||||||
!!! and alter the way program executes and/or gain access to system !!! */
|
!!! and alter the way program executes and/or gain access to system !!! */
|
||||||
pub async fn spawn<I, S>(program: &str, args: I) -> Result<Output, SpawnError>
|
pub async fn spawn(program: &str, args: &[&str]) -> Result<Output, SpawnError>
|
||||||
where
|
|
||||||
I: IntoIterator<Item = S>,
|
|
||||||
S: AsRef<OsStr>,
|
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
let cmd_args = args.join(" ");
|
||||||
|
event!(Level::INFO, "{} {}", program, cmd_args);
|
||||||
|
}
|
||||||
|
|
||||||
let output = Command::new(program).args(args).output().await?;
|
let output = Command::new(program).args(args).output().await?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ pub struct YtDlp {}
|
||||||
// BUG: REAL ARGUMENT INJECTION! FIX ASAP
|
// BUG: REAL ARGUMENT INJECTION! FIX ASAP
|
||||||
impl YtDlp {
|
impl YtDlp {
|
||||||
pub async fn load_info(url: &str) -> Result<YtDlpInfo, YtDlpError> {
|
pub async fn load_info(url: &str) -> Result<YtDlpInfo, YtDlpError> {
|
||||||
let output = spawn("python", ["-m", "yt_dlp", url, "-j"]).await?;
|
let output = spawn("python", &["-m", "yt_dlp", url, "-j"]).await?;
|
||||||
|
|
||||||
Ok(YtDlpInfo::parse(&output.stdout)?)
|
Ok(YtDlpInfo::parse(&output.stdout)?)
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +178,7 @@ impl YtDlp {
|
||||||
pub async fn download(url: &str, format_id: &str, output_path: &str) -> Result<(), YtDlpError> {
|
pub async fn download(url: &str, format_id: &str, output_path: &str) -> Result<(), YtDlpError> {
|
||||||
spawn(
|
spawn(
|
||||||
"python",
|
"python",
|
||||||
[
|
&[
|
||||||
"-m",
|
"-m",
|
||||||
"yt_dlp",
|
"yt_dlp",
|
||||||
url,
|
url,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue