From 3269a32a4665afd06e50fe1298bd93853c648f26 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Tue, 11 May 2021 07:55:11 +0200 Subject: [PATCH] check if ytdl exited with error --- src/ytd.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ytd.rs b/src/ytd.rs index 4d628dc..d73fb5a 100644 --- a/src/ytd.rs +++ b/src/ytd.rs @@ -1,6 +1,6 @@ //! Rust-Wrapper for youtube-dl -use std::fmt; +use std::{fmt, process::Output}; use std::{ fmt::{Display, Formatter}, fs::{canonicalize, create_dir_all}, @@ -99,14 +99,22 @@ impl YoutubeDL { pub fn download(&self) -> Result<&PathBuf, String> { let result = self.spawn_youtube_dl(); - if let Err(why) = result { - Err(format!("Error downloading video: {:?}", why)) - } else { - Ok(&self.path) + match result { + Err(why) => Err(format!("Error downloading video: {:?}", why)), + Ok(output) => { + if output.status.success() { + Ok(&self.path) + } else { + Err(format!( + "Error downloading video: {:?}", + output.stderr.as_slice() + )) + } + } } } - fn spawn_youtube_dl(&self) -> Result { + fn spawn_youtube_dl(&self) -> Result { let mut path = self.path.clone(); path.push("%(title).90s.%(ext)s"); let mut cmd = Command::new("youtube-dl"); @@ -130,6 +138,6 @@ impl YoutubeDL { } Ok(process) => process, }; - pr.wait() + pr.wait_with_output() } }