id3v2

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2018 License: MIT Imports: 9 Imported by: 0

README

id3v2 GoDoc Build Status

Fast, simple and powerful ID3 parsing and writing library for Go, based only on standard library.

id3v2 can:

  • ✅ support of ID3v2.3 and ID3v2.4 tags;
  • ✅ parse and write tags;
  • ✅ work with all available encodings;
  • ✅ set and read all text frames, unsynchronised lyrics/text (USLT), comments, attached pictures, UFID and TXXX frames;
  • ✅ set and read frames, that can be used multiple times in tag;
  • ✅ be used in multiple goroutines.

id3v2 can't:

  • ❌ work with unsynchronization, extended header, flags, padding, footer.

If you want some functionality, that library can't do, or you have some questions, just write an issue. And of course, pull requests are welcome!

Installation

go get -u github.com/bogem/id3v2

Example of usage

package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

func main() {
	// Open file and parse tag in it.
	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 frames.
	fmt.Println(tag.Artist())
	fmt.Println(tag.Title())

	// Set simple text frames.
	tag.SetArtist("New artist")
	tag.SetTitle("New title")

	// Set comment frame.
	comment := id3v2.CommentFrame{
		Encoding:    id3v2.EncodingUTF8,
		Language:    "eng",
		Description: "My opinion",
		Text:        "Very good song",
	}
	tag.AddCommentFrame(comment)

	// Write it to file.
	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.
	// For example, print the description:
	fmt.Println(pic.Description)
}

Options

// Options influence on processing the tag.
type Options struct {
	// Parse defines, if tag will be parsed.
	Parse bool

	// ParseFrames defines, that frames do you only want to parse. For example,
	// `ParseFrames: []string{"Artist", "Title"}` will only parse artist
	// and title frames. You can specify IDs ("TPE1", "TIT2") as well as
	// descriptions ("Artist", "Title"). If ParseFrame is blank or nil,
	// id3v2 will parse all frames in tag. It works only if Parse is true.
	//
	// It's very useful for performance, so for example
	// if you want to get only some text frames,
	// id3v2 will not parse huge picture or unknown frames.
	ParseFrames []string
}

Work with encodings

id3v2 can encode and decode text of avaialble encodings (ISO-8859-1, UTF-16 with BOM, UTF-16BE without BOM, UTF-8). Just set the desired encoding in Encoding field of frame and set UTF-8 encoded text to corresponding text fields.

For example, if you set comment frame with custom encoding and write it:

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

_, err := tag.WriteTo(w)
if err != nil {
	log.Fatal(err)
}

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

By default, if version of tag is 4 then UTF-8 is used for methods like SetArtist, SetTitle, SetGenre and etc, otherwise ISO-8859-1.

Benchmarks

See benchmarks in the description of last release.

Reference

https://godoc.org/github.com/bogem/id3v2

Documentation

Overview

Package id3v2 is the ID3 parsing and writing library for Go.

Example
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

