flacmeta

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0, MIT Imports: 11 Imported by: 1

README

FLACMETA

FLACMeta is an adaptation of go-flac. The purpose is to provide an interface for audiometa v3. FLACMeta modifies go-flac by not reading the entire file to memory, only the metadata is read to memory. When saving the data, FLACMeta copies stream data directly from the reader to the writer. FLACMeta removes all comment blocks and picture blocks from the file and replaces them with updated blocks. FLACMeta offers reading and writing of many popular vorbis tags.

Acknowledgements

go-flac This library gets a lot of its code and its inspiration from the go-flac library. Thank you go-flac.

License

This project is licensed under the MIT License. See the LICENSE file for details. Parts of this project are licensed under the Apache 2.0 License. See the LICENSE file for details.

AudioMeta v3

MP3Meta

MP4Meta

OGGMeta

Documentation

Index

Constants

View Source
const (
	// FIELD_TITLE Track/Work name
	FIELD_TITLE = "TITLE"
	// FIELD_VERSION The version field may be used to differentiate multiple versions of the same track title in a single collection. (e.g. remix info)
	FIELD_VERSION = "VERSION"
	// FIELD_ALBUM The collection name to which this track belongs
	FIELD_ALBUM = "ALBUM"
	// FIELD_TRACKNUMBER The track number of this piece if part of a specific larger collection or album
	FIELD_TRACKNUMBER = "TRACKNUMBER"
	// FIELD_ARTIST The artist generally considered responsible for the work. In popular music this is usually the performing band or singer. For classical music it would be the composer. For an audio book it would be the author of the original text.
	FIELD_ARTIST      = "ARTIST"
	FIELD_ALBUMARTIST = "ALBUMARTIST"
	FIELD_BPM         = "BPM"
	FIELD_COMPOSER    = "COMPOSER"
	FIELD_DISCNUMBER  = "DISCNUMBER"
	FIELD_DISCTOTAL   = "DISCTOTAL"
	FIELD_ENCODER     = "ENCODER"
	FIELD_TRACKTOTAL  = "TRACKTOTAL"
	// FIELD_PERFORMER The artist(s) who performed the work. In classical music this would be the conductor, orchestra, soloists. In an audio book it would be the actor who did the reading. In popular music this is typically the same as the ARTIST and is omitted.
	FIELD_PERFORMER = "PERFORMER"
	// FIELD_COPYRIGHT Copyright attribution, e.g., '2001 Nobody's Band' or '1999 Jack Moffitt'
	FIELD_COPYRIGHT = "COPYRIGHT"
	// FIELD_LICENSE License information, eg, 'All Rights Reserved', 'Any Use Permitted', a URL to a license such as a Creative Commons license ("www.creativecommons.org/blahblah/license.html") or the EFF Open Audio License ('distributed under the terms of the Open Audio License. see http://www.eff.org/IP/Open_licenses/eff_oal.html for details'), etc.
	FIELD_LICENSE = "LICENSE"
	// FIELD_ORGANIZATION Name of the organization producing the track (i.e. the 'record label')
	FIELD_ORGANIZATION = "ORGANIZATION"
	// FIELD_DESCRIPTION A short text description of the contents
	FIELD_DESCRIPTION = "DESCRIPTION"
	// FIELD_GENRE A short text indication of music genre
	FIELD_GENRE = "GENRE"
	// FIELD_DATE Date the track was recorded
	FIELD_DATE = "DATE"
	// FIELD_LOCATION Location where track was recorded
	FIELD_LOCATION = "LOCATION"
	// FIELD_CONTACT Contact information for the creators or distributors of the track. This could be a URL, an email address, the physical address of the producing label.
	FIELD_CONTACT = "CONTACT"
	// FIELD_ISRC ISRC number for the track; see the ISRC intro page for more information on ISRC numbers.
	FIELD_ISRC = "ISRC"
)
View Source
const (
	// MIMEURL is the MIME string indicating that imgData is a URL pointing to the image
	MIMEURL = "-->"
)

Variables

