Skip to content

Commit f4f902f

Browse files
authored
Add Option to Ignore Minor Writing Errors in Exiftool (-m Flag) (#72)
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
1 parent b9a9a53 commit f4f902f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

exiftool.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Exiftool struct {
4848
cmd *exec.Cmd
4949
backupOriginal bool
5050
clearFieldsBeforeWriting bool
51+
ignoreMinorErrors bool
5152
}
5253

5354
// NewExiftool instanciates a new Exiftool with configuration functions. If anything went
@@ -233,6 +234,13 @@ func (e *Exiftool) WriteMetadata(fileMetadata []FileMetadata) {
233234
}
234235
}
235236

237+
if e.ignoreMinorErrors {
238+
if _, err := fmt.Fprintln(e.stdin, "-m"); err != nil {
239+
fileMetadata[i].Err = err
240+
continue
241+
}
242+
}
243+
236244
if e.clearFieldsBeforeWriting {
237245
if _, err := fmt.Fprintln(e.stdin, "-All="); err != nil {
238246
fileMetadata[i].Err = err
@@ -418,6 +426,17 @@ func BackupOriginal() func(*Exiftool) error {
418426
}
419427
}
420428

429+
// IgnoreMinorErrors sets a `-m` arg to ignore minor exiftool errors when writing the file metadata
430+
// Sample :
431+
//
432+
// e, err := NewExiftool(IgnoreMinorErrors())
433+
func IgnoreMinorErrors() func(*Exiftool) error {
434+
return func(e *Exiftool) error {
435+
e.ignoreMinorErrors = true
436+
return nil
437+
}
438+
}
439+
421440
// ClearFieldsBeforeWriting will clear existing fields (e.g. tags) in the file before writing any
422441
// new tags
423442
// Sample :

0 commit comments

Comments
 (0)