func main() {
	// Open file and parse tag in it.
	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 frames.
	fmt.Println(tag.Artist())
	fmt.Println(tag.Title())

	// Set simple text frames.
	tag.SetArtist("Artist")
	tag.SetTitle("Title")

	// Set comment frame.
	comment := id3v2.CommentFrame{
		Encoding:    id3v2.EncodingUTF8,
		Language:    "eng",
		Description: "My opinion",
		Text:        "Very good song",
	}
	tag.AddCommentFrame(comment)

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

Example (Concurrent)
package main

import (
	"fmt"
	"log"
	"os"
	"sync"

	"github.com/bogem/id3v2"
)

func main() {
	tagPool := sync.Pool{New: func() interface{} { return id3v2.NewEmptyTag() }}

	var wg sync.WaitGroup
	wg.Add(100)
	for i := 0; i < 100; i++ {
		go func() {
			defer wg.Done()

			tag := tagPool.Get().(*id3v2.Tag)
			defer tagPool.Put(tag)

			file, err := os.Open("file.mp3")
			if err != nil {
				log.Fatal("Error while opening file:", err)
			}
			defer file.Close()

			if err := tag.Reset(file, id3v2.Options{Parse: true}); err != nil {
				log.Fatal("Error while reseting tag to file:", err)
			}

			fmt.Println(tag.Artist() + " - " + tag.Title())
		}()
	}
	wg.Wait()
}
Output:

Index

Examples

Constants

View Source
const (
	PTOther = iota
	PTFileIcon
	PTOtherFileIcon
	PTFrontCover
	PTBackCover
	PTLeafletPage
	PTMedia
	PTLeadArtistSoloist
	PTArtistPerformer
	PTConductor
	PTBandOrchestra
	PTComposer
	PTLyricistTextWriter
	PTRecordingLocation
	PTDuringRecording
	PTDuringPerformance
	PTMovieScreenCapture
	PTBrightColouredFish
	PTIllustration
	PTBandArtistLogotype
	PTPublisherStudioLogotype
)

Available picture types for picture frame.

Variables

View Source
var (
	V23CommonIDs = map[string]string{
		"Attached picture":                   "APIC",
		"Comments":                           "COMM",
		"Album/Movie/Show title":             "TALB",
		"BPM":                                "TBPM",
		"Composer":                           "TCOM",
		"Content type":                       "TCON",
		"Copyright message":                  "TCOP",
		"Date":                               "TDAT",
		"Playlist delay":                     "TDLY",
		"Encoded by":                         "TENC",
		"Lyricist/Text writer":               "TEXT",
		"File type":                          "TFLT",
		"Time":                               "TIME",
		"Content group description":          "TIT1",
		"Title/Songname/Content description": "TIT2",
		"Subtitle/Description refinement":    "TIT3",
		"Initial key":                        "TKEY",
		"Language":                           "TLAN",
		"Length":                             "TLEN",
		"Media type":                         "TMED",
		"Original album/movie/show title":    "TOAL",
		"Original filename":                  "TOFN",
		"Original lyricist/text writer":      "TOLY",
		"Original artist/performer":          "TOPE",
		"Original release year":              "TORY",
		"File owner/licensee":                "TOWN",
		"Lead artist/Lead performer/Soloist/Performing group": "TPE1",
		"Band/Orchestra/Accompaniment":                        "TPE2",
		"Conductor/performer refinement":                      "TPE3",
		"Interpreted, remixed, or otherwise modified by":      "TPE4",
		"Part of a set":                "TPOS",
		"Publisher":                    "TPUB",
		"Track number/Position in set": "TRCK",
		"Recording dates":              "TRDA",
		"Internet radio station name":  "TRSN",
		"Internet radio station owner": "TRSO",
		"Size":                         "TSIZ",
		"ISRC":                         "TSRC",
		"Software/Hardware and settings used for encoding": "TSSE",
		"Year":                                     "TYER",
		"User defined text information frame":      "TXXX",
		"Unique file identifier":                   "UFID",
		"Unsynchronised lyrics/text transcription": "USLT",

		"Artist": "TPE1",
		"Title":  "TIT2",
		"Genre":  "TCON",
	}

	V24CommonIDs = map[string]string{
		"Attached picture":                   "APIC",
		"Comments":                           "COMM",
		"Album/Movie/Show title":             "TALB",
		"BPM":                                "TBPM",
		"Composer":                           "TCOM",
		"Content type":                       "TCON",
		"Copyright message":                  "TCOP",
		"Encoding time":                      "TDEN",
		"Playlist delay":                     "TDLY",
		"Original release time":              "TDOR",
		"Recording time":                     "TDRC",
		"Release time":                       "TDRL",
		"Tagging time":                       "TDTG",
		"Encoded by":                         "TENC",
		"Lyricist/Text writer":               "TEXT",
		"File type":                          "TFLT",
		"Involved people list":               "TIPL",
		"Content group description":          "TIT1",
		"Title/Songname/Content description": "TIT2",
		"Subtitle/Description refinement":    "TIT3",
		"Initial key":                        "TKEY",
		"Language":                           "TLAN",
		"Length":                             "TLEN",
		"Musician credits list":              "TMCL",
		"Media type":                         "TMED",
		"Mood":                               "TMOO",
		"Original album/movie/show title":    "TOAL",
		"Original filename":                  "TOFN",
		"Original lyricist/text writer":      "TOLY",
		"Original artist/performer":          "TOPE",
		"File owner/licensee":                "TOWN",
		"Lead artist/Lead performer/Soloist/Performing group": "TPE1",
		"Band/Orchestra/Accompaniment":                        "TPE2",
		"Conductor/performer refinement":                      "TPE3",
		"Interpreted, remixed, or otherwise modified by":      "TPE4",
		"Part of a set":                "TPOS",
		"Produced notice":              "TPRO",
		"Publisher":                    "TPUB",
		"Track number/Position in set": "TRCK",
		"Internet radio station name":  "TRSN",
		"Internet radio station owner": "TRSO",
		"Album sort order":             "TSOA",
		"Performer sort order":         "TSOP",
		"Title sort order":             "TSOT",
		"ISRC":                         "TSRC",
		"Software/Hardware and settings used for encoding": "TSSE",
		"Set subtitle":                             "TSST",
		"User defined text information frame":      "TXXX",
		"Unique file identifier":                   "UFID",
		"Unsynchronised lyrics/text transcription": "USLT",

		"Date":                  "TDRC",
		"Time":                  "TDRC",
		"Original release year": "TDOR",
		"Recording dates":       "TDRC",
		"Size":                  "",
		"Year":                  "TDRC",

		"Artist": "TPE1",
		"Title":  "TIT2",
		"Genre":  "TCON",
	}
)

Common IDs for ID3v2.3 and ID3v2.4.

View Source
var (
	// EncodingISO is ISO-8859-1 encoding.
	EncodingISO = Encoding{
		Name:             "ISO-8859-1",
		Key:              0,
		TerminationBytes: []byte{0},
	}

	// EncodingUTF16 is UTF-16 encoded Unicode with BOM.
	EncodingUTF16 = Encoding{
		Name:             "UTF-16 encoded Unicode with BOM",
		Key:              1,
		TerminationBytes: []byte{0, 0},
	}

	// EncodingUTF16BE is UTF-16BE encoded Unicode without BOM.
	EncodingUTF16BE = Encoding{
		Name:             "UTF-16BE encoded Unicode without BOM",
		Key:              2,
		TerminationBytes: []byte{0, 0},
	}

	// EncodingUTF8 is UTF-8 encoded Unicode.
	EncodingUTF8 = Encoding{
		Name:             "UTF-8 encoded Unicode",
		Key:              3,
		TerminationBytes: []byte{0},
	}
)

Available encodings.

View Source
var ErrInvalidLanguageLength = errors.New("language code must consist of three letters according to ISO 639-2")
View Source
var ErrInvalidSizeFormat = errors.New("invalid format of tag's/frame's size")
View Source
var ErrNoFile = errors.New("tag was not initialized with file")
View Source
var ErrSizeOverflow = errors.New("size of tag/frame is greater than allowed in id3 tag")
View Source
var ErrSmallHeaderSize = errors.New("size of tag header is less than expected")
View Source
var ErrUnsupportedVersion = errors.New("unsupported version of ID3 tag")

Functions

This section is empty.

Types

type CommentFrame added in v0.6.1

type CommentFrame struct {
	Encoding    Encoding
	Language    string
	Description string
	Text        string
}

CommentFrame is used to work with COMM frames. The information about how to add comment frame to tag you can see in the docs to tag.AddCommentFrame function.

You must choose a three-letter language code from ISO 639-2 code list: https://www.loc.gov/standards/iso639-2/php/code_list.php

Example (Add)
package main

import (
	"github.com/bogem/id3v2"
)

func main() {
	tag := id3v2.NewEmptyTag()
	comment := id3v2.CommentFrame{
		Encoding:    id3v2.EncodingUTF8,
		Language:    "eng",
		Description: "My opinion",
		Text:        "Very good song",
	}
	tag.AddCommentFrame(comment)
}
Output:

Example (Get)
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	comments := tag.GetFrames(tag.CommonID("Comments"))
	for _, f := range comments {
		comment, ok := f.(id3v2.CommentFrame)
		if !ok {
			log.Fatal("Couldn't assert comment frame")
		}

		// Do something with comment frame.
		// For example, print the text:
		fmt.Println(comment.Text)
	}
}
Output:

