Code Monkey home page Code Monkey logo

id3-go's Introduction

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)

id3-go's People

Contributors

gerow avatar mikkyang avatar viking avatar xhenner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.