exiftool

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

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

Usage

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
(...)

Changelog

Documentation

Index

Examples

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Exiftool

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

Exiftool is the exiftool utility wrapper

Example
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:

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

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 (FileMetadata) GetFloat

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

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

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

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.

Jump to

Keyboard shortcuts

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