Documentation
¶
Index ¶
- func AddHandler(re *regexp.Regexp, name string, fn HandlerFunc, namespaces ...string)
- func ContentType(r io.Reader) (string, map[string]string, error)
- func ExtensionByType(contentType string) string
- func FilterMetadata(entries map[string]gomedia.Metadata, o *Opts) []gomedia.Metadata
- func GetMetadata(parent context.Context, r io.Reader, contentType string, opts ...Option) (_ []gomedia.Metadata, err error)
- type HandlerFunc
- type NamedStream
- type Option
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHandler ¶
func AddHandler(re *regexp.Regexp, name string, fn HandlerFunc, namespaces ...string)
Add a metadata handler for a given regular expression, along with a short name identifying it (e.g. "ffmpeg", "tmdb", "artwork" - used to name its span, "metadata.Handler.<name>", so it's distinguishable from other handlers in a trace) and the namespaces (e.g. "exif", "tiff") of metadata it can produce. A caller that requests specific namespaces via WithNamespace will only run handlers registered for one of those namespaces.
func ContentType ¶
Type returns the MIME type of the given file, along with a map of any additional metadata that was extracted from the file. If the MIME type cannot be determined, an error is returned.
func ExtensionByType ¶
ExtensionByType returns the preferred extension for contentType, falling back to the first registered extension if no preferred extension matches.
func FilterMetadata ¶
FilterMetadata returns the entries whose namespace was requested via o (see WithNamespace), or every entry if no namespace was requested. Keys are of the form "namespace:name" and matched case-insensitively. This is a helper for handlers that build up a map of "namespace:name"-keyed metadata and need to apply the namespace filter passed to their HandlerFunc.
func GetMetadata ¶
func GetMetadata(parent context.Context, r io.Reader, contentType string, opts ...Option) (_ []gomedia.Metadata, err error)
GetMetadata runs every handler registered for contentType against r, concurrently, and returns the combined metadata from all of them. Metadata from handlers that succeed is always returned, even if other handlers for the same content type fail; a non-nil error is the joined errors from any failing handlers, and should be treated as a warning rather than a reason to discard the metadata that was returned alongside it. ctx is passed to every handler and checked before any work starts, but GetMetadata otherwise waits for all handlers to finish rather than returning early on cancellation.
Types ¶
type HandlerFunc ¶
HandlerFunc is a function that can be used to extract metadata from a given reader. The context can be used to cancel or time out long-running extraction. Opts carries the options passed to GetMetadata; in particular Opts.HasNamespace can be used to check whether a specific namespace (e.g. "artwork") was requested via WithNamespace, which handlers that do expensive work for a single namespace should use to opt in only when that namespace was explicitly requested. A handler that produces several namespaces can use FilterMetadata to return only the ones requested.
func GetHandlers ¶
func GetHandlers(contentType string) []HandlerFunc
GetHandlers returns all handlers registered for a given content type, or nil if no handler is registered for that content type.
type NamedStream ¶
type NamedStream interface {
// Name returns the name (path) of the stream, which can be used to
// determine the MIME type.
Name() string
}
type Option ¶ added in v1.9.3
func WithDuration ¶ added in v1.10.5
WithDuration sets the duration of the stream, when the caller knows it, such as from the stream's own metadata. The TMDB handler then only matches a movie whose runtime is within 10% of it.
func WithNamespace ¶ added in v1.9.3
Return only the metadata from the given namespaces.
func WithTracer ¶ added in v1.9.3
Set the otel tracer to use for metadata operations.
func WithYear ¶ added in v1.10.6
WithYear sets the year of the stream, such as its release year, when the caller knows it, such as from the stream's own metadata. The TMDB handler then matches a movie whose title is the stream's, and whose release year is the year, whatever its runtime. A year in the stream's name is used rather than it. Zero is no year.
type Opts ¶ added in v1.9.3
type Opts struct {
// contains filtered or unexported fields
}
func (*Opts) Duration ¶ added in v1.10.5
Duration returns the duration of the stream set via WithDuration, or zero when it isn't known
func (*Opts) HasNamespace ¶ added in v1.9.3
HasNamespace reports whether ns was requested via WithNamespace, case-insensitively. Handlers that do expensive work for a single namespace (e.g. artwork extraction) use this to opt in only when that namespace was explicitly requested, rather than whenever no namespace filter was given at all.
func (*Opts) IsText ¶ added in v1.10.4
IsText reports whether the stream is a text document with a type which isn't a text type, such as a playlist with an audio type. Media handlers, such as ffmpeg's, don't read it, as it isn't media.