func (CommentFrame) Size added in v0.8.6

func (cf CommentFrame) Size() int

func (CommentFrame) WriteTo added in v0.8.6

func (cf CommentFrame) WriteTo(w io.Writer) (n int64, err error)

type Encoding added in v0.12.1

type Encoding struct {
	Name             string
	Key              byte
	TerminationBytes []byte
}

Encoding is a struct for encodings.

func (Encoding) Equals added in v0.12.1

func (e Encoding) Equals(other Encoding) bool

func (Encoding) String added in v0.12.1

func (e Encoding) String() string

type Framer added in v0.6.1

type Framer interface {
	// Size returns the size of frame body.
	Size() int

	// WriteTo writes body slice into w.
	WriteTo(w io.Writer) (n int64, err error)
}

Framer provides a generic interface for frames. You can create your own frames. They must implement only this interface.

type Options added in v0.12.1

type Options struct {
	// Parse defines, if tag will be parsed.
	Parse bool

	// ParseFrames defines, that frames do you only want to parse. For example,
	// `ParseFrames: []string{"Artist", "Title"}` will only parse artist
	// and title frames. You can specify IDs ("TPE1", "TIT2") as well as
	// descriptions ("Artist", "Title"). If ParseFrame is blank or nil,
	// id3v2 will parse all frames in tag. It works only if Parse is true.
	//
	// It's very useful for performance, so for example
	// if you want to get only some text frames,
	// id3v2 will not parse huge picture or unknown frames.
	ParseFrames []string
}

