ID3, MP4 and OGG/FLAC metadata parsing in Go
Go to file
Xavier Henner 1e646522d6 Support for numeric genres in id3v2
TCON

    The 'Content type', which previously was stored as a one byte numeric value
only, is now a numeric string. You may use one or several of the types as
ID3v1.1 did or, since the category list would be impossible to maintain with
accurate and up to date categories, define your own.

    References to the ID3v1 genres can be made by, as first byte, enter "("
followed by a number from the genres list (appendix A) and ended with a ")"
character. This is optionally followed by a refinement, e.g. "(21)" or
"(4)Eurodisco". Several references can be made in the same frame, e.g.
"(51)(39)". If the refinement should begin with a "(" character it should be
replaced with "((", e.g. "((I can figure out any genre)" or "(55)((I
think...)". The following new content types is defined in ID3v2 and is
implemented in the same way as the numerig content types, e.g. "(RX)".

To test it, use the id3v2 tool

% id3v2 -g 79 test.mp3
% id3v2 -l test.mp3| grep TCON
TCON (Content type): Hard Rock (79)
% ./tag test.mp3| grep Genre
 Genre: (79)

With the patch :
% go build && ./tag test.mp3| grep Genre
 Genre: Hard Rock
2015-07-04 14:20:43 +02:00
check Added Identity to check tool. 2015-07-02 23:07:50 +10:00
mbz Simplify MusicBrainz Info type and support more tags. 2015-06-08 11:01:32 +10:00
sum Refactored Hash -> Sum and fixed infinite loop issue with SumAtoms 2015-04-03 15:13:39 +11:00
tag Added -mbz option to tag tool to output MusicBrainz information. 2015-06-06 16:35:44 +10:00
.editorconfig Add a basic editorconfig file 2015-05-01 22:44:59 +10:00
.travis.yml Added .travis.yml 2015-03-20 09:02:27 +11:00
flac.go Tidy up visibility of internal-only types. 2015-06-28 12:40:49 +10:00
id3v1.go Reorganised Vorbis Comment parsing into own type 2015-05-24 10:44:45 +10:00
id3v2_test.go Support for numeric genres in id3v2 2015-07-04 14:20:43 +02:00
id3v2.go Support for numeric genres in id3v2 2015-07-04 14:20:43 +02:00
id3v2frames.go Check each ID3 tag is valid. 2015-06-28 09:53:07 +10:00
id3v2metadata_test.go Initial commit 2015-03-19 23:21:53 +11:00
id3v2metadata.go Support for numeric genres in id3v2 2015-07-04 14:20:43 +02:00
id.go Fix godoc comment. 2015-07-03 23:15:16 +10:00
LICENSE Initial commit 2015-03-19 23:21:53 +11:00
mp4.go Remove non-relative Seek calls from all functions. 2015-06-07 12:58:58 +10:00
ogg.go Remove non-relative Seek calls from all functions. 2015-06-07 12:58:58 +10:00
README.md Update README to include simple code example. 2015-06-28 10:43:57 +10:00
sum.go Refactor common code to skip last 128 bytes from ReadSeeker. 2015-06-30 23:07:26 +10:00
tag.go Add Identity function for identifying metadata/filetypes. 2015-07-02 23:07:17 +10:00
util_test.go Add some basic tests for utils 2015-05-03 09:59:03 +10:00
util.go Implemented basic FLAC support (no artwork, yet!) 2015-04-15 00:12:37 +10:00
vorbis.go Reorganised Vorbis Comment parsing into own type 2015-05-24 10:44:45 +10:00

MP3/MP4/OGG/FLAC metadata parsing library

Build Status 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

	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.

http://godoc.org/github.com/dhowden/tag#Sum

Tools

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

$ go get github.com/dhowden/tag/...
$ 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