Create output parent directory if it doesn't exists (#91)

This commit is contained in:
ByteDream 2022-12-27 20:49:53 +01:00
parent 2c3bd78fc1
commit c37e2495e1
2 changed files with 20 additions and 0 deletions

View file

@ -240,6 +240,12 @@ impl Execute for Download {
let mut stdout = std::io::stdout().lock();
download_segments(&ctx, &mut stdout, None, format.stream).await?;
} else {
// create parent directory if it does not exist
if let Some(parent) = path.parent() {
if !parent.exists() {
std::fs::create_dir_all(parent)?
}
}
let mut file = File::options().create(true).write(true).open(&path)?;
download_segments(&ctx, &mut file, None, format.stream).await?
}
@ -259,6 +265,13 @@ async fn download_ffmpeg(
let (input_presets, output_presets) =
FFmpegPreset::ffmpeg_presets(download.ffmpeg_preset.clone())?;
// create parent directory if it does not exist
if let Some(parent) = target.parent() {
if !parent.exists() {
std::fs::create_dir_all(parent)?
}
}
let mut ffmpeg = Command::new("ffmpeg")
.stdin(Stdio::piped())
.stdout(Stdio::null())