From ad64c52c0d6abf64a157b473055c59417b6fa8b6 Mon Sep 17 00:00:00 2001 From: xob0t <32616886+xob0t@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:44:50 +0300 Subject: [PATCH] Add Option to Ignore Minor Writing Errors in Exiftool (-m Flag) This pull request introduces a new configuration option, IgnoreMinorErrors, that makes Exiftool ignore minor errors when writing metadata. This is done by passing the -m argument to Exiftool. More info on the `-m` flag https://exiftool.org/exiftool_pod.html#Processing-control --- exiftool.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/exiftool.go b/exiftool.go index fb9dc27..7aa944f 100644 --- a/exiftool.go +++ b/exiftool.go @@ -48,6 +48,7 @@ type Exiftool struct { cmd *exec.Cmd backupOriginal bool clearFieldsBeforeWriting bool + ignoreMinorErrors bool } // NewExiftool instanciates a new Exiftool with configuration functions. If anything went @@ -233,6 +234,13 @@ func (e *Exiftool) WriteMetadata(fileMetadata []FileMetadata) { } } + if e.ignoreMinorErrors { + if _, err := fmt.Fprintln(e.stdin, "-m"); err != nil { + fileMetadata[i].Err = err + continue + } + } + if e.clearFieldsBeforeWriting { if _, err := fmt.Fprintln(e.stdin, "-All="); err != nil { fileMetadata[i].Err = err @@ -418,6 +426,17 @@ func BackupOriginal() func(*Exiftool) error { } } +// IgnoreMinorErrors sets a `-m` arg to ignore minor exiftool errors when writing the file metadata +// Sample : +// +// e, err := NewExiftool(IgnoreMinorErrors()) +func IgnoreMinorErrors() func(*Exiftool) error { + return func(e *Exiftool) error { + e.ignoreMinorErrors = true + return nil + } +} + // ClearFieldsBeforeWriting will clear existing fields (e.g. tags) in the file before writing any // new tags // Sample :