use crate::audio_converter::convert_audio_to_aac; use crate::dry_run::{print_shell_script_header, ShellScript}; use crate::file_finder::{find_audio_file, find_largest_video_file}; use crate::video_merger::merge_video_and_audio; use std::io::Result; use std::path::Path; pub fn merge_video_from_path(path: &Path, dry_run: bool, overwrite: bool) -> Result<()> { if dry_run { println!("=== DRY RUN MODE ==="); println!("This is a dry run. Below is the shell script that would be executed:"); println!(); print_shell_script_header(); } println!("Step 1: Searching for video file in: {}", path.display()); let video_path = find_largest_video_file(path)?; println!("Found video file: {}", video_path.display()); if dry_run { let mut script = ShellScript::new(); script.add_comment("File paths"); script.add_variable("VIDEO_FILE", &video_path); crate::dry_run::print_shell_script(&script); } println!("Step 2: Looking for corresponding audio file..."); let audio_path = find_audio_file(&video_path)?; println!("Found audio file: {}", audio_path.display()); if dry_run { let mut script = ShellScript::new(); script.add_variable("AUDIO_FILE", &audio_path); crate::dry_run::print_shell_script(&script); } println!(); println!("Step 3: Converting audio to AAC format..."); let aac_path = convert_audio_to_aac(&audio_path, dry_run, overwrite)?; println!(); println!("Step 4: Merging video and audio..."); let output_path = merge_video_and_audio(&video_path, &aac_path, dry_run, overwrite)?; if dry_run { println!(); println!("=== DRY RUN COMPLETE ==="); println!("To actually perform these operations, run without -n flag."); println!("You can also copy the shell script above and execute it manually."); } else { println!(); println!("=== MERGE COMPLETE ==="); println!("Video file: {}", output_path.display()); } Ok(()) }