View Source
var (
	ErrorNotVorbisComment = errors.New("not a vorbis comment metadata block")
	ErrorUnexpEof         = errors.New("unexpected end of stream")
	ErrorMalformedComment = errors.New("malformed comment")
	ErrorInvalidFieldName = errors.New("malformed field Name")
	// ErrorNotPictureMetadataBlock is returned if the metadata provided is not a picture block.
	ErrorNotPictureMetadataBlock = errors.New("not a picture metadata block")
	// ErrorUnsupportedMIME is returned if the provided image MIME type is unsupported.
	ErrorUnsupportedMIME = errors.New("unsupported MIME")
	// ErrorNoFLACHeader indicates that "fLaC" marker not found at the beginning of the file
	ErrorNoFLACHeader = errors.New("fLaC head incorrect")
	// ErrorNoStreamInfo indicates that StreamInfo Metablock not present or is not the first Metablock
	ErrorNoStreamInfo = errors.New("stream info not present")
	// ErrorStreamInfoEarlyEOF indicates that an unexpected EOF is hit while reading StreamInfo Metablock
	ErrorStreamInfoEarlyEOF = errors.New("unexpected end of stream while reading stream info")
	// ErrorNoSyncCode indicates that the frames are malformed as the sync code is not present after the last Metablock
	ErrorNoSyncCode = errors.New("frames do not begin with sync code")
)

Functions

This section is empty.

Types

type BlockData

type BlockData []byte

BlockData data in a FLAC Metadata Block. Custom Metadata decoders and modifiers should accept/modify whole MetaDataBlock instead.

type BlockType

type BlockType int

BlockType representation of types of FLAC Metadata Block

const (
	// StreamInfo METADATA_BLOCK_STREAMINFO
	// This block has information about the whole stream, like sample rate, number of channels, total number of samples, etc. It must be present as the first metadata block in the stream. Other metadata blocks may follow, and ones that the decoder doesn't understand, it will skip.
	StreamInfo BlockType = iota
	// Padding METADATA_BLOCK_PADDING
	// This block allows for an arbitrary amount of padding. The contents of a PADDING block have no meaning. This block is useful when it is known that metadata will be edited after encoding; the user can instruct the encoder to reserve a PADDING block of sufficient size so that when metadata is added, it will simply overwrite the padding (which is relatively quick) instead of having to insert it into the right place in the existing file (which would normally require rewriting the entire file).
	Padding
	// Application METADATA_BLOCK_APPLICATION
	// This block is for use by third-party applications. The only mandatory field is a 32-bit identifier. This ID is granted upon request to an application by the FLAC maintainers. The remainder is of the block is defined by the registered application. Visit the registration page if you would like to register an ID for your application with FLAC.
	Application
	// SeekTable METADATA_BLOCK_SEEKTABLE
	// This is an optional block for storing seek points. It is possible to seek to any given sample in a FLAC stream without a seek table, but the delay can be unpredictable since the bitrate may vary widely within a stream. By adding seek points to a stream, this delay can be significantly reduced. Each seek point takes 18 bytes, so 1% resolution within a stream adds less than 2k. There can be only one SEEKTABLE in a stream, but the table can have any number of seek points. There is also a special 'placeholder' seekpoint which will be ignored by decoders but which can be used to reserve space for future seek point insertion.
	SeekTable
	// VorbisComment METADATA_BLOCK_VORBIS_COMMENT
	// This block is for storing a list of human-readable name/value pairs. Values are encoded using UTF-8. It is an implementation of the Vorbis comment specification (without the framing bit). This is the only officially supported tagging mechanism in FLAC. There may be only one VORBIS_COMMENT block in a stream. In some external documentation, Vorbis comments are called FLAC tags to lessen confusion.
	VorbisComment
	// CueSheet METADATA_BLOCK_CUESHEET
	// This block is for storing various information that can be used in a cue sheet. It supports track and index points, compatible with Red Book CD digital audio discs, as well as other CD-DA metadata such as media catalog number and track ISRCs. The CUESHEET block is especially useful for backing up CD-DA discs, but it can be used as a general purpose cueing mechanism for playback.
	CueSheet
	// Picture METADATA_BLOCK_PICTURE
	// This block is for storing pictures associated with the file, most commonly cover art from CDs. There may be more than one PICTURE block in a file. The picture format is similar to the APIC frame in ID3v2. The PICTURE block has a type, MIME type, and UTF-8 description like ID3v2, and supports external linking via URL (though this is discouraged). The differences are that there is no uniqueness constraint on the description field, and the MIME type is mandatory. The FLAC PICTURE block also includes the resolution, color depth, and palette size so that the client can search for a suitable picture without having to scan them all.
	Picture
	// Reserved Reserved Metadata Block Types
	Reserved
	// Invalid Invalid Metadata Block Type
	Invalid BlockType = 127
)

type ErrInvalidFieldName

type ErrInvalidFieldName struct {
	Field string
}

func (*ErrInvalidFieldName) Error

func (e *ErrInvalidFieldName) Error() string

type FLACFile

type FLACFile struct {
	Meta         []*MetaDataBlock
	Frames       FrameData
	StreamReader io.ReadSeeker
}

