Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to Ignore Minor Writing Errors in Exiftool (-m Flag) #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions exiftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down