metadata

package module
v0.0.0-...-ecdbfc7 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 12 Imported by: 0

README

Metadata

GoDoc

Metadata package for go. Currently Exif and XMP metadata in JPEG and MP4 files are supported.

go get github.com/tajtiattila/metadata

Documentation

Overview

Package metadata parses metadata in media files.

Currently metadata in JPEG (Exif and XMP) and MP4 (XMP) formats are supported.

Index

Constants

View Source
const (
	// date of original image (eg. scanned photo)
	DateTimeOriginal = "DateTimeOriginal"

	// original file creation date (eg. time of scan)
	DateTimeCreated = "DateTimeCreated"

	// Date/time of GPS fix (RFC3339, always UTC)
	GPSDateTime = "GPSDateTime"

	// latitude and longitude are signed floating point
	// values formatted with no exponent
	GPSLatitude  = "GPSLatitude"  // +north, -south
	GPSLongitude = "GPSLongitude" // +east, -west

	// Orientation (integer) 1..8, values are like exif
	Orientation = "Orientation"

	// XMP Rating (integer), -1: rejected, 0: unrated, 1..5: user rating
	Rating = "Rating"

	// recording equipment manufacturer and model name/number name
	Make  = "Make"
	Model = "Model"
)

Attribute names read from media files.

Date/time values are formatted as expected by the Time type of this package.

Variables

View Source
var ErrNoMeta = errors.New("metadata: no metadata found")

ErrNoMeta is returned by Parse and ParseAt when the file format was recognised but no metadata was found.

View Source
var ErrUnknownFormat = errors.New("metadata: unknown content format")

ErrUnknownFormat is returned by Parse and ParseAt when the file format is not understood by this package.

TimeAttrs lists time attributes recognised in Merge.

Functions

This section is empty.

Types

type GPSInfo

type GPSInfo struct {
	// Latitude and Longitude are the geographical location.
	// Positive latitude means north, positive longitude means east.
	Latitude  float64
	Longitude float64

	// Time is time of the GPS fix. Zero means undefined.
	Time time.Time
}

GPSInfo records GPS information.

type Metadata

type Metadata struct {
	// Date of original image (eg. scanned photo)
	DateTimeOriginal Time

	// Original file creation date (eg. time of scan)
	DateTimeCreated Time

	// GPS records GPS information.
	GPS struct {
		GPSInfo

		// Valid indicates if Latitude and Longitude
		// fields of GPSInfo are valid.
		Valid bool
	}

	// Orientation is the Exif orientation.
	// Possible values are based on the exif spec:
	//   0: undefined
	//   1: no rotation
	//   2: flip horizontal
	//   3: rotate 180°
	//   4: flip vertical
	//   5: transpose
	//   6: rotate 90°
	//   7: transverse
	//   8: rotate 270°
	Orientation int

	// Rating is the XMP rating. Possible values are:
	//  -1: rejected
	//   0: unrated or missing
	//   1..5: user rating
	Rating int

	// Recording equipment manufacturer and model name/number name
	Make, Model string

	// Attr holds metadata attributes as strings.
	Attr map[string]string
}

Metadata records file metadata.

func FromExif

func FromExif(x *exif.Exif) *Metadata

func FromExifBytes

func FromExifBytes(p []byte) (*Metadata, error)

func FromXMP

func FromXMP(x *xmp.Meta) *Metadata

FromXMP decodes XMP metadata.

func FromXMPBytes

func FromXMPBytes(p []byte) (*Metadata, error)

func Merge

func Merge(v ...*Metadata) *Metadata

Merge merges metadata from multiple sources.

func Parse

func Parse(r io.Reader) (*Metadata, error)

Parse parses metadata from r, and returns the metadata found and the first error encountered.

Metadata is parsed on a best effort basis. Valid values are always returned even when if non-fatal errors had been encountered by decoding the underlying formats.

If r is also an io.Seeker, then it is used to seek within r.

func ParseAt

func ParseAt(r io.ReaderAt) (*Metadata, error)

ParseAt parses metadata from r, and returns the metadata found and the first error encountered.

Metadata is parsed on a best effort basis. Valid values are always returned even when if non-fatal errors had been encountered by decoding the underlying formats.

func (*Metadata) Get

func (m *Metadata) Get(key string) string

Get returns a metadata attribute.

func (*Metadata) Set

func (m *Metadata) Set(key, value string)

Set sets a metadata attribute.

type Time

type Time struct {
	// Actual time value.
	// Its location is always time.Local if HasLoc is false.
	time.Time

	// Prec records the number of valid components of the parsed
	// value between 1 (year) and 7 (subsecond).
	// A Time with Prec == 0 is invalid.
	Prec int

	// HasLoc records whether the parsed value included a time zone.
	HasLoc bool
}

Time is like time.Time but records the precision (year, month, day, hour, minute, second or subsecond) of the parsed string and whether a time zone was specified.

Certain metadata formats has limited time representations:

MVHD in MP4 is unix(ish) time lacking time zone information.

Exif has a fixed standard time layout without a time zone. Certain tools can write time zone information to Exif date fields, but such Exif files are technically invalid.

XMP uses the time format understood by ParseTime, but may omit elements from the end of the string, reducing precision.

func ParseTime

func ParseTime(s string) Time

ParseTime parses a time string based on the RFC 3339 format, possibly truncated and with or without a time zone.

func (Time) In

func (t Time) In(loc *time.Location) Time

In returns t with the location information set to loc. If t.HasLoc was false, the time.Time of the result will have the same Date() and Clock() as before and its HasLoc set.

In panics if loc is nil.

func (Time) String

func (t Time) String() string

String formats t using the layout understood by ParseTime.

Directories

Path Synopsis
cmd
example
Package exif implements an JPEG/Exif decoder and encoder.
Package exif implements an JPEG/Exif decoder and encoder.
exiftag
Package exiftag defines constants used for TIFF and Exif files.
Package exiftag defines constants used for TIFF and Exif files.
Package jpeg implements a low-level a JPEG scanner.
Package jpeg implements a low-level a JPEG scanner.
Package orient provides the Orient function that applies an Exif orientation to an image.
Package orient provides the Orient function that applies an Exif orientation to an image.

Jump to

Keyboard shortcuts

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