func ParseBytes

func ParseBytes(f io.ReadSeeker) (*FLACFile, error)

ParseBytes accepts a reader to a FLAC stream and returns the final file

func ParseMetaGetStreamReader

func ParseMetaGetStreamReader(f io.ReadSeeker) (*FLACFile, error)

func ParseMetadata

func ParseMetadata(f io.ReadSeeker) (*FLACFile, error)

ParseMetadata accepts a reader to a FLAC stream and consumes only FLAC metadata Frames is always nil

func (*FLACFile) Marshal

func (c *FLACFile) Marshal() ([]byte, error)

func (*FLACFile) MarshalMeta

func (c *FLACFile) MarshalMeta() ([]byte, error)

type FLACTag

type FLACTag struct {
	Album        string
	AlbumArtist  string
	Artist       string
	BPM          int
	Contact      string
	Composer     string
	Copyright    string
	CoverArt     *image.Image
	Date         string
	Description  string
	DiscNumber   int
	DiscTotal    int
	Encoder      string
	Genre        string
	ISRC         string
	License      string
	Location     string
	Organization string
	Performer    string
	Title        string
	TrackNumber  int
	TrackTotal   int
	Version      string
	// contains filtered or unexported fields
}

func ReadFLAC

func ReadFLAC(r io.ReadSeeker) (*FLACTag, error)

func (*FLACTag) GetAlbum

func (f *FLACTag) GetAlbum() string

func (*FLACTag) GetAlbumArtist

func (f *FLACTag) GetAlbumArtist() string

func (*FLACTag) GetArtist

func (f *FLACTag) GetArtist() string

func (*FLACTag) GetBPM

func (f *FLACTag) GetBPM() int

func (*FLACTag) GetComposer

func (f *FLACTag) GetComposer() string

func (*FLACTag) GetContact

func (f *FLACTag) GetContact() string

func (*FLACTag) GetCopyright

func (f *FLACTag) GetCopyright() string

func (*FLACTag) GetCoverArt

func (f *FLACTag) GetCoverArt() *image.Image

func (*FLACTag) GetDate

func (f *FLACTag) GetDate() string

func (*FLACTag) GetDescription

func (f *FLACTag) GetDescription() string

func (*FLACTag) GetDiscNumber

func (f *FLACTag) GetDiscNumber() int

func (*FLACTag) GetDiscTotal

func (f *FLACTag) GetDiscTotal() int

func (*FLACTag) GetEncoder

func (f *FLACTag) GetEncoder() string

func (*FLACTag) GetGenre

func (f *FLACTag) GetGenre() string

func (*FLACTag) GetISRC

func (f *FLACTag) GetISRC() string

func (*FLACTag) GetLicense

func (f *FLACTag) GetLicense() string

func (*FLACTag) GetLocation

func (f *FLACTag) GetLocation() string

func (*FLACTag) GetOrganization

func (f *FLACTag) GetOrganization() string

func (*FLACTag) GetPerformer

func (f *FLACTag) GetPerformer() string

func (*FLACTag) GetTitle

func (f *FLACTag) GetTitle() string

func (*FLACTag) GetTrackNumber

func (f *FLACTag) GetTrackNumber() int

func (*FLACTag) GetTrackTotal

func (f *FLACTag) GetTrackTotal() int

func (*FLACTag) GetVersion

func (f *FLACTag) GetVersion() string

func (*FLACTag) Save

func (f *FLACTag) Save(w io.Writer) error

func (*FLACTag) SetAlbum

func (f *FLACTag) SetAlbum(album string)

func (*FLACTag) SetAlbumArtist

func (f *FLACTag) SetAlbumArtist(albumArtist string)

func (*FLACTag) SetArtist

func (f *FLACTag) SetArtist(artist string)

func (*FLACTag) SetBPM

func (f *FLACTag) SetBPM(bpm int)

func (*FLACTag) SetComposer

func (f *FLACTag) SetComposer(composer string)

func (*FLACTag) SetContact

func (f *FLACTag) SetContact(contact string)

func (*FLACTag) SetCopyright

func (f *FLACTag) SetCopyright(copyright string)

func (*FLACTag) SetCoverArt

func (f *FLACTag) SetCoverArt(coverArt *image.Image)

func (*FLACTag) SetDate

func (f *FLACTag) SetDate(date string)

func (*FLACTag) SetDescription

func (f *FLACTag) SetDescription(description string)

func (*FLACTag) SetDiscNumber

func (f *FLACTag) SetDiscNumber(discNumber int)

func (*FLACTag) SetDiscTotal

func (f *FLACTag) SetDiscTotal(discTotal int)

