diff --git a/src/merge.rs b/src/merge.rs index eb9365d..472e74f 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -1,6 +1,6 @@ -use std::fs; use std::io::Result; use std::path::{Path, PathBuf}; +use std::{fs, io}; fn guess_video_path(path: &Path) -> Result { let mut largest_size = 0; @@ -23,7 +23,16 @@ fn guess_video_path(path: &Path) -> Result { pub fn merge_video_from_path(path: &Path) -> Result<()> { let video_path = guess_video_path(path)?; - let video_name = video_path.file_name().unwrap(); + let video_name = video_path.file_name().unwrap().to_str().unwrap(); + let video_extension = video_path.extension().unwrap(); + + let audio_name = format!("{}.m4a", &video_name[..video_name.len() - video_extension.len() - 1]); + let audio_path = video_path.parent().unwrap().join(audio_name); + if !audio_path.exists() { + return Err(io::Error::new(io::ErrorKind::NotFound, "Audio file does not exist")); + } + + println!("Merging video from {:?}", audio_path); println!("Merging video {:?}", video_name); Ok(())