Options influence on processing the tag.

type PictureFrame added in v0.6.1

type PictureFrame struct {
	Encoding    Encoding
	MimeType    string
	PictureType byte
	Description string
	Picture     []byte
}

PictureFrame structure is used for picture frames (APIC). The information about how to add picture frame to tag you can see in the docs to tag.AddAttachedPicture function.

Available picture types you can see in constants.

Example (Add)
package main

import (
	"io/ioutil"
	"log"

	"github.com/bogem/id3v2"
)

func main() {
	tag := id3v2.NewEmptyTag()
	artwork, err := ioutil.ReadFile("artwork.jpg")
	if err != nil {
		log.Fatal("Error while reading artwork file", err)
	}

	pic := id3v2.PictureFrame{
		Encoding:    id3v2.EncodingUTF8,
		MimeType:    "image/jpeg",
		PictureType: id3v2.PTFrontCover,
		Description: "Front cover",
		Picture:     artwork,
	}
	tag.AddAttachedPicture(pic)
}
Output:

Example (Get)
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	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.
		// For example, print the description:
		fmt.Println(pic.Description)
	}
}
Output:

func (PictureFrame) Size added in v0.8.6

func (pf PictureFrame) Size() int

func (PictureFrame) WriteTo added in v0.8.6

func (pf PictureFrame) WriteTo(w io.Writer) (n int64, err error)

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag stores all information about opened tag.

func NewEmptyTag added in v0.12.1

func NewEmptyTag() *Tag

NewEmptyTag returns an empty ID3v2.4 tag without any frames and reader.

func Open

func Open(name string, opts Options) (*Tag, error)

Open opens file with name and passes it to OpenFile. If there is no tag in file, it will create new one with version ID3v2.4.

func ParseReader added in v0.12.1

func ParseReader(rd io.Reader, opts Options) (*Tag, error)

ParseReader parses rd and finds tag in it considering opts. If there is no tag in rd, it will create new one with version ID3v2.4.

func (*Tag) AddAttachedPicture added in v0.5.1

func (tag *Tag) AddAttachedPicture(pf PictureFrame)

AddAttachedPicture adds the picture frame to tag.

Example
package main

