ID3 library for Go
Go to file
joshua stein 1c3fc9101a don't trust sizes of existing frames, re-calculate
also write new text strings for toc/chap in utf-16
2017-05-30 20:36:08 -05:00
encodedbytes don't trust sizes of existing frames, re-calculate 2017-05-30 20:36:08 -05:00
v1 add support for deleting a single frame 2017-05-26 21:56:20 -05:00
v2 don't trust sizes of existing frames, re-calculate 2017-05-30 20:36:08 -05:00
.travis.yml Update travis 2015-11-30 20:13:46 -05:00
LICENSE Initial commit 2013-12-19 15:20:17 -05:00
README.md Add build status indicator 2014-07-04 21:31:18 -04:00
chaptest.mp3 add support for reading and writing CHAP and CTOC frames 2017-05-26 21:56:19 -05:00
id3.go add support for deleting a single frame 2017-05-26 21:56:20 -05:00
id3_test.go Remove dependency on iconv with the help of @mmorton's patches 2017-05-26 21:56:20 -05:00
test.mp3 cleaned up testing of UTF-16 on UnsynchTextFrames fix 2014-07-05 18:38:28 -04:00
util.go Move file end check to helper method 2014-01-10 14:54:24 -05:00

README.md

id3

build status

ID3 library for Go.

Supported formats:

  • ID3v1
  • ID3v2.2
  • ID3v2.3

Install

The platform ($GOROOT/bin) "go get" tool is the best method to install.

go get github.com/mikkyang/id3-go

This downloads and installs the package into your $GOPATH. If you only want to recompile, use "go install".

go install github.com/mikkyang/id3-go

Usage

An import allows access to the package.

import (
    id3 "github.com/mikkyang/id3-go"
)

Version specific details can be accessed through the subpackages.

import (
    "github.com/mikkyang/id3-go/v1"
    "github.com/mikkyang/id3-go/v2"
)

Quick Start

To access the tag of a file, first open the file using the package's Open function.

mp3File, err := id3.Open("All-In.mp3")

It's also a good idea to ensure that the file is closed using defer.

defer mp3File.Close()

Accessing Information

Some commonly used data have methods in the tag for easier access. These methods are for Title, Artist, Album, Year, Genre, and Comments.

mp3File.SetArtist("Okasian")
fmt.Println(mp3File.Artist())

ID3v2 Frames

v2 Frames can be accessed directly by using the Frame or Frames method of the file, which return the first frame or a slice of frames as Framer interfaces. These interfaces allow read access to general details of the file.

lyricsFrame := mp3File.Frame("USLT")
lyrics := lyricsFrame.String()

If more specific information is needed, or frame-specific write access is needed, then the interface must be cast into the appropriate underlying type. The example provided does not check for errors, but it is recommended to do so.

lyricsFrame := mp3File.Frame("USLT").(*v2.UnsynchTextFrame)

Adding Frames

For common fields, a frame will automatically be created with the Set method. For other frames or more fine-grained control, frames can be created with the corresponding constructor, usually prefixed by New. These constructors require the first argument to be a FrameType struct, which are global variables named by version.

ft := V23FrameTypeMap["TIT2"]
text := "Hello"
textFrame := NewTextFrame(ft, text)
mp3File.AddFrames(textFrame)