func (*FLACTag) SetEncoder

func (f *FLACTag) SetEncoder(encoder string)

func (*FLACTag) SetGenre

func (f *FLACTag) SetGenre(genre string)

func (*FLACTag) SetISRC

func (f *FLACTag) SetISRC(isrc string)

func (*FLACTag) SetLicense

func (f *FLACTag) SetLicense(license string)

func (*FLACTag) SetLocation

func (f *FLACTag) SetLocation(location string)

func (*FLACTag) SetOrganization

func (f *FLACTag) SetOrganization(organization string)

func (*FLACTag) SetPerformer

func (f *FLACTag) SetPerformer(performer string)

func (*FLACTag) SetTitle

func (f *FLACTag) SetTitle(title string)

func (*FLACTag) SetTrackNumber

func (f *FLACTag) SetTrackNumber(trackNumber int)

func (*FLACTag) SetTrackTotal

func (f *FLACTag) SetTrackTotal(trackTotal int)

func (*FLACTag) SetVersion

func (f *FLACTag) SetVersion(version string)

type FrameData

type FrameData []byte

type MetaDataBlock

type MetaDataBlock struct {
	Type BlockType
	Data BlockData
}

MetaDataBlock is the struct representation of a FLAC Metadata Block

func (*MetaDataBlock) Marshal

func (c *MetaDataBlock) Marshal(isfinal bool) ([]byte, error)

type MetadataBlockPicture

type MetadataBlockPicture struct {
	PictureType       PictureType
	MIME              string
	Description       string
	Width             uint32
	Height            uint32
	ColorDepth        uint32
	IndexedColorCount uint32
	ImageData         []byte
}

MetadataBlockPicture represents a picture metadata block

func NewFromImageData

func NewFromImageData(pictype PictureType, description string, imgdata []byte, mime string) (*MetadataBlockPicture, error)

NewFromImageData generates a MetadataBlockPicture from image data, returns an error if the picture data connot be parsed

func ParsePicFromMetaDataBlock

func ParsePicFromMetaDataBlock(meta MetaDataBlock) (*MetadataBlockPicture, error)

ParseFromMetaDataBlock parses an existing picture MetaDataBlock

func (*MetadataBlockPicture) Marshal

func (c *MetadataBlockPicture) Marshal() (MetaDataBlock, error)

func (*MetadataBlockPicture) ParsePicture

func (c *MetadataBlockPicture) ParsePicture() error

ParsePicture decodes the image and inflated the Width, Height, ColorDepth, IndexedColorCount fields. This is called automatically by NewFromImageData

type PictureType

type PictureType uint32
const (
	PictureTypeOther PictureType = iota
	PictureTypeFileIcon
	PictureTypeOtherIcon
	PictureTypeFrontCover
	PictureTypeBackCover
	PictureTypeLeaflet
	PictureTypeMedia
	PictureTypeLeadArtist
	PictureTypeArtist
	PictureTypeConductor
	PictureTypeBand
	PictureTypeComposer
	PictureTypeLyricist
	PictureTypeRecordingLocation
	PictureTypeDuringRecording
	PictureTypeDuringPerformance
	PictureTypeScreenCapture
	PictureTypeBrightColouredFish
	PictureTypeIllustration
	PictureTypeBandArtistLogotype
	PictureTypePublisherStudioLogotype
)

type VorbisCommentBlock

type VorbisCommentBlock struct {
	Vendor   string
	Comments map[string]string
}

func NewVorbisCommentBlock

func NewVorbisCommentBlock() *VorbisCommentBlock

func ParseVorbisCommentFromMetaDataBlock

func ParseVorbisCommentFromMetaDataBlock(meta MetaDataBlock) (*VorbisCommentBlock, error)

func (*VorbisCommentBlock) DeleteComment

func (v *VorbisCommentBlock) DeleteComment(key string)

func (*VorbisCommentBlock) GetComment

func (v *VorbisCommentBlock) GetComment(key string) string

func (*VorbisCommentBlock) GetComments

func (v *VorbisCommentBlock) GetComments() map[string]string

func (*VorbisCommentBlock) GetVendor

func (v *VorbisCommentBlock) GetVendor() string

func (*VorbisCommentBlock) Marshal

func (v *VorbisCommentBlock) Marshal() (MetaDataBlock, error)

func (*VorbisCommentBlock) SetComment

func (v *VorbisCommentBlock) SetComment(key string, value string) error

func (*VorbisCommentBlock) SetVendor

func (v *VorbisCommentBlock) SetVendor(vendor string)

Jump to

Keyboard shortcuts

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