exiftool

package module
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: GPL-3.0 Imports: 12 Imported by: 67

README

go-exiftool

Mentioned in Awesome Go Build Status go report card GoDoc codecov

go-exiftool is a golang library that wraps ExifTool.

ExifTool's purpose is to extract and update as much metadata as possible (EXIF, IPTC, XMP, GPS, ...) from a lots of differents file types (Office documents, pictures, movies, PDF, ...).

go-exiftool uses ExifTool's stay_open feature to optimize performance.

Requirements

go-exiftool needs ExifTool to be installed.

  • On Debian : sudo apt-get install exiftool

By default, go-exiftool binary will look for exiftool binary in $PATH, but another location can be specified (see SetExiftoolBinaryPath functional option).

Usage

Metadata extraction
et, err := exiftool.NewExiftool()
if err != nil {
    fmt.Printf("Error when intializing: %v\n", err)
    return
}
defer et.Close()

fileInfos := et.ExtractMetadata("testdata/20190404_131804.jpg")

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)
    }
}

Output :

[FOV] 69.4 deg
[Orientation] Rotate 90 CW
[ColorSpace] sRGB
[Compression] JPEG (old-style)
[YCbCrSubSampling] YCbCr4:2:2 (2 1)
[Aperture] 1.7
[ColorComponents] 3
[SubSecCreateDate] 2019:04:04 13:18:03.0937
[FileSize] 26 kB
[FileAccessDate] 2019:05:17 22:44:26+02:00
[DateTimeOriginal] 2019:04:04 13:18:03
[CreateDate] 2019:04:04 13:18:03
(...)
Metadata update

See example function ExampleExiftool_Write in exiftool_sample_test.go

Changelog

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBufferTooSmall = errors.New("exiftool's buffer too small (see Buffer init option)")

ErrBufferTooSmall is a sentinel error that is returned when the buffer used to store Exiftool's output is too small.

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is a sentinel error used when a queried key does not exist

View Source
var ErrNotExist = errors.New("file does not exist")

ErrNotExist is a sentinel error for non existing file

View Source
var ErrNotFile = errors.New("can't extract metadata from folder")

ErrNotFile is a sentinel error that is returned when a folder is provided instead of a rerular file

View Source
var WaitTimeout = time.Second

WaitTimeout specifies the duration to wait for exiftool to exit when closing before timing out

Functions

func Api added in v1.9.0

func Api(apiValue string) func(*Exiftool) error

Api defines an -api value to pass to Exiftool, see https://www.exiftool.org/exiftool_pod.html#Advanced-options Sample :

e, err := NewExiftool(Api("QuickTimeUTC"))

func BackupOriginal added in v1.7.0

func BackupOriginal() func(*Exiftool) error