import (
	"io/ioutil"
	"log"

	"github.com/bogem/id3v2"
)

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

	artwork, err := ioutil.ReadFile("artwork.jpg")
	if err != nil {
		log.Fatal("Error while reading artwork file", err)
	}

	pic := id3v2.PictureFrame{
		Encoding:    id3v2.EncodingUTF8,
		MimeType:    "image/jpeg",
		PictureType: id3v2.PTFrontCover,
		Description: "Front cover",
		Picture:     artwork,
	}
	tag.AddAttachedPicture(pic)
}
Output:

func (*Tag) AddCommentFrame added in v0.5.1

func (tag *Tag) AddCommentFrame(cf CommentFrame)

AddCommentFrame adds the comment frame to tag.

Example
package main

import (
	"log"

	"github.com/bogem/id3v2"
)

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

	comment := id3v2.CommentFrame{
		Encoding:    id3v2.EncodingUTF8,
		Language:    "eng",
		Description: "My opinion",
		Text:        "Very good song",
	}
	tag.AddCommentFrame(comment)
}
Output:

func (*Tag) AddFrame added in v0.5.1

func (tag *Tag) AddFrame(id string, f Framer)

AddFrame adds f to tag with appropriate id. If id is "" or f is nil, AddFrame will not add it to tag.

If you want to add attached picture, comment or unsynchronised lyrics/text transcription frames, better use AddAttachedPicture, AddCommentFrame or AddUnsynchronisedLyricsFrame methods respectively.

func (*Tag) AddTextFrame added in v1.1.1

func (tag *Tag) AddTextFrame(id string, encoding Encoding, text string)

AddTextFrame creates the text frame with provided encoding and text and adds to tag.

func (*Tag) AddUFIDFrame added in v1.1.0

func (tag *Tag) AddUFIDFrame(ufid UFIDFrame)

AddUFIDFrame adds the unique file identifier frame (UFID) to tag.

func (*Tag) AddUnsynchronisedLyricsFrame added in v0.5.1

func (tag *Tag) AddUnsynchronisedLyricsFrame(uslf UnsynchronisedLyricsFrame)

AddUnsynchronisedLyricsFrame adds the unsynchronised lyrics/text frame to tag.

Example
package main

import (
	"log"

	"github.com/bogem/id3v2"
)

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

	uslt := id3v2.UnsynchronisedLyricsFrame{
		Encoding:          id3v2.EncodingUTF8,
		Language:          "ger",
		ContentDescriptor: "Deutsche Nationalhymne",
		Lyrics:            "Einigkeit und Recht und Freiheit...",
	}
	tag.AddUnsynchronisedLyricsFrame(uslt)
}
Output:

func (*Tag) AddUserDefinedTextFrame added in v1.1.0

func (tag *Tag) AddUserDefinedTextFrame(udtf UserDefinedTextFrame)

AddUserDefinedTextFrame adds the custom frame (TXXX) to tag.

func (*Tag) Album added in v0.7.1

func (tag *Tag) Album() string

func (*Tag) AllFrames added in v0.7.1

func (tag *Tag) AllFrames() map[string][]Framer

AllFrames returns map, that contains all frames in tag, that could be parsed. The key of this map is an ID of frame and value is an array of frames.

func (*Tag) Artist added in v0.7.1

func (tag *Tag) Artist() string

func (*Tag) Close

func (tag *Tag) Close() error

Close closes tag's file, if tag was opened with a file. If tag was initiliazed not with file, it returns ErrNoFile.

func (*Tag) CommonID added in v0.8.3

func (tag *Tag) CommonID(description string) string

CommonID returns ID3v2.3 or ID3v2.4 (in appropriate to version of Tag) frame ID from given description. For example, CommonID("Language") will return "TLAN". If it can't find the ID with given description, it returns the description.

