From 852e269b6deca6994621f53ee429e4996eae88b7 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 24 Feb 2019 11:24:32 +0200 Subject: [PATCH] Executable that removes images --- src/bin/id3-image-remove.rs | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/bin/id3-image-remove.rs diff --git a/src/bin/id3-image-remove.rs b/src/bin/id3-image-remove.rs new file mode 100644 index 0000000..30736a0 --- /dev/null +++ b/src/bin/id3-image-remove.rs @@ -0,0 +1,56 @@ +use std::process; +use std::io::{self, Write}; +use std::path::PathBuf; + +use structopt::StructOpt; +use id3_image::remove_images; + +#[derive(StructOpt, Debug)] +#[structopt(name = "id3-image-remove")] +struct Opt { + /// Verbose mode (-v, -vv, -vvv, etc.) + #[structopt(short = "v", long = "verbose", parse(from_occurrences))] + verbose: u8, + + /// Don't ask for confirmation before removing + #[structopt(long = "no-confirm")] + no_confirm: bool, + + /// Music file to remove images from + #[structopt(name = "music-file.mp3", required = true, parse(from_os_str))] + music_filename: PathBuf, +} + +fn main() { + let opt = Opt::from_args(); + + if !opt.no_confirm { + print_prompt(); + let mut input = String::new(); + while let Err(_) = io::stdin().read_line(&mut input) { + println!("Could not read your input, please try again."); + print_prompt(); + } + + let choice = input.to_lowercase().trim().chars().next().unwrap_or('y'); + if choice != 'y' { + if opt.verbose >= 1 { + println!("Exiting without removing images"); + } + process::exit(0); + } + } + + if let Err(e) = remove_images(&opt.music_filename) { + eprintln!("{}", e); + process::exit(1); + } + if opt.verbose >= 1 { + println!("Removed images on {:?}", opt.music_filename); + } +} + +fn print_prompt() { + print!("Are you sure you'd like to clear all embedded images? [Y/n] "); + io::stdout().flush().unwrap(); +}