BackupOriginal backs up the original file when writing the file metadata instead of overwriting the original (activates Exiftool's '-overwrite_original' parameter) Sample :

e, err := NewExiftool(BackupOriginal())

func Buffer added in v1.1.2

func Buffer(buf []byte, max int) func(*Exiftool) error

Buffer defines the buffer used to read from stdout and stderr, see https://golang.org/pkg/bufio/#Scanner.Buffer Sample :

buf := make([]byte, 128*1000)
e, err := NewExiftool(Buffer(buf, 64*1000))

func Charset added in v1.1.2

func Charset(charset string) func(*Exiftool) error

Charset defines the -charset value to pass to Exiftool, see https://exiftool.org/faq.html#Q10 and https://exiftool.org/faq.html#Q18 Sample :

e, err := NewExiftool(Charset("filename=utf8"))

func ClearFieldsBeforeWriting added in v1.7.0

func ClearFieldsBeforeWriting() func(*Exiftool) error

ClearFieldsBeforeWriting will clear existing fields (e.g. tags) in the file before writing any new tags Sample :

e, err := NewExiftool(ClearFieldsBeforeWriting())

func CoordFormant added in v1.8.0

func CoordFormant(format string) func(*Exiftool) error

CoordFormant defines the -coordFormat value to pass to Exiftool, see https://exiftool.org/ExifTool.html#CoordFormat Sample :

e, err := NewExiftool(CoordFormant("%+f"))

func DateFormant added in v1.8.0

func DateFormant(format string) func(*Exiftool) error

DateFormant defines the -dateFormat value to pass to Exiftool, see https://exiftool.org/ExifTool.html#DateFormat Sample :

e, err := NewExiftool(DateFormant("%s"))

func ExtractAllBinaryMetadata added in v1.6.0

func ExtractAllBinaryMetadata() func(*Exiftool) error

ExtractAllBinaryMetadata extracts all binary metadata (activates Exiftool's '-b' paramater) Sample :

e, err := NewExiftool(ExtractAllBinaryMetadata())

func ExtractEmbedded added in v1.5.0

func ExtractEmbedded() func(*Exiftool) error

ExtractEmbedded extracts embedded metadata from files (activates Exiftool's '-ee' paramater) Sample :

e, err := NewExiftool(ExtractEmbedded())

func NoPrintConversion added in v1.4.0

func NoPrintConversion() func(*Exiftool) error

NoPrintConversion enables 'No print conversion' mode, see https://exiftool.org/exiftool_pod.html. Sample :

e, err := NewExiftool(NoPrintConversion())

func PrintGroupNames added in v1.10.0

func PrintGroupNames(groupNumbers string) func(*Exiftool) error

PrintGroupNames prints the group names for each tag based on the pass group number(s), (activates Exiftool's '-G' paramater) Sample :

e, err := NewExiftool(PrintGroupNames("0"))

func SetExiftoolBinaryPath added in v1.6.1

func SetExiftoolBinaryPath(p string) func(*Exiftool) error

SetExiftoolBinaryPath sets exiftool's binary path. When not specified, the binary will have to be in $PATH Sample :

e, err := NewExiftool(SetExiftoolBinaryPath("/usr/bin/exiftool"))

Types

type Exiftool

type Exiftool struct {
	// contains filtered or unexported fields
}

Exiftool is the exiftool utility wrapper

func NewExiftool

func NewExiftool(opts ...func(*Exiftool) error) (*Exiftool, error)

NewExiftool instanciates a new Exiftool with configuration functions. If anything went wrong, a non empty error will be returned.

func (*Exiftool) Close

func (e *Exiftool) Close() error

Close closes exiftool. If anything went wrong, a non empty error will be returned

func (*Exiftool) ExtractMetadata

func (e *Exiftool) ExtractMetadata(files ...string) []FileMetadata

ExtractMetadata extracts metadata from files

func (*Exiftool) WriteMetadata added in v1.7.0

func (e *Exiftool) WriteMetadata(fileMetadata []FileMetadata)

WriteMetadata writes the given metadata for each file. Any errors will be saved to FileMetadata.Err Note: If you're reusing an existing FileMetadata instance,

you should nil the Err before passing it to WriteMetadata

type FileMetadata

type FileMetadata struct {
	File   string
	Fields map[string]interface{}
	Err    error
}

FileMetadata is a structure that represents an exiftool extraction. File contains the filename that had to be extracted. If anything went wrong, Err will not be nil. Fields stores extracted fields.

func EmptyFileMetadata added in v1.7.0

func EmptyFileMetadata() FileMetadata

EmptyFileMetadata creates an empty FileMetadata struct

func (FileMetadata) Clear added in v1.7.0

func (fm FileMetadata) Clear(k string)

Clear removes value for a specific metadata field

func (FileMetadata) ClearAll added in v1.7.0

func (fm FileMetadata) ClearAll()

ClearAll removes all medatadata

func (FileMetadata) GetFloat added in v1.1.1

func (fm FileMetadata) GetFloat(k string) (float64, error)

GetFloat returns a field value as float64 and an error if one occurred. KeyNotFoundError will be returned if the key can't be found.

func (FileMetadata) GetInt added in v1.1.1

func (fm FileMetadata) GetInt(k string) (int64, error)

GetInt returns a field value as int64 and an error if one occurred. KeyNotFoundError will be returned if the key can't be found, ParseError if a parsing error occurs.

func (FileMetadata) GetString added in v1.1.1

func (fm FileMetadata) GetString(k string) (string, error)

GetString returns a field value as string and an error if one occurred. KeyNotFoundError will be returned if the key can't be found

func (FileMetadata) GetStrings added in v1.1.1

func (fm FileMetadata) GetStrings(k string) ([]string, error)

GetStrings returns a field value as []string and an error if one occurred. KeyNotFoundError will be returned if the key can't be found.

func (FileMetadata) SetFloat added in v1.7.0

func (fm FileMetadata) SetFloat(k string, v float64)

SetFloat sets a float value for a specific field

func (FileMetadata) SetInt added in v1.7.0

func (fm FileMetadata) SetInt(k string, v int64)

SetInt sets a int value for a specific field

func (FileMetadata) SetString added in v1.7.0

func (fm FileMetadata) SetString(k string, v string)

SetString sets a string value for a specific field

func (FileMetadata) SetStrings added in v1.7.0

func (fm FileMetadata) SetStrings(k string, v []string)

SetStrings sets a []String value for a specific field

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL