audiometa

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

README

audiometa

MP3/MP4/FLAC/OGG tag reader and writer for go

Go Reference

This package allows you to parse and write ID tags for mp3, mp4 (m4a, m4b, m4p), FLAC, and ogg (Vorbis, OPUS) files.

This is the only package available in Go that uses native Go to allow writing of ogg vorbis metadata. As an added bonus I've added support for ogg OPUS as well.

You can access all of the fields of the IDTag through the accessor functions.

v2 massively improves memory management and speed. Several sections have been rewritten.

Fields that can be parsed:

MP3: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, BPM, ContentType, CopyrightMessage, Date, EncodedBy, Lyricist, FileType, Language, Length, PartOfSet, and Publisher

MP4: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, EncodedBy, and CopyrightMessage

FLAC: Artist, Album, AlbumArt, Date, Genre Title

OGG: Artist, AlbumArtist, Album, AlbumArt, Comment, Date, Genre, Title, Copyright, Publisher, Composer, and has extended support for all other custom or unmapped fields

Fields that can be written:

MP3: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, BPM, ContentType, CopyrightMessage, Date, EncodedBy, Lyricist, FileType, Language, Length, PartOfSet, and Publisher

MP4: Artist, AlbumArtist, Album, AlbumArt, Comments, Composer, Genre, Title, Year, and CopyrightMessage

FLAC: Artist, Album, AlbumArt, Genre, Title

OGG: Artist, AlbumArtist, Album, AlbumArt, Comment, Date, Genre, Title, Copyright, Publisher, Composer, and has extended support to allow for passthrough of unknown fields and adding any custom or unmapped field

Documentation

Overview

Package audiometa is an all in one solution for reading and writing audio meta data in Go. It's the only Go module available that can read and write OGG Vorbis and OGG Opus metadata. audiometa supports several different filetypes and a wide range of tags.

Index

Constants

View Source
const (
	// Continuation of packet
	COP byte = 1 << iota
	// Beginning of stream
	BOS = 1 << iota
	// End of stream
	EOS = 1 << iota
)
View Source
const (
	ALBUM  string = "album"
	ARTIST string = "artist"
	DATE   string = "date"
	TITLE  string = "title"
	GENRE  string = "genre"
)
View Source
const MIMEType = "application/ogg"

The MIME type as defined in RFC 3534.

Variables

View Source
var (
	ErrFLACParse    = errors.New("error parsing flac stream")
	ErrFLACCmtParse = errors.New("error parsing flac comment")

	ErrMP4AtomOutOfBounds  = errors.New("mp4 atom out of bounds")
	ErrMP4InvalidAtomSize  = errors.New("mp4 atom has invalid size")
	ErrMP4InvalidEncoding  = errors.New("invalid encoding: got wrong number of bytes")
	ErrMP4IlstAtomMissing  = errors.New("ilst atom is missing")
	ErrMP4InvalidCntntType = errors.New("invalid content type")

	ErrOggInvalidSgmtTblSz = errors.New("invalid segment table size")
	ErrOggInvalidHeader    = errors.New("invalid ogg header")
	ErrOggInvalidCRC       = errors.New("invalid CRC")
	ErrOggMissingCOP       = errors.New("missing ogg COP packet")
	ErrOggImgConfigFail    = errors.New("failed to get image config")
	ErrOggCodecNotSpprtd   = errors.New("unsupported codec for ogg")

	ErrMP3ParseFail = errors.New("error parsing mp3")

	ErrNoMethodAvlble = errors.New("no method available for this filetype")
)

Functions

func SaveTag

func SaveTag(tag *IDTag, w io.Writer) error

SaveTag saves the corresponding IDTag to the supplied io.Writer. It can be a bytes.Buffer, file, etc. If it's the same file as the input, audiometa creates a temp buffer to prevent a read/write circle.

Types

type FileType

type FileType string
const (
	MP3  FileType = "mp3"
	M4P  FileType = "m4p"
	M4A  FileType = "m4a"
	M4B  FileType = "m4b"
	MP4  FileType = "mp4"
	FLAC FileType = "flac"
	OGG  FileType = "ogg"
)

func GetFileType

func GetFileType(filepath string) (FileType, error)

GetFileType returns the file type of the file pointed to by filepath. If the filetype is not supported, an error is returned.

type IDTag

type IDTag struct {
	PassThrough map[string]string
	// contains filtered or unexported fields
}

The IDTag represents all of the metadata that can be retrieved from a file. The IDTag contains all tags for all audio types. Some tags may not be applicable to all types. Only the valid types are written to the respective data files. Although a tag may be set, if the function to write that tag attribute doesn't exist, the tag attribute will be ignored and the save function will not produce an error.

func Open

func Open(r io.ReadSeeker, p ParseOptions) (*IDTag, error)

Open opens the tag for the passed in reader. It does not have to be a file, it can be a bytes.Reader, or any other interface that implements io.ReadSeeker

func OpenTagFromPath

func OpenTagFromPath(filepath string, p ...ParseOptions) (*IDTag, error)

OpenTagFromPath Opens the ID tag for the corresponding file as long as it is a supported filetype Use the OpenTagFromPath command and you will be able to access all metadata associated with the file If you don't pass ParseOptions this function will try to detect the filetype by the extension. If the extension can't be detected an error will occur.

func (*IDTag) AdditionalTags

func (tag *IDTag) AdditionalTags() map[string]string

AdditionalTags gets all additional (unmapped) tags

func (*IDTag) Album

func (tag *IDTag) Album() string

Album gets the album for a tag

func (*IDTag) AlbumArtist

func (tag *IDTag) AlbumArtist() string

AlbumArtist gets the album artist for a tag

func (*IDTag) Artist

