implement async process spawning

This commit is contained in:
mykola2312 2024-02-19 12:48:10 +02:00
parent 1b0b3972cd
commit 87d25880f6
3 changed files with 34 additions and 6 deletions

View file

@ -1 +1,2 @@
pub mod spawn;
pub mod yt_dlp;

25
src/dl/spawn.rs Normal file
View file

@ -0,0 +1,25 @@
use std::process::{Command, Output};
use tokio::task::{spawn_blocking, JoinError};
pub enum SpawnError {
CommandError(std::io::Error),
SpawnBlockingError(JoinError)
}
pub async fn spawn_process(program: String, args: Vec<String>) -> Result<Output, SpawnError> {
let output = spawn_blocking(move || {
let output = Command::new(program)
.args(args)
.output();
match output {
Ok(output) => Ok(output),
Err(e) => Err(SpawnError::CommandError(e))
}
}).await;
match output {
Ok(output) => output,
Err(e) => Err(SpawnError::SpawnBlockingError(e))
}
}

View file

@ -13,20 +13,22 @@ pub struct YtDlpFormat {
pub vcodec: Option<String>,
pub acodec: Option<String>,
pub abr: Option<f32>,
pub vbr: Option<f32>
pub vbr: Option<f32>,
}
#[derive(Deserialize, Debug)]
pub struct YtDlpInfo {
pub id: String,
pub title: String,
pub formats: Vec<YtDlpFormat>
pub formats: Vec<YtDlpFormat>,
}
enum YtDlpError {
SpawnError,
}
pub struct YtDlp {}
impl YtDlp {
pub fn load_info(url: &str) {
}
}
pub async fn load_info(url: &str) {}
}