All descriptions you can find in file common_ids.go or in id3 documentation (for fourth version: http://id3.org/id3v2.4.0-frames; for third version: http://id3.org/id3v2.3.0#Declared_ID3v2_frames).

func (*Tag) Count added in v0.8.6

func (tag *Tag) Count() int

Count returns the number of frames in tag.

func (*Tag) DefaultEncoding added in v1.1.1

func (tag *Tag) DefaultEncoding() Encoding

DefaultEncoding returns default encoding of tag. Default encoding is used in methods (e.g. SetArtist, SetAlbum ...) for setting text frames without the explicit providing of encoding.

func (*Tag) DeleteAllFrames added in v0.8.1

func (tag *Tag) DeleteAllFrames()

DeleteAllFrames deletes all frames in tag.

func (*Tag) DeleteFrames added in v0.8.1

func (tag *Tag) DeleteFrames(id string)

DeleteFrames deletes frames in tag with given id.

func (*Tag) Genre added in v0.7.1

func (tag *Tag) Genre() string

func (*Tag) GetFrames added in v0.7.1

func (tag *Tag) GetFrames(id string) []Framer

GetFrames returns frames with corresponding id. It returns nil if there is no frames with given id.

Example
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	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.
		// For example, print description of picture frame:
		fmt.Println(pic.Description)
	}
}
Output:

func (*Tag) GetLastFrame added in v0.7.1

func (tag *Tag) GetLastFrame(id string) Framer

GetLastFrame returns last frame from slice, that is returned from GetFrames function. GetLastFrame is suitable for frames, that can be only one in whole tag. For example, for text frames.

Example
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	bpmFramer := tag.GetLastFrame(tag.CommonID("BPM"))
	if bpmFramer != nil {
		bpm, ok := bpmFramer.(id3v2.TextFrame)
		if !ok {
			log.Fatal("Couldn't assert bpm frame")
		}
		fmt.Println(bpm.Text)
	}
}
Output:

func (*Tag) GetTextFrame added in v0.7.1

func (tag *Tag) GetTextFrame(id string) TextFrame

GetTextFrame returns text frame with corresponding id.

func (*Tag) HasFrames added in v0.12.1

func (tag *Tag) HasFrames() bool

HasFrames checks if there is at least one frame in tag. It's much faster than tag.Count() > 0.

func (*Tag) Reset added in v0.12.1

func (tag *Tag) Reset(rd io.Reader, opts Options) error

Reset deletes all frames in tag and parses rd considering opts.

func (*Tag) Save added in v0.7.1

func (tag *Tag) Save() error

Save writes tag to the file, if tag was opened with a file. If there are no frames in tag, Save will write only music part without any ID3v2 information. If tag was initiliazed not with file, it returns ErrNoFile.

func (*Tag) SetAlbum

func (tag *Tag) SetAlbum(album string)

func (*Tag) SetArtist

func (tag *Tag) SetArtist(artist string)

func (*Tag) SetDefaultEncoding added in v1.1.1

func (tag *Tag) SetDefaultEncoding(encoding Encoding)

SetDefaultEncoding sets default encoding for tag. Default encoding is used in methods (e.g. SetArtist, SetAlbum ...) for setting text frames without explicit providing encoding.

func (*Tag) SetGenre

func (tag *Tag) SetGenre(genre string)

func (*Tag) SetTitle

func (tag *Tag) SetTitle(title string)

func (*Tag) SetVersion added in v0.8.7

func (tag *Tag) SetVersion(version byte)

SetVersion sets given ID3v2 version to tag. If version is less than 3 or greater than 4, then this method will do nothing. If tag has some frames, which are deprecated or changed in given version, then to your notice you can delete, change or just stay them.

func (*Tag) SetYear

func (tag *Tag) SetYear(year string)

func (*Tag) Size added in v0.8.8

func (tag *Tag) Size() int

Size returns the size of tag (tag header + size of all frames) in bytes.

func (*Tag) Title added in v0.7.1

func (tag *Tag) Title() string

func (*Tag) Version added in v0.8.7

func (tag *Tag) Version() byte

Version returns current ID3v2 version of tag.

func (*Tag) WriteTo added in v0.8.9

func (tag *Tag) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes whole tag in w if there is at least one frame. It returns the number of bytes written and error during the write. It returns nil as error if the write was successful.

func (*Tag) Year added in v0.7.1

func (tag *Tag) Year() string

type TextFrame added in v0.6.1

type TextFrame struct {
	Encoding Encoding
	Text     string
}

TextFrame is used to work with all text frames (all T*** frames like TIT2 (title), TALB (album) and so on).

Example (Add)
package main

import (
	"github.com/bogem/id3v2"
)

func main() {
	tag := id3v2.NewEmptyTag()
	textFrame := id3v2.TextFrame{
		Encoding: id3v2.EncodingUTF8,
		Text:     "Happy",
	}
	tag.AddFrame(tag.CommonID("Mood"), textFrame)
}
Output:

Example (Get)
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	tf := tag.GetTextFrame(tag.CommonID("Mood"))
	fmt.Println(tf.Text)
}
Output:

func (TextFrame) Size added in v0.8.6

func (tf TextFrame) Size() int

func (TextFrame) WriteTo added in v0.8.6

func (tf TextFrame) WriteTo(w io.Writer) (int64, error)

type UFIDFrame added in v1.1.0

type UFIDFrame struct {
	OwnerIdentifier string
	Identifier      []byte
}

func (UFIDFrame) Size added in v1.1.0

func (ufid UFIDFrame) Size() int

func (UFIDFrame) WriteTo added in v1.1.0

func (ufid UFIDFrame) WriteTo(w io.Writer) (n int64, err error)

type UnknownFrame added in v0.8.1

type UnknownFrame struct {
	Body []byte
}

UnknownFrame is used for frames, which id3v2 so far doesn't know how to parse and write it. It just contains an unparsed byte body of the frame.

func (UnknownFrame) Size added in v0.8.6

func (uf UnknownFrame) Size() int

func (UnknownFrame) WriteTo added in v0.8.6

func (uf UnknownFrame) WriteTo(w io.Writer) (n int64, err error)

type UnsynchronisedLyricsFrame added in v0.6.1

type UnsynchronisedLyricsFrame struct {
	Encoding          Encoding
	Language          string
	ContentDescriptor string
	Lyrics            string
}

UnsynchronisedLyricsFrame is used to work with USLT frames. The information about how to add unsynchronised lyrics/text frame to tag you can see in the docs to tag.AddUnsynchronisedLyricsFrame function.

You must choose a three-letter language code from ISO 639-2 code list: https://www.loc.gov/standards/iso639-2/php/code_list.php

Example (Add)
package main

import (
	"github.com/bogem/id3v2"
)

func main() {
	tag := id3v2.NewEmptyTag()
	uslt := id3v2.UnsynchronisedLyricsFrame{
		Encoding:          id3v2.EncodingUTF8,
		Language:          "ger",
		ContentDescriptor: "Deutsche Nationalhymne",
		Lyrics:            "Einigkeit und Recht und Freiheit...",
	}
	tag.AddUnsynchronisedLyricsFrame(uslt)
}
Output:

Example (Get)
package main

import (
	"fmt"
	"log"

	"github.com/bogem/id3v2"
)

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

	uslfs := tag.GetFrames(tag.CommonID("Unsynchronised lyrics/text transcription"))
	for _, f := range uslfs {
		uslf, ok := f.(id3v2.UnsynchronisedLyricsFrame)
		if !ok {
			log.Fatal("Couldn't assert USLT frame")
		}

		// Do something with USLT frame.
		// For example, print the lyrics:
		fmt.Println(uslf.Lyrics)
	}
}
Output:

func (UnsynchronisedLyricsFrame) Size added in v0.8.6

func (uslf UnsynchronisedLyricsFrame) Size() int

func (UnsynchronisedLyricsFrame) WriteTo added in v0.8.6

func (uslf UnsynchronisedLyricsFrame) WriteTo(w io.Writer) (n int64, err error)

type UserDefinedTextFrame added in v1.1.0

type UserDefinedTextFrame struct {
	Encoding    Encoding
	Description string
	Value       string
}

UserDefinedTextFrame is used to work with TXXX frames. There can be many UserDefinedTextFrames but the Desciption fields need to be unique.

func (UserDefinedTextFrame) Size added in v1.1.0

func (udtf UserDefinedTextFrame) Size() int

func (UserDefinedTextFrame) WriteTo added in v1.1.0

func (udtf UserDefinedTextFrame) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL