feat: argparse and dry-run.

This commit is contained in:
2026-01-04 01:46:39 +08:00
parent 21e0e96841
commit 5ce56bda36
10 changed files with 656 additions and 90 deletions
+46 -9
View File
@@ -1,15 +1,52 @@
mod audio_converter;
mod dry_run;
mod ffmpeg;
mod file_finder;
mod merge;
mod video_merger;
use std::env;
use clap::Parser;
use std::io::Result;
use std::path::PathBuf;
fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
let merge_path = if args.len() > 1 {
PathBuf::from(args[1].as_str())
} else {
PathBuf::from(".")
};
merge::merge_video_from_path(&merge_path)
#[derive(Parser)]
#[command(name = "bilibili-merge")]
#[command(about = "Merge bilibili downloaded videos with audio")]
#[command(long_about = "Merge bilibili downloaded videos with audio.
This tool automatically:
1. Finds the largest video file in the specified directory (by file size)
2. Looks for the corresponding audio file (.m4a) with the same base name
3. Converts the audio to AAC format
4. Merges the video and audio into a single file
The original video file will be renamed to 'original.<extension>' as a backup.
The merged file will be saved as '<original_name>.mp4' regardless of the input format.")]
struct Args {
/// Path to the directory containing video and audio files
///
/// The tool will automatically select the largest file (by size) in this directory
/// as the video file to merge. Make sure only one video file exists, or the largest
/// one will be selected.
#[arg(default_value = ".")]
path: PathBuf,
/// Dry run mode: show what would be done without actually doing it
///
/// In dry-run mode, the tool will output a shell script showing all operations
/// that would be performed. You can copy and execute this script manually if needed.
#[arg(short = 'n', long = "dry-run")]
dry_run: bool,
/// Force overwrite existing files
///
/// By default, the tool will not overwrite existing files. Use this flag to
/// force overwrite if the output file already exists.
#[arg(short = 'f', long = "force")]
force: bool,
}
fn main() -> Result<()> {
let args = Args::parse();
merge::merge_video_from_path(&args.path, args.dry_run, args.force)
}