func (tag *IDTag) Artist() string

Artist gets the artist for a tag

func (*IDTag) BPM

func (tag *IDTag) BPM() string

BPM gets the BPM for a tag as a string

func (*IDTag) ClearAllTags

func (tag *IDTag) ClearAllTags(preserveUnknown ...bool)

ClearAllTags clears all tags except the fileUrl tag which is used to reference the file, takes an optional parameter "preserveUnkown": when this is true passThroughMap is not cleared and unknown tags are preserved

func (*IDTag) Comments

func (tag *IDTag) Comments() string

Comments gets the comments for a tag

func (*IDTag) Composer

func (tag *IDTag) Composer() string

Composer gets the composer for a tag

func (*IDTag) CopyrightMsg

func (tag *IDTag) CopyrightMsg() string

CopyrightMs gets the Copyright Messgae for a tag

func (*IDTag) Date

func (tag *IDTag) Date() string

Date gets the date for a tag as a string

func (*IDTag) EncodedBy

func (tag *IDTag) EncodedBy() string

EncodedBy gets who encoded the tag

func (*IDTag) FileType

func (tag *IDTag) FileType() string

FileType gets the filetype of the tag

func (*IDTag) Genre

func (tag *IDTag) Genre() string

Genre gets the genre for a tag

func (*IDTag) Language

func (tag *IDTag) Language() string

Language gets the language of the tag

func (*IDTag) Length

func (tag *IDTag) Length() string

Length gets the length of the audio file

func (*IDTag) Lyricist

func (tag *IDTag) Lyricist() string

Lyricist gets the lyricist for the tag

func (*IDTag) PartOfSet

func (tag *IDTag) PartOfSet() string

PartOfSet gets if the track is part of a set

func (*IDTag) Publisher

func (tag *IDTag) Publisher() string

Publisher gets the publisher for the tag

func (*IDTag) Save

func (tag *IDTag) Save(w io.Writer) error

Save saves the corresponding IDTag to the audio file that it references and returns an error if the saving process fails

func (*IDTag) SetAdditionalTag

func (tag *IDTag) SetAdditionalTag(id string, value string)

SetAdditionalTag sets an additional (unmapped) tag taking an id and value (id,value) (ogg only)

func (*IDTag) SetAlbum

func (tag *IDTag) SetAlbum(album string)

SetAlbum sets the album for a tag

func (*IDTag) SetAlbumArtFromByteArray

func (tag *IDTag) SetAlbumArtFromByteArray(albumArt []byte) error

SetAlbumArtFromByteArray sets the album art by passing a byte array for the album art

func (*IDTag) SetAlbumArtFromFilePath

func (tag *IDTag) SetAlbumArtFromFilePath(filePath string) error

SetAlbumArtFromFilePath sets the album art by passing a filepath as a string

func (*IDTag) SetAlbumArtFromImage

func (tag *IDTag) SetAlbumArtFromImage(albumArt *image.Image)

SetAlbumArtFromImage sets the album art by passing an *image.Image as the album art

func (*IDTag) SetAlbumArtist

func (tag *IDTag) SetAlbumArtist(albumArtist string)

SetAlbumArtist sets the album artist for a tag

func (*IDTag) SetArtist

func (tag *IDTag) SetArtist(artist string)

SetArtist sets the artist for a tag

func (*IDTag) SetBPM

func (tag *IDTag) SetBPM(bpm string)

SetBPM sets the BPM for a tag

func (*IDTag) SetComments

func (tag *IDTag) SetComments(comments string)

SetComments sets the comments for a tag

func (*IDTag) SetComposer

func (tag *IDTag) SetComposer(composer string)

SetComposer sets the composer for a tag

func (*IDTag) SetCopyrightMsg

func (tag *IDTag) SetCopyrightMsg(copyrightMsg string)

SetCopyrightMsg sets the Copyright Message for a tag

func (*IDTag) SetDate

func (tag *IDTag) SetDate(date string)

SetDate sets the date for a tag

func (*IDTag) SetEncodedBy

func (tag *IDTag) SetEncodedBy(encodedBy string)

SetEncodedBy sets who encoded the tag

func (*IDTag) SetFileType

func (tag *IDTag) SetFileType(fileType string)

SetFileType sets the filtype of the tag

func (*IDTag) SetGenre

func (tag *IDTag) SetGenre(genre string)

SetGenre sets the genre for a tag

func (*IDTag) SetLanguage

func (tag *IDTag) SetLanguage(language string)

SetLanguage sets the lanuguage of the tag

func (*IDTag) SetLength

func (tag *IDTag) SetLength(length string)

SetLength sets the length of the audio file

func (*IDTag) SetLyricist

func (tag *IDTag) SetLyricist(lyricist string)

SetLyricist sets the lyricist for the tag

func (*IDTag) SetPartOfSet

func (tag *IDTag) SetPartOfSet(partOfSet string)

SetPartOfSet sets if the track is part of a set

func (*IDTag) SetPublisher

func (tag *IDTag) SetPublisher(publisher string)

SetPublisher sets the publisher for the tag

func (*IDTag) SetTitle

func (tag *IDTag) SetTitle(title string)

SetTitle sets the title for a tag

func (*IDTag) SetYear

func (tag *IDTag) SetYear(year string)

SetYear sets the year for a tag

func (*IDTag) Title

func (tag *IDTag) Title() string

Title gets the title for a tag

func (*IDTag) Year

func (tag *IDTag) Year() string

Year gets the year for a tag as a string

type MP4Delete

type MP4Delete []string

type ParseOptions

type ParseOptions struct {
	Format FileType
}

ParseOptions is a struct that is passed when parsing a tag. If included, you should set the format to one of the existing FileTypes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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