Small Rust scripts

Add exiftool

+50
+50
exiftool
··· 1 + #!/usr/bin/env -S cargo eval -- 2 + 3 + // cargo-deps: argh = "0.1", rexiv2 = "0.9.1" 4 + 5 + // This script requires gexiv2 6 + // Available through: 7 + // (Mac) brew install gexiv2 8 + 9 + use argh::FromArgs; 10 + use rexiv2::Metadata; 11 + 12 + #[derive(FromArgs)] 13 + #[argh(description = "Show and strip EXIF data from image files.")] 14 + struct App { 15 + #[argh(switch, description = "show EXIF info (just tags for now)")] 16 + show: bool, 17 + 18 + #[argh(switch, description = "strip EXIF info")] 19 + strip: bool, 20 + 21 + #[argh(positional, description = "path to file(s)")] 22 + paths: Vec<String>, 23 + } 24 + 25 + fn main() { 26 + let App { show, strip, paths } = argh::from_env(); 27 + 28 + if !show && !strip { 29 + eprintln!("Either --show or --strip is required"); 30 + return; 31 + } else if paths.is_empty() { 32 + eprintln!("Must provide at least one path"); 33 + return; 34 + } 35 + 36 + for path in paths { 37 + let meta = Metadata::new_from_path(&path).expect("should be able to open metadata"); 38 + 39 + if show { 40 + let tags = meta.get_exif_tags().expect("should be able to get tags"); 41 + println!("Available EXIF tags: {}", tags.join(", ")); 42 + } 43 + 44 + if strip { 45 + println!("Clearing EXIF data from: {:?}", path); 46 + meta.clear_exif(); 47 + meta.save_to_file(&path).expect("should be able to resave"); 48 + } 49 + } 50 + }