🎵 ID3 parsing and writing library for Go https://godoc.org/github.com/bogem/id3v2

Valery Gridnev cd346cac9d Attempt to fix parallel decoding (#74) 1 month ago
testdata ed68a94969 Update tests and testdata 2 years ago
v2 cd346cac9d Attempt to fix parallel decoding (#74) 1 month ago
.gitignore 5f2eaf0402 Add .gitignore 4 years ago
.travis.yml 3da5773345 Support older versions and 32bit 2 years ago
LICENSE 5aa0629ea3 First commit! 6 years ago
README.md 28e96ce23f Delete some dots from README 7 months ago
bench_test.go 6a143b684c Take off UDTF and UFID frames from benchmarks 4 years ago
buf_reader.go 2387fe5800 Make BOM private 2 years ago
buf_reader_test.go 2387fe5800 Make BOM private 2 years ago
buf_writer.go 88f2646e81 Fix UTF16LE parsing and writing 2 years ago
chapter_frame.go 033cd251e7 support CHAP frames (#62) 1 year ago
chapter_frame_test.go 033cd251e7 support CHAP frames (#62) 1 year ago
comment_frame.go da76e5aa9a V2.1 (#68) 1 year ago
common_ids.go da76e5aa9a V2.1 (#68) 1 year ago
encoding.go db1352ecc2 Put bufWriter in encodedSize 2 years ago
encoding_test.go da76e5aa9a V2.1 (#68) 1 year ago
example_test.go 8403eb1ef1 add popularimeter frame 2 years ago
framer.go 4de0eaa090 Add framer.UniqueIdentifier() 2 years ago
go.mod bf62f74844 Use Go modules 2 years ago
go.sum bf62f74844 Use Go modules 2 years ago
header.go 5785be9ad4 Tag header size should always be synchsafe 4 years ago
header_test.go 8190b64040 Use own bufWriter 4 years ago
id3v2.go 1283c51623 Add encoding conversion support 5 years ago
options.go 0735adcee6 Add id3v2.Options 5 years ago
parse.go da76e5aa9a V2.1 (#68) 1 year ago
parse_test.go 8403eb1ef1 add popularimeter frame 2 years ago
picture_frame.go da76e5aa9a V2.1 (#68) 1 year ago
pools.go e4247ea7ec Fix getByteSlice 4 years ago
popularimeter_frame.go da76e5aa9a V2.1 (#68) 1 year ago
popularimeter_frame_test.go 8403eb1ef1 add popularimeter frame 2 years ago
sequence.go 4de0eaa090 Add framer.UniqueIdentifier() 2 years ago
sequence_test.go da76e5aa9a V2.1 (#68) 1 year ago
size.go 3845103da5 Fix parsing and writing synchunsafe sizes, that are used in id3v2.3 4 years ago
size_test.go 171cb14044 Fix race conditions in unknown frame 2 years ago
tag.go da76e5aa9a V2.1 (#68) 1 year ago
tag_test.go 8403eb1ef1 add popularimeter frame 2 years ago
text_frame.go 9d871ea687 Add comment 2 years ago
ufid_frame.go da76e5aa9a V2.1 (#68) 1 year ago
unknown_frame.go 171cb14044 Fix race conditions in unknown frame 2 years ago
unknown_frame_test.go 171cb14044 Fix race conditions in unknown frame 2 years ago
unsynchronised_lyrics_frame.go da76e5aa9a V2.1 (#68) 1 year ago
user_defined_text_frame.go da76e5aa9a V2.1 (#68) 1 year ago

README.md

id3v2

Supported ID3 versions: 2.3, 2.4

Installation

go get -u github.com/bogem/id3v2/v2

Documentation

https://pkg.go.dev/github.com/bogem/id3v2/v2

Usage example

package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2/v2"
)

func main() {
	tag, err := id3v2.Open("file.mp3", id3v2.Options{Parse: true})
	if err != nil {
 		log.Fatal("Error while opening mp3 file: ", err)
 	}
	defer tag.Close()

	// Read tags
	fmt.Println(tag.Artist())
	fmt.Println(tag.Title())

	// Set tags
	tag.SetArtist("Aphex Twin")
	tag.SetTitle("Xtal")

	comment := id3v2.CommentFrame{
		Encoding:    id3v2.EncodingUTF8,
		Language:    "eng",
		Description: "My opinion",
		Text:        "I like this song!",
	}
	tag.AddCommentFrame(comment)

	// Write tag to file.mp3
	if err = tag.Save(); err != nil {
		log.Fatal("Error while saving a tag: ", err)
	}
}

Read multiple frames

pictures := tag.GetFrames(tag.CommonID("Attached picture"))
for _, f := range pictures {
	pic, ok := f.(id3v2.PictureFrame)
	if !ok {
		log.Fatal("Couldn't assert picture frame")
	}

	// Do something with picture frame
	fmt.Println(pic.Description)
}

Encodings

For example, if you want to set comment frame with custom encoding, you may do the following:

comment := id3v2.CommentFrame{
	Encoding:    id3v2.EncodingUTF16,
	Language:    "ger",
	Description: "Tier",
	Text:        "Der Löwe",
}
tag.AddCommentFrame(comment)

Text field will be automatically encoded with UTF-16BE with BOM and written to w.

UTF-8 is default for v2.4, ISO-8859-1 - for v2.3.