flacvorbis

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 23

README

flacvorbis

Documentation Build Status Coverage Status

FLAC vorbis comment metablock manipulation for go-flac

Examples

The following example extracts existing tags from a FLAC file. It returns the last vorbis comment block and also the corresponding index of the metadata, which could be used for updating later on.

package example

import (
    "github.com/go-flac/flacvorbis"
    "github.com/go-flac/go-flac"
)

func extractFLACComment(fileName string) (*flacvorbis.MetadataBlockVorbisComment, int) {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
    
	var cmt *flacvorbis.MetadataBlockVorbisComment
	var cmtIdx int
	for idx, meta := range f.Meta {
		if meta.Type == flac.VorbisComment {
			cmt, err = flacvorbis.ParseFromMetaDataBlock(*meta)
			cmtIdx = idx
			if err != nil {
				panic(err)
			}
		}
    	}
	return cmt, cmtIdx
}

The following example adds a title to the FLAC metadata. It considers whether there is already an existing vorbis comment block and updates it accordingly or otherwise creates a new one. Only add a new entry if you are sure there is none existing, multiple entries can be misleading for some audio players.

package example

import (
    "github.com/go-flac/flacvorbis"
    "github.com/go-flac/go-flac"
)

func addFLACTitle(fileName string, title []byte) {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
	cmts, idx := extractFLACComment(f)
	if cmts == nil && idx > 0 {
		cmts = flacvorbis.New()
	}
	cmts.Add(flacvorbis.FIELD_TITLE, title)
	cmtsmeta := cmts.Marshal()
	if idx > 0 {	
		f.Meta[idx] = &cmtsmeta
	} else {
		f.Meta = append(f.Meta, &cmtsmeta)
	}
	f.Save(fileName)
}

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_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 (
	APP_VERSION = "0.1.0"
)

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")
)

Functions

This section is empty.

Types

type MetaDataBlockVorbisComment

type MetaDataBlockVorbisComment struct {
	Vendor   string
	Comments []string
}

func New

New creates a new MetaDataBlockVorbisComment vendor is set to flacvorbis <version> by default

func ParseFromMetaDataBlock

func ParseFromMetaDataBlock(meta flac.MetaDataBlock) (*MetaDataBlockVorbisComment, error)

ParseFromMetaDataBlock parses an existing picture MetaDataBlock

func (*MetaDataBlockVorbisComment) Add

func (c *MetaDataBlockVorbisComment) Add(key string, val string) error

Add adds a key-val pair to the comments

func (*MetaDataBlockVorbisComment) Get

func (c *MetaDataBlockVorbisComment) Get(key string) ([]string, error)

Get get all comments with field name specified by the key parameter If there is no match, error would still be nil

func (MetaDataBlockVorbisComment) Marshal

Marshal marshals this block back into a flac.MetaDataBlock

Jump to

Keyboard shortcuts

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