-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmloc.go
81 lines (66 loc) · 2.13 KB
/
rmloc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/fatih/color"
"github.com/google/subcommands"
)
type rmlocCmd struct {
suffix bool
outDir string
verbose bool
verbose2 bool
appConfig AppConfig
}
func (*rmlocCmd) Name() string { return "rmloc" }
func (*rmlocCmd) Synopsis() string { return "Remove all GPS metadata." }
func (*rmlocCmd) Usage() string {
return `rmloc [-s] [-d out_dir] [-v|-vv] file1.jpg [file2.nef ...]:
Removes all GPS data from the given files.
`
}
func (p *rmlocCmd) SetFlags(f *flag.FlagSet) {
f.BoolVar(&p.suffix, "s", false, "Write modified images to new files named with the suffix _noGPS, rather than to the originals.")
f.StringVar(&p.outDir, "d", "", "Write modified images to this directory.")
f.BoolVar(&p.verbose, "v", false, "Print full exiftool output for each image.")
f.BoolVar(&p.verbose2, "vv", false, "Print exiftool commands and full exiftool output.")
}
func (p *rmlocCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
if p.verbose2 {
p.verbose = true
}
if len(f.Args()) == 0 {
f.Usage()
return subcommands.ExitUsageError
}
p.appConfig = AppConfigFromCtx(ctx)
exiftoolArgs := []string{"-gps*="}
if p.outDir != "" && p.suffix {
exiftoolArgs = append(exiftoolArgs, "-o", fmt.Sprintf("%s%s%%f_noGPS.%%e", p.outDir, string(os.PathSeparator)))
} else if p.suffix {
exiftoolArgs = append(exiftoolArgs, "-o", "%d%f_noGPS.%e")
} else if p.outDir != "" {
exiftoolArgs = append(exiftoolArgs, "-o", fmt.Sprintf("%s%s", p.outDir, string(os.PathSeparator)))
}
successes, failures := ExiftoolProcess(
ctx,
exiftoolArgs,
f.Args(),
p.appConfig,
p.verbose,
p.verbose2,
)
boldWhitePrintf := color.New(color.Bold, color.FgWhite).PrintfFunc()
boldRedPrintf := color.New(color.Bold, color.FgRed).PrintfFunc()
boldWhitePrintf("\nrmloc: successfully processed %d images.\n", len(successes))
if len(failures) != 0 {
boldRedPrintf("Errors:\n")
for filename, err := range failures {
fmt.Printf("- %s %s\n", color.MagentaString("%s:", filename), err)
}
return subcommands.ExitFailure
}
return subcommands.ExitSuccess
}