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