meta

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package meta turns a media path into the descriptive metadata a UI shows: tags, cover art and the stream shape. Resolvers are pluggable, so a new source (a sidecar file, a music database, an FFprobe wrapper) is added without touching the chain or the player.

A resolver that fails is not fatal: the chain moves down the priority order and lets a cheaper answer stand in. That is why resolving a path almost always succeeds even for a file with no tags at all.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatch = errors.New("meta: no resolver could describe the path")

ErrNoMatch means every matching resolver failed. It is not returned for an untagged file, because the filename resolver always has an answer.

View Source
var ErrNoTags = errors.New("meta: no embedded tags")

ErrNoTags means the file parsed but carries no usable metadata. It is a deliberate step-aside, not a hard failure: a tagless file should fall down to the filename resolver instead of surfacing an empty title.

Functions

This section is empty.

Types

type Chain

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

Chain runs resolvers from highest priority to lowest and returns the first success. Failure is a signal to fall through, never an abort.

func Default

func Default() *Chain

Default is the chain a player uses unless the caller supplies another.

func NewChain

func NewChain(resolvers ...Resolver) *Chain

NewChain sorts a copy of resolvers by descending priority so Resolve never has to. Ties keep the caller's order, which makes a chain with two equal priorities predictable.

func (*Chain) Match

func (c *Chain) Match(string) bool

Match always reports true; the chain delegates matching to its members.

func (*Chain) Name

func (c *Chain) Name() string

Name identifies the chain in Meta.Source when a caller uses it directly.

func (*Chain) Priority

func (c *Chain) Priority() int

Priority is zero: a chain is a container for resolvers, not a peer of them.

func (*Chain) Resolve

func (c *Chain) Resolve(ctx context.Context, path string) (*Meta, error)

Resolve walks the chain in priority order and returns the first resolver that both matches and succeeds.

func (*Chain) Resolvers

func (c *Chain) Resolvers() []Resolver

Resolvers returns the chain's members in the order Resolve will try them.

type EmbeddedTags

type EmbeddedTags struct{}

EmbeddedTags reads the container's own metadata through dhowden/tag, which covers ID3 (MP3), Vorbis comments (Ogg/Opus/FLAC), MP4 atoms and DSF. One library covers every format we decode today.

func NewEmbeddedTags

func NewEmbeddedTags() *EmbeddedTags

NewEmbeddedTags returns the content-aware resolver.

func (*EmbeddedTags) Match

func (e *EmbeddedTags) Match(path string) bool

func (*EmbeddedTags) Name

func (e *EmbeddedTags) Name() string

func (*EmbeddedTags) Priority

func (e *EmbeddedTags) Priority() int

Priority puts container metadata above a filename guess, because it is cheaper and more direct than probing the stream.

func (*EmbeddedTags) Resolve

func (e *EmbeddedTags) Resolve(ctx context.Context, path string) (*Meta, error)

Resolve reads the tags and cover art. A parser error and a file with no tags both return an error, so the chain falls through either way.

type Filename

type Filename struct{}

Filename is the last-resort resolver: it always matches and turns the base name into a title. It exists so a UI never has to show an empty line, and it guarantees the chain can answer for a file no other resolver understands.

func NewFilename

func NewFilename() *Filename

NewFilename returns the fallback resolver.

func (*Filename) Match

func (f *Filename) Match(string) bool

Match always reports true. Requiring the file to exist here would make a queued but not-yet-created path fail to describe itself, which is not this resolver's job to police: the decoder reports a missing file.

func (*Filename) Name

func (f *Filename) Name() string

func (*Filename) Priority

func (f *Filename) Priority() int

Priority puts the filename below every content-aware resolver. Content wins when it is available; the name is a guess and should never outrank it.

func (*Filename) Resolve

func (f *Filename) Resolve(ctx context.Context, path string) (*Meta, error)

Resolve derives a title from the base name without the extension and a container hint from the extension. It never opens the file.

type Meta

type Meta struct {
	Path      string
	Container string
	Codec     string
	Stream    core.StreamInfo
	Tags      Tags

	// Source names the resolver that answered, for debugging and for a UI that
	// wants to show where the title came from.
	Source string
}

Meta is everything known about one media file. Stream is filled by whoever opened the file, not by a resolver, because only the decoder can report the true stream shape.

func Resolve

func Resolve(ctx context.Context, path string) (*Meta, error)

Resolve runs the default chain. It is the entry point for callers that have no reason to customise their resolvers.

type Resolver

type Resolver interface {
	Name() string
	Priority() int
	Match(path string) bool
	Resolve(ctx context.Context, path string) (*Meta, error)
}

Resolver is one source of metadata. Match is a cheap path-only check, so a resolver is never opened for a file it cannot handle.

type Tags

type Tags struct {
	Title       string
	Artist      string
	Album       string
	AlbumArtist string
	Track       int
	Disc        int
	Year        int

	// Cover is the raw image bytes and CoverMIME the type the source declared.
	// A UI hands both to an image decoder; the engine never touches them.
	Cover     []byte
	CoverMIME string
}

Tags is the human-facing part of the metadata. Zero values mean "the source did not provide this", which lets a UI decide what to show instead of guessing.

Jump to

Keyboard shortcuts

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