xmp

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package xmp provides XMP (Extensible Metadata Platform) encoding and decoding. XMP stores structured metadata as RDF/XML, organized into namespaced properties that can be simple strings, ordered or unordered arrays, localized alternatives, or nested structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterValueType added in v1.9.0

func RegisterValueType(key string, typ ValueType)

RegisterValueType registers or overrides the scalar type for a specific XMP key in "prefix:name" form.

Types

type Item

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

Item represents a single XMP metadata property and implements media.Metadata.

func NewAlt

func NewAlt(ns, prefix, name string, langValues ...[2]string) *Item

NewAlt creates an alternatives property. langValues is a sequence of [lang, value] pairs; use "x-default" as the lang for the canonical value.

func NewBag

func NewBag(ns, prefix, name string, values ...string) *Item

NewBag creates an unordered-set property.

func NewItem

func NewItem(ns, prefix, name, value string) *Item

NewItem creates a Simple property.

func NewItemLang

func NewItemLang(ns, prefix, name, lang, value string) *Item

NewItemLang creates a Simple property with an xml:lang qualifier.

func NewSeq

func NewSeq(ns, prefix, name string, values ...string) *Item

NewSeq creates an ordered-sequence property.

func NewStruct

func NewStruct(ns, prefix, name string, fields ...*Item) *Item

NewStruct creates a structured property with named fields.

func (*Item) Any

func (it *Item) Any() any

Any returns the property value as an appropriate Go type (implements media.Metadata):

  • Simple → string
  • Bag/Seq → []string
  • Alt → map[string]string (lang → value)
  • Struct → []*Item

func (*Item) AsBool added in v1.9.0

func (it *Item) AsBool() (bool, bool)

AsBool parses this Simple item as a boolean.

func (*Item) AsDuration added in v1.9.0

func (it *Item) AsDuration() (time.Duration, bool)

AsDuration parses this Simple item as a duration.

func (*Item) AsGPSCoord added in v1.9.0

func (it *Item) AsGPSCoord() (float64, bool)

AsGPSCoord parses this Simple item as a decimal degree coordinate.

func (*Item) AsRational added in v1.9.0

func (it *Item) AsRational() (Rational, bool)

AsRational parses this Simple item as a rational value.

func (*Item) AsTime added in v1.9.0

func (it *Item) AsTime() (time.Time, bool)

AsTime parses this Simple item as a time value.

func (*Item) Bytes

func (it *Item) Bytes() []byte

Bytes returns nil — XMP properties are text-only (implements media.Metadata).

func (*Item) Image

func (it *Item) Image() image.Image

Image returns nil (implements media.Metadata).

func (*Item) ItemKind

func (it *Item) ItemKind() Kind

ItemKind returns the value kind.

func (*Item) Items

func (it *Item) Items() []*Item

Items returns child items: members of Bag/Seq/Alt, or fields of a Struct.

func (*Item) Key

func (it *Item) Key() string

Key returns "prefix:name" (implements media.Metadata).

func (*Item) Lang

func (it *Item) Lang() string

Lang returns the xml:lang qualifier (non-empty for Simple items with a language tag and for Alt child items).

func (*Item) LocalName

func (it *Item) LocalName() string

LocalName returns the local property name.

func (*Item) MarshalJSON

func (it *Item) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Item) NS

func (it *Item) NS() string

NS returns the namespace URI.

func (*Item) Prefix

func (it *Item) Prefix() string

Prefix returns the preferred namespace prefix.

func (*Item) String

func (it *Item) String() string

String returns "key=value".

func (*Item) TypedValue added in v1.9.0

func (it *Item) TypedValue() any

TypedValue returns a typed scalar for Simple items where a registered type exists, and falls back to string (or the normal Any() for non-Simple kinds).

func (*Item) Value

func (it *Item) Value() string

Value returns the string value (implements media.Metadata). For Bag/Seq, values are joined with "; ". For Alt, the "x-default" value is returned, falling back to the first entry. For Struct, an empty string is returned.

func (*Item) ValueType added in v1.9.0

func (it *Item) ValueType() ValueType

ValueType returns the registered scalar type for this item's key.

type Kind

type Kind uint8

Kind describes the shape of an XMP property value.

const (
	Simple Kind = iota // a single string (optionally language-tagged)
	Bag                // unordered set of strings
	Seq                // ordered sequence of strings
	Alt                // localized alternatives keyed by xml:lang
	Struct             // nested record with named fields
)

func (Kind) String

func (k Kind) String() string

type Rational added in v1.9.0

type Rational struct {
	Numerator   int64
	Denominator int64
}

Rational is a signed rational number represented as numerator/denominator.

type ValueType added in v1.9.0

type ValueType uint8

ValueType describes the scalar value type expected for an XMP tag.

const (
	ValueTypeUnknown ValueType = iota
	ValueTypeTime
	ValueTypeDuration
	ValueTypeBoolean
	ValueTypeRational
	ValueTypeGPSCoord
)

func ValueTypeForKey added in v1.9.0

func ValueTypeForKey(key string) ValueType

ValueTypeForKey returns the registered scalar type for key.

type XMP

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

XMP holds a parsed XMP metadata document.

func FromMetadata added in v1.9.0

func FromMetadata(items []gomedia.Metadata, namespaces ...map[string]string) *XMP

FromMetadata creates an XMP document from a list of metadata entries. Keys in "prefix:name" form are split into namespace prefix and local name. Bare keys (without ':') are added as unqualified XMP properties.

Optionally, callers can provide one namespace map of prefix -> URI to define extra namespaces (for example "audio" or "video").

func New

func New() *XMP

New returns an empty XMP document.

func Parse

func Parse(data []byte) (*XMP, error)

Parse parses an XMP document from a byte slice.

func Read

func Read(r io.Reader) (*XMP, error)

Read parses an XMP document from r.

func (*XMP) Add

func (x *XMP) Add(items ...*Item)

Add appends items to the document.

func (*XMP) Delete

func (x *XMP) Delete(key string) int

Delete removes all items matching key and returns the count removed.

func (*XMP) First

func (x *XMP) First(keys ...string) *Item

First returns the first item with a non-empty value from the first matching key in the ordered list. This implements the priority-fallback pattern used when the same semantic field can appear under multiple namespace prefixes, e.g. x.First("photoshop:DateCreated", "exif:DateTimeOriginal", "xmp:CreateDate").

func (*XMP) Get

func (x *XMP) Get(key string) []*Item

Get returns all items whose key equals key. The key may be "prefix:name" or just the local name.

func (*XMP) Items

func (x *XMP) Items() []*Item

Items returns all top-level metadata properties.

func (*XMP) MarshalJSON

func (x *XMP) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*XMP) String

func (x *XMP) String() string

String returns the document encoded as an XMP/XML string.

func (*XMP) Write

func (x *XMP) Write(w io.Writer) error

Write encodes the XMP document as an XMP/RDF/XML packet to w.

Jump to

Keyboard shortcuts

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