2015-05-24 03:29:38 +02:00
|
|
|
# MP3/MP4/OGG/FLAC metadata parsing library
|
2015-03-19 23:09:07 +01:00
|
|
|
[![Build Status](https://travis-ci.org/dhowden/tag.svg?branch=master)](https://travis-ci.org/dhowden/tag)
|
2015-03-19 13:29:03 +01:00
|
|
|
[![GoDoc](https://godoc.org/github.com/dhowden/tag?status.svg)](https://godoc.org/github.com/dhowden/tag)
|
|
|
|
|
2015-05-24 03:29:38 +02:00
|
|
|
This package provides MP3 (ID3v1,2.{2,3,4}) and MP4 (ACC, M4A, ALAC), OGG and FLAC metadata detection, parsing and artwork extraction.
|
2015-04-03 06:12:30 +02:00
|
|
|
|
2015-06-28 02:43:57 +02:00
|
|
|
Detect and parse tag metadata from an `io.ReadSeeker` (i.e. an `*os.File`):
|
|
|
|
|
2017-01-29 00:14:22 +01:00
|
|
|
```go
|
|
|
|
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).
|
|
|
|
```
|
2015-06-28 02:43:57 +02:00
|
|
|
|
2015-04-03 06:12:30 +02:00
|
|
|
Parsed metadata is exported via a single interface (giving a consistent API for all supported metadata formats).
|
|
|
|
|
2017-01-29 00:14:22 +01:00
|
|
|
```go
|
|
|
|
// 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
|
2018-11-04 21:56:00 +01:00
|
|
|
Comment() string
|
2017-01-29 00:14:22 +01:00
|
|
|
|
|
|
|
Raw() map[string]interface{} // NB: raw tag names are not consistent across formats.
|
|
|
|
}
|
|
|
|
```
|
2015-04-03 06:12:30 +02:00
|
|
|
|
|
|
|
## 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](http://godoc.org/github.com/dhowden/tag#Sum)
|
|
|
|
|
2015-06-28 02:43:57 +02:00
|
|
|
## Tools
|
2015-04-03 06:12:30 +02:00
|
|
|
|
2015-06-28 02:43:57 +02:00
|
|
|
There are simple command-line tools which demonstrate basic tag extraction and summing:
|
2015-04-03 06:12:30 +02:00
|
|
|
|
2017-08-01 14:29:01 +02:00
|
|
|
```console
|
|
|
|
$ 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
|
|
|
|
```
|