implement async process spawning
This commit is contained in:
parent
e935caefdc
commit
c6cff5ad66
3 changed files with 34 additions and 6 deletions
|
|
@ -1 +1,2 @@
|
|||
pub mod spawn;
|
||||
pub mod yt_dlp;
|
||||
|
|
|
|||
25
src/dl/spawn.rs
Normal file
25
src/dl/spawn.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue