Documentation
¶
Index ¶
- func AddHandler(re *regexp.Regexp, name string, fn HandlerFunc, namespaces ...string)
- func AddTextExtensionType(ext, contentType string) error
- 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 MarkdownWriter
- type NamedStream
- type Option
- func WithDuration(d time.Duration) Option
- func WithNamespace(ns ...string) Option
- func WithRange(offset, limit uint64) Option
- func WithTMDB(token string, clientopts ...client.ClientOpt) Option
- func WithTMDBEpisode(show, season, episode uint64) Option
- func WithTMDBMovie(id uint64) Option
- func WithTracer(tracer trace.Tracer) Option
- func WithYear(year int) 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 AddTextExtensionType ¶ added in v1.10.7
AddTextExtensionType registers the type of text with the extension, such as text/x-typescript for .ts, which refines content sniffed as plain text, as mime.AddExtensionType's does, but is never the type of content by its extension alone, so content which isn't text, such as an MPEG transport stream, has the type it otherwise has. The extension starts with a dot, and is matched without case.
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, or else the first extension of the type of text (see AddTextExtensionType).
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 MarkdownWriter ¶ added in v1.10.9
type MarkdownWriter struct {
// contains filtered or unexported fields
}
MarkdownWriter is written the content of a document as Markdown, by a handler of the "markdown" namespace, and keeps the part of it in the range set via WithRange. Once it has the part, a write returns an error, so the handler can stop, rather than converting the rest of the document. A handler returns the part with Metadata, which also takes the handler's error.
func NewMarkdownWriter ¶ added in v1.10.9
func NewMarkdownWriter(o *Opts) *MarkdownWriter
NewMarkdownWriter returns a writer which keeps the part of the Markdown in the range set via WithRange, or all of it
func (*MarkdownWriter) Metadata ¶ added in v1.10.9
func (w *MarkdownWriter) Metadata(err error) ([]gomedia.Metadata, error)
Metadata returns the part of the Markdown, and the handler's error, which is nil when it stopped as the writer had the part. The part is markdown:body; markdown:offset is the byte it starts at, when the range has an offset, which is moved forward to the start of a character; and markdown:next is the offset of the next part, when there's more. Returns an error when the offset is beyond the end of the Markdown.
func (*MarkdownWriter) Write ¶ added in v1.10.9
func (w *MarkdownWriter) Write(data []byte) (int, error)
Write keeps the part of the data in the range. It returns an error once it has the part, and there's more of the Markdown, so the handler can stop.
func (*MarkdownWriter) WriteString ¶ added in v1.10.9
func (w *MarkdownWriter) WriteString(s string) (int, error)
WriteString keeps the part of the string in the range, as Write does
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 WithRange ¶ added in v1.10.9
WithRange sets the part of a document's Markdown which a handler of the markdown namespace returns: from the byte offset, and at most limit bytes, so a long document is read a part at a time. A limit of zero is all of it from the offset, and otherwise holds a whole character. See MarkdownWriter.
func WithTMDBEpisode ¶ added in v1.10.9
WithTMDBEpisode sets the TMDB identifier of the stream's show, and its season and episode, when the caller knows them, such as from an earlier match. The TMDB handler then gets the episode by them, rather than searching for the show and matching the results. Season zero is a show's specials. It replaces a movie set via WithTMDBMovie.
func WithTMDBMovie ¶ added in v1.10.9
WithTMDBMovie sets the TMDB identifier of the stream's movie, when the caller knows it, such as from an earlier match. The TMDB handler then gets the movie by it, rather than searching for the stream's name and matching the results, which is fewer requests, and is sure to be the same movie. It replaces an episode set via WithTMDBEpisode.
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.
func (*Opts) TMDB ¶ added in v1.9.3
TMDB returns the TMDB client set via WithTMDB, or nil if none was set. Handlers that need to query TMDB use this to opt out (return nil, nil) when no client is configured, rather than erroring.
func (*Opts) TMDBEpisode ¶ added in v1.10.9
TMDBEpisode returns the TMDB identifier of the stream's show, and its season and episode, set via WithTMDBEpisode, or zeros