mp3mp4tag

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

README

mp3-mp4-tag

ID3/MP4/VorbisComment 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.

Simply use the OpenTag() function with a string file path as the argument and the library will return the IDTag.

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

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

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 MIMEType = "application/ogg"

The MIME type as defined in RFC 3534.

Variables

View Source
var ErrBadSegs = errors.New("invalid segment table size")

ErrBadSegs error is thrown when an attempt is made to decode a page with a segment table size less than 1.

Functions

func GetFileType added in v1.2.3

func GetFileType(filepath string) (*string, error)

func ReadAtoms

func ReadAtoms(r io.ReadSeeker) (metadataMP4, error)

ReadAtoms reads MP4 metadata atoms from the io.ReadSeeker into a Metadata, returning non-nil error if there was a problem.

func ReadFromMP4

func ReadFromMP4(r io.ReadSeeker) (metadataMP4, error)

func SaveTag

func SaveTag(tag *IDTag) error

This operation saves the corresponding IDTag to the mp3/mp4 file that it references and returns an error if the saving process fails

Types

type ErrBadCrc added in v1.2.0

type ErrBadCrc struct {
	Found    uint32
	Expected uint32
}

ErrBadCrc error occurs when the CRC field in an ogg page doesn't match the CRC calculated by the Decoder.

func (ErrBadCrc) Error added in v1.2.0

func (bc ErrBadCrc) Error() string

Error function to return a formatted error message

type IDTag

