id3v2

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2016 License: MIT Imports: 9 Imported by: 0

README

ID3v2

IMHO

I think, ID3v2 is a very overwhelmed standard: it does more than it really should do. There are a lot of aspects, which developer should take into consideration. And that's why it's pretty complicated to write a good library. So if you have some thoughts about writing a new simply and elegant standard for providing information for digital music tracks, just write me. I think, it's a good time to write an appropriate standard for it 😉

Information

Stable and fast ID3v2 Library written in Go

This library can only set and write tags, but can't read them. So if you only want to set tags, it fits you. And if there is a tag of version 3 or 4, this library will just delete it.

What it can do:

  • Set artist, album, year, genre and attached pictures (e.g. album covers) and write all to file
  • Set several attached pictures
  • Work with only one encoding (UTF-8)

What it can't do:

  • Parse tags
  • Work with extended header, flags, padding
  • Work with encodings, except UTF-8

If you want some functionality, that library can't do, just write an issue. I will implement it as fast as I can

And of course, pull requests are welcome!

Benchmarks

All benchmarks run on MacBook Air 13" (early 2013, 1,4GHz Intel Core i5, 4GB 1600MHz DDR3)

Set title, artist, album, year, genre and 50KB picture to 4,6MB MP3:
BenchmarkSet-4	     200	   9857336 ns/op	  148739 B/op	      51 allocs/op

Installation

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

Usage

Example:
package main

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

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

  tag.SetArtist("Artist")
  tag.SetTitle("Title")
  tag.SetYear("2016")
  ...


  if err = tag.Flush(); err != nil {
    log.Fatal("Error while closing a tag: ", err)
  }
}

Available functions for setting text frames:
tag.SetTitle(title string)
tag.SetArtist(artist string)
tag.SetAlbum(album string)
tag.SetYear(year string)
tag.SetGenre(genre string)
Setting a picture:
package main

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

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

  pic := id3v2.NewAttachedPicture()
  pic.SetMimeType("image/jpeg")
  pic.SetDescription("Cover")
  pic.SetPictureType("Cover (front)")

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

  if err = pic.SetPictureFromFile(artwork); err != nil {
    log.Fatal("Error while setting a picture from file: ", err)
  }
  if err = tag.SetAttachedPicture(pic); err != nil {
		t.Error("Error while setting a picture frame to tag: ", err)
  }

  if err = tag.Flush(); err != nil {
    log.Fatal("Error while closing a tag: ", err)
  }
}

Available picture types:

  • Other
  • File icon
  • Other file icon
  • Cover (front)
  • Cover (back)
  • Leaflet page
  • Media
  • Lead artist
  • Artist
  • Conductor
  • Band/Orchestra
  • Composer
  • Lyricist/text writer
  • Recording Location
  • During recording
  • During performance
  • Movie/video screen capture
  • A bright coloured fish
  • Illustration
  • Band/artist logotype
  • Publisher/Studio logotype

TODO

  • Parse tags
  • Work with other encodings
  • Work with extended header, flags, padding (Does somebody really use it?)

License

MIT

Documentation

Index

Constants

View Source
const (
	ID3Identifier = "ID3"
	TagHeaderSize = 10
)

Variables

This section is empty.

Functions

func FormTagHeader

func FormTagHeader(h TagHeader) ([]byte, error)

func NewAttachedPicture

func NewAttachedPicture() *frame.PictureFrame

Types

type Tag

type Tag struct {
	Header *TagHeader

	File         *os.File
	OriginalSize uint32
	// contains filtered or unexported fields
}

func NewTag

func NewTag(file *os.File) *Tag

func Open

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

func ParseTag

func ParseTag(file *os.File) (*Tag, error)

func (*Tag) Flush added in v0.1.2

func (t *Tag) Flush() error

func (Tag) FormFrames

func (t Tag) FormFrames() ([]byte, error)

func (*Tag) SetAlbum

func (t *Tag) SetAlbum(album string)

func (*Tag) SetArtist

func (t *Tag) SetArtist(artist string)

func (*Tag) SetAttachedPicture

func (t *Tag) SetAttachedPicture(pf frame.PictureFramer) error

func (*Tag) SetGenre

func (t *Tag) SetGenre(genre string)

func (*Tag) SetTextFrame

func (t *Tag) SetTextFrame(id string, text string)

func (*Tag) SetTitle

func (t *Tag) SetTitle(title string)

func (*Tag) SetYear

func (t *Tag) SetYear(year string)

type TagHeader

type TagHeader struct {
	FramesSize uint32
	Version    byte
}

func ParseHeader

func ParseHeader(r io.Reader) (*TagHeader, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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