Categorygithub.com/dhowden/tag
modulepackage
0.0.0-20240417053706-3d75831295e8
Repository: https://github.com/dhowden/tag.git
Documentation: pkg.go.dev

# README

MP3/MP4/OGG/FLAC metadata parsing library

GoDoc

This package provides MP3 (ID3v1,2.{2,3,4}) and MP4 (ACC, M4A, ALAC), OGG and FLAC metadata detection, parsing and artwork extraction.

Detect and parse tag metadata from an io.ReadSeeker (i.e. an *os.File):

m, err := tag.ReadFrom(f)
if err != nil {
	log.Fatal(err)
}
log.Print(m.Format()) // The detected format.
log.Print(m.Title())  // The title of the track (see Metadata interface for more details).

Parsed metadata is exported via a single interface (giving a consistent API for all supported metadata formats).

// Metadata is an interface which is used to describe metadata retrieved by this package.
type Metadata interface {
	Format() Format
	FileType() FileType

	Title() string
	Album() string
	Artist() string
	AlbumArtist() string
	Composer() string
	Genre() string
	Year() int

	Track() (int, int) // Number, Total
	Disc() (int, int) // Number, Total

	Picture() *Picture // Artwork
	Lyrics() string
	Comment() string

	Raw() map[string]interface{} // NB: raw tag names are not consistent across formats.
}

Audio Data Checksum (SHA1)

This package also provides a metadata-invariant checksum for audio files: only the audio data is used to construct the checksum.

https://pkg.go.dev/github.com/dhowden/tag#Sum

Tools

There are simple command-line tools which demonstrate basic tag extraction and summing:

$ go install github.com/dhowden/tag/cmd/tag@latest
$ cd $GOPATH/bin
$ ./tag 11\ High\ Hopes.m4a
Metadata Format: MP4
Title: High Hopes
Album: The Division Bell
Artist: Pink Floyd
Composer: Abbey Road Recording Studios/David Gilmour/Polly Samson
Year: 1994
Track: 11 of 11
Disc: 1 of 1
Picture: Picture{Ext: jpeg, MIMEType: image/jpeg, Type: , Description: , Data.Size: 606109}

$ ./sum 11\ High\ Hopes.m4a
2ae208c5f00a1f21f5fac9b7f6e0b8e52c06da29

# Packages

Package mbz extracts MusicBrainz Picard-specific tags from general tag metadata.

# Functions

Identify identifies the format and file type of the data in the ReadSeeker.
ReadAtoms reads MP4 metadata atoms from the io.ReadSeeker into a Metadata, returning non-nil error if there was a problem.
ReadDSFTags reads DSF metadata from the io.ReadSeeker, returning the resulting metadata in a Metadata implementation, or non-nil error if there was a problem.
ReadFLACTags reads FLAC metadata from the io.ReadSeeker, returning the resulting metadata in a Metadata implementation, or non-nil error if there was a problem.
ReadFrom detects and parses audio file metadata tags (currently supports ID3v1,2.{2,3,4}, MP4, FLAC/OGG).
ReadID3v1Tags reads ID3v1 tags from the io.ReadSeeker.
ReadID3v2Tags parses ID3v2.{2,3,4} tags from the io.ReadSeeker into a Metadata, returning non-nil error on failure.
ReadOGGTags reads OGG metadata from the io.ReadSeeker, returning the resulting metadata in a Metadata implementation, or non-nil error if there was a problem.
Sum creates a checksum of the audio file data provided by the io.ReadSeeker which is metadata (ID3, MP4) invariant.
SumAll returns a checksum of the content from the reader (until EOF).
SumAtoms constructs a checksum of MP4 audio file data provided by the io.ReadSeeker which is metadata invariant.
SumFLAC costructs a checksum of the FLAC audio file data provided by the io.ReadSeeker (ignores metadata fields).
SumID3v1 constructs a checksum of MP3 audio file data (assumed to have ID3v1 tags) provided by the io.ReadSeeker which is metadata invariant.
SumID3v2 constructs a checksum of MP3 audio file data (assumed to have ID3v2 tags) provided by the io.ReadSeeker which is metadata invariant.

# Constants

Apple Lossless file FIXME: actually detect this.
DSF file DSD Sony format see https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf.
FLAC file.
ID3v1 tag format.
ID3v2.2 tag format.
ID3v2.3 tag format (most common).
ID3v2.4 tag format.
M4A file Apple iTunes (ACC) Audio.
M4A file Apple iTunes (ACC) Audio Book.
M4A file Apple iTunes (ACC) AES Protected Audio.
MP3 file.
MP4 tag (atom) format (see http://www.ftyps.com/ for a full file type list).
OGG file.
Unknown FileType.
Unknown Format.
Vorbis Comment tag format.

# Variables

DefaultUTF16WithBOMByteOrder is the byte order used when the "UTF16 with BOM" encoding is specified without a corresponding BOM in the data.
ErrNoTagsFound is the error returned by ReadFrom when the metadata format cannot be identified.
ErrNotID3v1 is an error which is returned when no ID3v1 header is found.

# Structs

Comm is a type used in COMM, UFID, TXXX, WXXX and USLT tag.
Picture is a type which represents an attached picture extracted from metadata.
UFID is composed of a provider (frequently a URL and a binary identifier) The identifier can be a text (Musicbrainz use texts, but not necessary).

# Interfaces

Metadata is an interface which is used to describe metadata retrieved by this package.

# Type aliases

FileType is an enumeration of the audio file types supported by this package, in particular there are audio file types which share metadata formats, and this type is used to distinguish between them.
Format is an enumeration of metadata types supported by this package.