Skip to content

Instantly share code, notes, and snippets.

@agorman
Created May 27, 2023 00:55
Show Gist options
  • Save agorman/6ef72d4be151326e39de980247c6ea46 to your computer and use it in GitHub Desktop.
Save agorman/6ef72d4be151326e39de980247c6ea46 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/barasher/go-exiftool"
)
func main() {
dir := os.Args[1]
et, err := exiftool.NewExiftool()
if err != nil {
panic(err)
}
go runExiftool(dir, et)
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
et.Close()
}
func runExiftool(dir string, et *exiftool.Exiftool) {
list, err := os.ReadDir(dir)
if err != nil {
panic(err)
}
for _, fi := range list {
fileInfos := et.ExtractMetadata(filepath.Join(dir, fi.Name()))
for _, fileInfo := range fileInfos {
if fileInfo.Err != nil {
fmt.Printf("Error concerning %v: %v\n", fileInfo.File, fileInfo.Err)
continue
}
for k, v := range fileInfo.Fields {
fmt.Printf("[%v] %v\n", k, v)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment