trackmeta

package
v2.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package trackmeta reads the tags and cover art of an audio track.

Tag data is untrusted: every read is bounded by a byte cap checked against the size the file declares before anything is parsed, structures whose lengths do not fit the data they sit in are refused before the tag parser sees them, and a panic inside the parser is recovered.

Index

Constants

View Source
const (
	SourceEmbedded = "embedded"
	SourceFolder   = "folder"
)

Picture source names reported by ReadPicture.

Variables

View Source
var (
	// ErrNoTags is returned when a track has no tags this package reads.
	ErrNoTags = errors.New("no track tags")
	// ErrTagsTooLarge is returned when a track declares more tag data than
	// the cap allows.
	ErrTagsTooLarge = errors.New("track tags exceed size limit")
	// ErrMalformedTags is returned when a track's tags do not fit together.
	ErrMalformedTags = errors.New("malformed track tags")
	// ErrNoArt is returned by ReadPicture when a track has no cover art.
	ErrNoArt = errors.New("no cover art")
)

Functions

func FolderArtPath

func FolderArtPath(path string) (string, bool)

FolderArtPath returns the cover image beside the track at path, if any.

func HasFolderArt

func HasFolderArt(path string) bool

findFolderArt looks for a cover, folder or front image in the directory of the track at path. HasFolderArt reports whether a cover, folder or front image sits beside the track at path.

Types

type Meta

type Meta struct {
	Title       string
	Artist      string
	Album       string
	AlbumArtist string
	Genre       string
	Year        int
	TrackNumber int
	TrackTotal  int
	DiscNumber  int
	DiscTotal   int
	// ReplayGainDB is the track's ReplayGain adjustment, valid when
	// HasReplayGain is set.
	ReplayGainDB  float64
	HasReplayGain bool
	// HasArt reports cover art either embedded in the track or as an image
	// beside it.
	HasArt bool
}

Meta is what a track's tags say about it. Empty fields were not tagged.

func Read

func Read(path string, maxTagBytes int64) (*Meta, error)

Read returns the tags of the track at path. Tag data larger than maxTagBytes is not parsed; the returned Meta then only reports folder art. It returns ErrNoTags when there is nothing to report at all.

type Picture

type Picture struct {
	// Path is the file the bytes came from: the track for embedded art, the
	// image file for folder art.
	Path     string
	MIMEType string
	Source   string
	Data     []byte
}

Picture is a track's cover art.

func ReadPicture

func ReadPicture(path string, maxBytes int64) (*Picture, error)

ReadPicture returns the cover art of the track at path: the picture embedded in its tags, else a cover, folder or front image beside it. Art larger than maxBytes is not returned.

Jump to

Keyboard shortcuts

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