type IDTag struct {
	// 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 both mp3 and mp4. 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 OpenTag

func OpenTag(filepath string) (*IDTag, error)

Opens the ID tag for the corresponding file as long as it is a supported filetype Use the OpenTag command and you will be able to access all metadata associated with the file

func ReadOGGTags added in v1.2.0

func ReadOGGTags(r io.Reader) (*IDTag, error)

ReadOGGTags reads OGG metadata from the io.ReadSeeker, returning the resulting metadata in a Metadata implementation, or non-nil error if there was a problem.

func (*IDTag) AdditionalTags added in v1.2.1

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

Get all additional (unmapped) tags

func (*IDTag) Album

func (tag *IDTag) Album() string

Get the album for a tag

func (*IDTag) AlbumArt

func (tag *IDTag) AlbumArt() *image.Image

Get the album art for the tag as an *image.Image

func (*IDTag) AlbumArtist

func (tag *IDTag) AlbumArtist() string

Get the album artist for a tag

func (*IDTag) Artist

func (tag *IDTag) Artist() string

Get the artist for a tag

func (*IDTag) BPM

func (tag *IDTag) BPM() string

Get the BPM for a tag

func (*IDTag) ClearAllAdditionalTags added in v1.2.1

func (tag *IDTag) ClearAllAdditionalTags()

func (*IDTag) ClearAllTags

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

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

Get the commnets for a tag

func (*IDTag) Composer

func (tag *IDTag) Composer() string

Get the composer for a tag

func (*IDTag) CopyrightMsg

func (tag *IDTag) CopyrightMsg() string

Get the Copyright Messgae for a tag

func (*IDTag) Date

func (tag *IDTag) Date() string

Get the date for a tag

func (*IDTag) EncodedBy

func (tag *IDTag) EncodedBy() string

Get who encoded the tag

func (*IDTag) FileType

func (tag *IDTag) FileType() string

Get the filetype of the tag

func (*IDTag) Genre

func (tag *IDTag) Genre() string

Get the genre for a tag

func (*IDTag) Language

func (tag *IDTag) Language() string

Get the language of the tag

func (*IDTag) Length

func (tag *IDTag) Length() string

Get the langth of the tag

func (*IDTag) Lyricist

func (tag *IDTag) Lyricist() string

Get the lyricist for the tag

func (*IDTag) PartOfSet

func (tag *IDTag) PartOfSet() string

Get if tag is part of a set

func (*IDTag) Publisher

func (tag *IDTag) Publisher() string

Get publisher for the tag

func (*IDTag) Save

func (tag *IDTag) Save() error

This operation saves the corresponding IDTag to the mp3/mp4 file that it references and returns an error if the saving process fails

func (*IDTag) SetAdditionalTag added in v1.2.1

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

Set an additional (unmapped) tag

func (*IDTag) SetAlbum

func (tag *IDTag) SetAlbum(album string)

Set the album for a tag

func (*IDTag) SetAlbumArtFromByteArray

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

Set the album art by passing a byte array for the album art

func (*IDTag) SetAlbumArtFromFilePath

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

Set the album art by passing a filepath as a string

func (*IDTag) SetAlbumArtFromImage

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

Set the album art by passing an *image.Image as the album art

func (*IDTag) SetAlbumArtist

func (tag *IDTag) SetAlbumArtist(albumArtist string)

Set teh album artist for a tag

func (*IDTag) SetAllAdditionalTags added in v1.2.1

func (tag *IDTag) SetAllAdditionalTags(set map[string]string)

Set a map for all additional tags

func (*IDTag) SetArtist

func (tag *IDTag) SetArtist(artist string)

Set the artist for a tag

func (*IDTag) SetBPM

func (tag *IDTag) SetBPM(bpm string)

Set the BPM for a tag

func (*IDTag) SetComments

func (tag *IDTag) SetComments(comments string)

Set the comments for a tag

func (*IDTag) SetComposer

func (tag *IDTag) SetComposer(composer string)

Set the composer for a tag

func (*IDTag) SetCopyrightMsg

func (tag *IDTag) SetCopyrightMsg(copyrightMsg string)

Set the Copyright Message for a tag

func (*IDTag) SetDate

func (tag *IDTag) SetDate(date string)

Set the date for a tag

func (*IDTag) SetEncodedBy

func (tag *IDTag) SetEncodedBy(encodedBy string)

Set who encoded the tag

func (*IDTag) SetFileType

func (tag *IDTag) SetFileType(fileType string)

Set the filtype of the tag

func (*IDTag) SetGenre

func (tag *IDTag) SetGenre(genre string)

Set the genre for a tag

func (*IDTag) SetLanguage

func (tag *IDTag) SetLanguage(language string)

Set the lanuguage of the tag

func (*IDTag) SetLength

func (tag *IDTag) SetLength(length string)

Set the length of the tag

func (*IDTag) SetLyricist

func (tag *IDTag) SetLyricist(lyricist string)

Set the lyricist for the tag

func (*IDTag) SetPartOfSet

func (tag *IDTag) SetPartOfSet(partOfSet string)

Set if the tag is part of a set

func (*IDTag) SetPublisher

func (tag *IDTag) SetPublisher(publisher string)

Set publihser for the tag

func (*IDTag) SetTitle

func (tag *IDTag) SetTitle(title string)

Set the title for a tag

func (*IDTag) SetYear

func (tag *IDTag) SetYear(year string)

Set the year for a tag

func (*IDTag) Title

func (tag *IDTag) Title() string

Get the title for a tag

func (*IDTag) Year

func (tag *IDTag) Year() string

Get the year for a tag

type IDTagExtended added in v1.2.1

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

type OGGDecoder added in v1.2.0

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

OGGDecoder is a structure that facilitates the page-by-page decoding of an ogg stream.

func NewOGGDecoder added in v1.2.0

func NewOGGDecoder(r io.Reader) *OGGDecoder

NewOGGDecoder is a constructor that initializes an ogg Decoder.

func (*OGGDecoder) DecodeOGG added in v1.2.0

func (d *OGGDecoder) DecodeOGG() (OGGPage, error)

/ Decode reads from the Reader of the Decoder until the next ogg page is found, then decodes and returns the Page or an error. An io.EOF error can be returned if that's what the Reader returns.

The memory for the returned Page's Packets' bytes is managed by the Decoder. It can be overwritten by subsequent calls to Decode.

It's safe to call Decode concurrently on different Decoders, provided their Readers are distinct. Otherwise, the outcome is not defined.

type OGGEncoder added in v1.2.0

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

Encoder converts raw bytes into an ogg stream.

func NewOGGEncoder added in v1.2.0

func NewOGGEncoder(id uint32, w io.Writer) *OGGEncoder

NewEncoder initializes an ogg encoder with a given serial ID. When using multiple Encoders for multiplexed logical streams, ensure unique IDs. Encode streams as per ogg RFC for Grouping and Chaining.

func (*OGGEncoder) Encode added in v1.2.0

func (w *OGGEncoder) Encode(granule int64, packets [][]byte) error

Encode writes a data packet to the ogg stream with a given granule position. Large packets are split across multiple pages with continuation-of-packet flag set. Packets can be empty or nil, resulting in a single segment of size 0.

func (*OGGEncoder) EncodeBOS added in v1.2.0

func (w *OGGEncoder) EncodeBOS(granule int64, packets [][]byte) error

EncodeBOS writes a beginning-of-stream packet to the ogg stream with a given granule position. Large packets are split across multiple pages with continuation-of-packet flag set. Packets can be empty or nil, resulting in a single segment of size 0.

func (*OGGEncoder) EncodeEOS added in v1.2.0

func (w *OGGEncoder) EncodeEOS(granule int64, packets [][]byte) error

EncodeEOS writes a end-of-stream packet to the ogg stream. Packets can be empty or nil, resulting in a single segment of size 0.

type OGGPage added in v1.2.0

type OGGPage struct {
	// Type is a bitmask of COP, BOS, and/or EOS.
	Type byte
	// Serial represents the bitstream serial number.
	Serial uint32
	// Granule represents the granule position, its interpretation depends on the encapsulated codec.
	Granule int64
	// Packets are the actual packet data.
	// If Type & COP != 0, the first element is
	// a continuation of the previous page's last packet.
	Packets [][]byte
}

Page struct represents a logical unit of an ogg page.

type Picture

type Picture struct {
	Ext         string // Extension of the picture file.
	MIMEType    string // MIMEType of the picture.
	Type        string // Type of the picture (see pictureTypes).
	Description string // Description.
	Data        []byte // Raw picture data.
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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