Skip to content

n10v/id3v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

34286c4 Â· May 9, 2023
Dec 22, 2022
Mar 3, 2020
Feb 9, 2023
May 17, 2018
May 15, 2016
May 9, 2023
Aug 25, 2018
May 1, 2020
May 1, 2020
Mar 3, 2020
Nov 23, 2021
Nov 23, 2021
Nov 23, 2021
Nov 23, 2021
Jun 6, 2020
Nov 23, 2021
Jun 7, 2020
Feb 12, 2020
Mar 5, 2020
Mar 5, 2020
Aug 15, 2018
Apr 7, 2018
Aug 24, 2017
May 1, 2017
Nov 23, 2021
Jun 7, 2020
Nov 23, 2021
Apr 7, 2018
Nov 23, 2021
Jun 7, 2020
Feb 12, 2020
Nov 23, 2021
Aug 15, 2018
Jun 5, 2020
Nov 23, 2021
Jun 7, 2020
Mar 3, 2020
Nov 23, 2021
Jun 5, 2020
Jun 5, 2020
Nov 23, 2021
Nov 23, 2021

Repository files navigation

id3v2

Implementation of ID3 v2.3 and v2.4 in native Go.

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.