feat: argparse and dry-run.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
use std::io::Result;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn find_largest_video_file(path: &Path) -> Result<PathBuf> {
|
||||
let mut largest_size = 0;
|
||||
let mut largest_file = PathBuf::from(path);
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let entry_path = entry?.path().canonicalize()?;
|
||||
if entry_path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let size = entry_path.metadata()?.len();
|
||||
if size >= largest_size {
|
||||
largest_size = size;
|
||||
largest_file = entry_path.into();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(largest_file)
|
||||
}
|
||||
|
||||
pub fn find_audio_file(video_path: &Path) -> Result<PathBuf> {
|
||||
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(std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
format!("Audio file does not exist: {}", audio_path.display())
|
||||
));
|
||||
}
|
||||
|
||||
Ok(audio_path)
|
||||
}
|
||||
Reference in New Issue
Block a user