-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmeta.go
74 lines (62 loc) · 2 KB
/
meta.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
package main
import (
"bufio"
"bytes"
"log"
"path/filepath"
"github.com/ncruces/go-exiftool"
)
var exifserver *exiftool.Server
func setupExifTool() (s *exiftool.Server, err error) {
exifserver, err = exiftool.NewServer("-ignoreMinorErrors", "-quiet", "-quiet")
return exifserver, err
}
func getMetaHTML(path string) ([]byte, error) {
log.Print("exiftool (get meta)...")
return exifserver.Command("-htmlFormat", "-groupHeadings", "-long", "-fixBase", path)
}
func fixMetaDNG(orig, dest, name string) error {
opts := []string{"-tagsFromFile", orig, "-fixBase",
"-MakerNotes", "-OriginalRawFileName-=" + filepath.Base(orig)}
if name != "" {
opts = append(opts, "-OriginalRawFileName="+filepath.Base(name))
}
opts = append(opts, "-overwrite_original", dest)
log.Print("exiftool (fix dng)...")
_, err := exifserver.Command(opts...)
return err
}
func fixMetaJPEG(orig, dest string) error {
opts := []string{"-tagsFromFile", orig, "-fixBase",
"-CommonIFD0", "-ExifIFD:all", "-GPS:all", // https://exiftool.org/forum/index.php?topic=8378.msg43043#msg43043
"-IPTC:all", "-XMP-dc:all", "-XMP-dc:Format=",
"-fast", "-overwrite_original", dest}
log.Print("exiftool (fix jpeg)...")
_, err := exifserver.Command(opts...)
return err
}
func dngHasEdits(path string) bool {
log.Print("exiftool (has edits?)...")
out, err := exifserver.Command("-XMP-photoshop:all", path)
return err == nil && len(out) > 0
}
func cameraMatchingWhiteBalance(path string) string {
log.Print("exiftool (get camera matching white balance)...")
out, err := exifserver.Command("-duplicates", "-short3", "-fast", "-ExifIFD:WhiteBalance", "-MakerNotes:WhiteBalance", path)
if err != nil {
return ""
}
for scan := bufio.NewScanner(bytes.NewReader(out)); scan.Scan(); {
switch wb := scan.Text(); wb {
case "Auto", "Daylight", "Cloudy", "Shade", "Tungsten", "Fluorescent", "Flash":
return wb
case "Sunny":
return "Daylight"
case "Overcast":
return "Cloudy"
case "Incandescent":
return "Tungsten"
}
}
return "As Shot"
}