ID3, MP4 and OGG/FLAC metadata parsing in Go
Go to file
majomi 142ccac8dc
Some checks failed
Go / build (push) Failing after 43s
go.mod
2024-07-15 16:37:49 +02:00
.github/workflows id3v2: try to parse the year when 'year' tag could be a date (#104) 2024-04-17 15:37:06 +10:00
cmd Add comment metadata (#44) 2018-11-05 07:56:00 +11:00
internal/id3v1_test Move ID3v1 test data under internal directory 2016-07-17 08:16:53 +10:00
mbz Simplify MusicBrainz Info type and support more tags. 2015-06-08 11:01:32 +10:00
testdata ogg: support comment header packets spanning pages (#57) 2019-11-22 22:23:40 +11:00
.editorconfig Add a basic editorconfig file 2015-05-01 22:44:59 +10:00
.travis.yml update to use new io.Seek consts, require min go1.7 2018-04-02 11:06:41 +10:00
dsf.go move towards using uint for all sizes (#59) 2019-11-22 22:50:59 +11:00
flac.go update to use new io.Seek consts, require min go1.7 2018-04-02 11:06:41 +10:00
go.mod go.mod 2024-07-15 16:37:49 +02:00
go.sum go.mod 2024-07-15 16:37:49 +02:00
id3v1_test.go Move ID3v1 test data under internal directory 2016-07-17 08:16:53 +10:00
id3v1.go Add comment metadata (#44) 2018-11-05 07:56:00 +11:00
id3v2_test.go added genre codes 148 to 191 (winamp ext) (#103) 2024-01-23 08:33:51 +11:00
id3v2.go added genre codes 148 to 191 (winamp ext) (#103) 2024-01-23 08:33:51 +11:00
id3v2frames.go fix panic on invalid input 2020-11-20 18:04:57 +11:00
id3v2metadata_test.go Initial commit 2015-03-19 23:21:53 +11:00
id3v2metadata.go id3v2: try to parse the year when 'year' tag could be a date (#104) 2024-04-17 15:37:06 +10:00
id.go update to use new io.Seek consts, require min go1.7 2018-04-02 11:06:41 +10:00
LICENSE Initial commit 2015-03-19 23:21:53 +11:00
mp4.go add additional means (#101) 2024-01-23 08:42:04 +11:00
ogg.go Add Ogg Opus metadata support (#69) 2022-05-30 21:04:23 +10:00
README.md update README links (#93) 2022-06-19 09:00:19 +10:00
sum_test.go limit up-front allocation when reading bytes 2020-08-29 07:40:07 +10:00
sum.go update to use new io.Seek consts, require min go1.7 2018-04-02 11:06:41 +10:00
tag_test.go ogg: support comment header packets spanning pages (#57) 2019-11-22 22:23:40 +11:00
tag.go added dsf support, reusing the existing ID3 parser (#43) 2018-11-05 09:57:29 +11:00
util_test.go move towards using uint for all sizes (#59) 2019-11-22 22:50:59 +11:00
util.go limit up-front allocation when reading bytes 2020-08-29 07:40:07 +10:00
vorbis.go Fix typo 2024-07-15 16:25:51 +02:00

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