tag

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 6 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 tag describes audio metadata, including normalized fields, native tags, embedded artwork, and snapshots delivered during playback.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNilContext = errors.New("tag: nil context")

ErrNilContext reports that opening artwork requires a non-nil context.

Functions

This section is empty.

Types

type Artwork

type Artwork struct {
	MIMEType    string
	Role        ArtworkRole
	Description string
	Size        int64 // Encoded byte count, or -1 when unknown.
	// contains filtered or unexported fields
}

Artwork gives access to an original encoded image.

func NewArtwork

func NewArtwork(mime string, role ArtworkRole, description string, size int64, open func(context.Context) (io.ReadCloser, error)) Artwork

NewArtwork describes an encoded image. The open function must return a fresh reader positioned at the start of the same image on each call.

func (Artwork) Open

func (a Artwork) Open(ctx context.Context) (io.ReadCloser, error)

Open returns a reader positioned at the start of the original encoded image. Each call has its own cursor. Close the reader after use. A nil context returns ErrNilContext.

Artwork retained by a forward-only decoder stays readable after the decoder and its input close. For file-backed artwork, keep the input open until the returned reader is closed.

Example
// A stream decoder keeps the encoded image after reading its tag.
image := []byte{0xff, 0xd8, 0xff, 0xd9}
cover := NewArtwork(
	"image/jpeg",
	ArtworkFront,
	"Front cover",
	int64(len(image)),
	func(context.Context) (io.ReadCloser, error) {
		return io.NopCloser(bytes.NewReader(image)), nil
	},
)
reader, err := cover.Open(context.Background())
if err != nil {
	panic(err)
}
defer func() { _ = reader.Close() }()
encoded, err := io.ReadAll(reader)
if err != nil {
	panic(err)
}
fmt.Printf("%s %x\n", cover.MIMEType, encoded)
Output:
image/jpeg ffd8ffd9

type ArtworkRole

type ArtworkRole uint8

ArtworkRole identifies how the source classified an image.

const (
	ArtworkOther ArtworkRole = iota // Unspecified or different role.
	ArtworkFront                    // Front cover.
	ArtworkBack                     // Back cover.
)

type Key

type Key int

Key identifies a normalized metadata field.

const (
	Unknown      Key = iota // Native field without a canonical mapping.
	Title                   // Selected recording title.
	Artists                 // Performers credited on the recording.
	Album                   // Album containing the recording.
	AlbumArtists            // Performers credited for the album.
	NowPlaying              // Current title supplied by a live stream.
	Station                 // Station or service carrying the stream.
	Genres                  // Musical styles listed for the recording.
	Date                    // Release or recording date supplied by the source.
	TrackNumber             // Positive decimal position within a disc or release.
	DiscNumber              // Positive decimal position within a multi-disc release.
)

type Metadata

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

Metadata is a snapshot of the tags and artwork associated with audio. Its zero value represents an audio source with no reported metadata.

Example
// A decoder supplies source fields with their canonical keys.
fields := []SourceTag{
	{
		Namespace: "vorbis",
		Name:      "TITLE",
		Key:       Title,
		Values:    []string{"Night Flight"},
	},
}
metadata := NewMetadata(fields, nil)
fmt.Println(metadata.Title())
fmt.Println(metadata.SourceTags()[0].Name)
Output:
Night Flight
TITLE

func NewMetadata

func NewMetadata(fields []SourceTag, artwork []Artwork) Metadata

NewMetadata builds a snapshot from the decoder's fields and artwork.

func (Metadata) Album

func (m Metadata) Album() string

Album returns the album, or an empty string.

func (Metadata) AlbumArtists

func (m Metadata) AlbumArtists() []string

AlbumArtists returns the credited album artists in source order.

func (Metadata) Artists

func (m Metadata) Artists() []string

Artists returns the performers in source order.

func (Metadata) Artwork

func (m Metadata) Artwork() []Artwork

Artwork returns descriptions of embedded images in source order.

func (Metadata) Date

func (m Metadata) Date() string

Date returns the tagged release or recording date, or an empty string.

func (Metadata) DiscNumber

func (m Metadata) DiscNumber() string

DiscNumber returns the positive decimal disc number, or an empty string.

func (Metadata) First

func (m Metadata) First(key Key) string

First returns the first nonempty value for key, or an empty string.

func (Metadata) Genres

func (m Metadata) Genres() []string

Genres returns the musical styles in source order.

func (Metadata) SourceTags

func (m Metadata) SourceTags() []SourceTag

SourceTags returns copies of all parsed text tags, including empty values.

func (Metadata) Title

func (m Metadata) Title() string

Title returns the title, or an empty string.

func (Metadata) TrackNumber

func (m Metadata) TrackNumber() string

TrackNumber returns the positive decimal track number, or an empty string.

func (Metadata) Values

func (m Metadata) Values(key Key) []string

Values returns nonempty values at the most specific scope, in source order. The returned slice belongs to the caller.

type Scope

type Scope uint8

Scope identifies the part of the source a tag describes.

const (
	ScopeFile   Scope = iota // Whole file or container.
	ScopeTrack               // Selected audio track.
	ScopeAlbum               // Containing album.
	ScopeStream              // Live stream.
)

type SourceTag

type SourceTag struct {
	Namespace  string
	Name       string
	Qualifier  string
	Values     []string
	Language   string
	Locale     uint32 // Native locale indicator, if present.
	Scope      Scope
	Key        Key      // Canonical field, or Unknown.
	Normalized []string // Decoded values when they differ from Values.
}

SourceTag retains a text value in its native namespace.

type Update

type Update struct {
	Frame    int64    // Zero-based offset at the accompanying PCM rate.
	Exact    bool     // Whether the presentation frame is precise.
	Metadata Metadata // Snapshot at Frame.
}

Update describes a metadata snapshot at a presentation frame.

Jump to

Keyboard shortcuts

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