# README
go-exiftool
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
- v1.1.0 : initial release
- v1.1.1
- v1.1.3
- add Mac & Windows support (thanks to @PROger4ever)
- increase errors readability (thanks to @PROger4ever)
- v1.2.0
- add stdout and stderr buffer configuration capabilities (thank to @asannikov)
- v1.3.0
- Add functionnal option to set ExifTool's
-charset
parameter (thank to @PROger4ever)
- Add functionnal option to set ExifTool's
- v1.3.1
- v1.3.2
- add Freebsd support (thanks to @ghyman1)
- v1.4.0
- "NoPrintConversion" functional option (thanks to Kjeldgaard)
- v1.5.0
- "ExtractEmbedded" functional option
- v1.6.0
- "ExtractAllBinaryMetadata" functional option
- v1.6.1
- "SetExiftoolBinaryPath" functional option : specify where to find exiftool binary (default : $path)
- v1.6.2
- Several improvements (thanks to Dale Hui)
- v1.7.0
- Add metadata writing capabilities (thanks to Dale Hui)
- v1.8.0
- Fix a bug that was blocking
go-exiftool
when a folder was provided. Folder metadata extraction will now return a new sentinel error (ErrNotFile). - Add a new sentinel error (
ErrBufferTooSmall
) that is returned whengo-exiftool
's buffer isn't big enough for a specifi file (countermeasure: initializego-exiftool
with theBuffer
option) - New option to specify a date format (
DateFormat
) (thanks to Andy Gorman) - New option to output format for GPS coordinates (
CoordFormat
) (thanks to Andy Gorman)
- Fix a bug that was blocking
- v1.9.0
- v1.10.0
# Functions
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")).
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()).
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)).
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")).
ClearFieldsBeforeWriting will clear existing fields (e.g.
CoordFormant defines the -coordFormat value to pass to Exiftool, see https://exiftool.org/ExifTool.html#CoordFormat Sample : e, err := NewExiftool(CoordFormant("%+f")).
DateFormant defines the -dateFormat value to pass to Exiftool, see https://exiftool.org/ExifTool.html#DateFormat Sample : e, err := NewExiftool(DateFormant("%s")).
EmptyFileMetadata creates an empty FileMetadata struct.
ExtractAllBinaryMetadata extracts all binary metadata (activates Exiftool's '-b' paramater) Sample : e, err := NewExiftool(ExtractAllBinaryMetadata()).
ExtractEmbedded extracts embedded metadata from files (activates Exiftool's '-ee' paramater) Sample : e, err := NewExiftool(ExtractEmbedded()).
NewExiftool instanciates a new Exiftool with configuration functions.
NoPrintConversion enables 'No print conversion' mode, see https://exiftool.org/exiftool_pod.html.
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")).
SetExiftoolBinaryPath sets exiftool's binary path.
# Variables
ErrBufferTooSmall is a sentinel error that is returned when the buffer used to store Exiftool's output is too small.
ErrKeyNotFound is a sentinel error used when a queried key does not exist.
ErrNotExist is a sentinel error for non existing file.
ErrNotFile is a sentinel error that is returned when a folder is provided instead of a rerular file.
WaitTimeout specifies the duration to wait for exiftool to exit when closing before timing out.
# Structs
Exiftool is the exiftool utility wrapper.
FileMetadata is a structure that represents an exiftool extraction.