check if ytdl exited with error

This commit is contained in:
Nils Pukropp committed 2021-05-11 07:55:11 +02:00
1 parent bac1a5c8b0
commit 3269a32a46
1 file changed
+15 -7
+15 -7
View File
@@ -1,6 +1,6 @@
//! Rust-Wrapper for youtube-dl //! Rust-Wrapper for youtube-dl
use std::fmt; use std::{fmt, process::Output};
use std::{ use std::{
fmt::{Display, Formatter}, fmt::{Display, Formatter},
fs::{canonicalize, create_dir_all}, fs::{canonicalize, create_dir_all},
@@ -99,14 +99,22 @@ impl YoutubeDL {
pub fn download(&self) -> Result<&PathBuf, String> { pub fn download(&self) -> Result<&PathBuf, String> {
let result = self.spawn_youtube_dl(); let result = self.spawn_youtube_dl();
if let Err(why) = result { match result {
Err(format!("Error downloading video: {:?}", why)) Err(why) => Err(format!("Error downloading video: {:?}", why)),
} else { Ok(output) => {
Ok(&self.path) if output.status.success() {
Ok(&self.path)
} else {
Err(format!(
"Error downloading video: {:?}",
output.stderr.as_slice()
))
}
}
} }
} }
fn spawn_youtube_dl(&self) -> Result<ExitStatus, Error> { fn spawn_youtube_dl(&self) -> Result<Output, Error> {
let mut path = self.path.clone(); let mut path = self.path.clone();
path.push("%(title).90s.%(ext)s"); path.push("%(title).90s.%(ext)s");
let mut cmd = Command::new("youtube-dl"); let mut cmd = Command::new("youtube-dl");
@@ -130,6 +138,6 @@ impl YoutubeDL {
} }
Ok(process) => process, Ok(process) => process,
}; };
pr.wait() pr.wait_with_output()
} }
} }