diff --git a/src/main.rs b/src/main.rs index 8c732e6..8be4e1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,8 +36,6 @@ struct Args { #[tokio::main] async fn main() -> anyhow::Result<()> { - eprintln!("-> Initialize env_logger"); - let env = Env::default() . filter_or("LOG_LEVEL", "error") . write_style_or("LOG_STYLE", "always"); @@ -51,11 +49,11 @@ async fn main() -> anyhow::Result<()> { let name = args.name.as_path(); if name.file_name() != Some(OsStr::new(name)) { - return Err(anyhow!("Name must not contain a path")); + Err(anyhow!("Name must not contain a path"))? } if name.extension() != Some(OsStr::new("mp4")) { - return Err(anyhow!("Only filenames with .mp4 extension are allowed")); + Err(anyhow!("Only filenames with .mp4 extension are allowed"))? } let concurrency = args.concurrency.unwrap_or(10); @@ -85,8 +83,8 @@ async fn main() -> anyhow::Result<()> { client.stop(); info!("Call ffmpeg to join ts files to single mp4..."); - let status = ffmpeg(&name, download.index_uri()).await?; + let status = ffmpeg(&name, download.index_uri()).await?; debug!("ffmpeg status: {}", status); info!("Leave and remove temporary download dir..."); diff --git a/src/process.rs b/src/process.rs index 88ff02b..667631e 100644 --- a/src/process.rs +++ b/src/process.rs @@ -3,7 +3,7 @@ use std::{ set_current_dir}, ffi::OsString, io::ErrorKind, - path::Path, + path::{Path, PathBuf}, process::{Command, ExitStatus} }; @@ -13,7 +13,7 @@ use shellwords::escape; use tokio::fs::{create_dir, remove_dir_all}; use which::which; -use log::{log, Level}; +use log::debug; pub(super) async fn enter_download_dir(name: &dyn AsRef) -> anyhow::Result { @@ -29,15 +29,18 @@ pub(super) async fn enter_download_dir(name: &dyn AsRef) -> anyhow::Result return Err(anyhow!("Unable to create directory at {:?}", basename)); } } - set_current_dir(basename)?; + let basename = PathBuf::from(basename) + . canonicalize()?; + + set_current_dir(basename.clone())?; Ok(basename.into()) } pub(super) async fn remove_download_dir(name: &dyn AsRef) -> anyhow::Result<()> { - let name = name.as_ref().parent() + let parent = name.as_ref().parent() . ok_or(anyhow!("Failed to get parent of download dir"))?; - set_current_dir(name)?; + set_current_dir(parent)?; remove_dir_all(name).await?; Ok(()) @@ -59,15 +62,14 @@ pub(super) async fn ffmpeg(name: &dyn AsRef, uri: &Uri) -> anyhow::Result< let index = Path::new(index).canonicalize()?; let index = index.as_os_str(); - log!(Level::Debug, "ffmpeg: {:?}", ffmpeg); - log!(Level::Debug, "index: {:?}", index); - log!(Level::Debug, "outfile: {:?}", outfile); + debug!("ffmpeg: {:?}", ffmpeg); + debug!("index: {:?}", index); + debug!("outfile: {:?}", outfile); - log!( Level::Debug - , "execute: {} -allowed_extensions ALL -i {} -c copy {}" - , escape(ffmpeg.try_into()?) - , escape(index.try_into()?) - , escape(outfile.try_into()?) ); + debug!("execute: {} -allowed_extensions ALL -i {} -c copy {}" + , escape(ffmpeg.try_into()?) + , escape(index.try_into()?) + , escape(outfile.try_into()?) ); let mut child = Command::new(ffmpeg) . arg("-allowed_extensions") . arg("ALL")