flacpicture

package module
v0.3.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: 7 Imported by: 20

README

flacpicture

Documentation Build Status Coverage Status

FLAC picture metablock manipulation for go-flac

Examples

The following example adds a jpeg image as front cover to the FLAC metadata.

package example

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

func addFLACCover(fileName string, imgData []byte) {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
	picture, err := flacpicture.NewFromImageData(flacpicture.PictureTypeFrontCover, "Front cover", imgData, "image/jpeg")
	if err != nil {
		panic(err)
	}
	picturemeta := picture.Marshal()
	f.Meta = append(f.Meta, &picturemeta)
	f.Save(fileName)
}

The following example extracts an existing cover from a FLAC file

package example

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

func extractFLACCover(fileName string) *flacpicure.MetadataBlockPicture {
	f, err := flac.ParseFile(fileName)
	if err != nil {
		panic(err)
	}
    
    var pic *flacpicure.MetadataBlockPicture
	for _, meta := range f.Meta {
		if meta.Type == flac.Picture {
			pic, err = flacpicure.ParseFromMetaDataBlock(*meta)
			if err != nil {
				panic(err)
			}
		}
    }
    return pic
}

Documentation

Index

Constants

View Source
const (
	// MIMEURL is the MIME string indicating that imgData is a URL pointing to the image
	MIMEURL = "-->"
)

Variables

View Source
var (
	// 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")
)

Functions

This section is empty.

Types

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 ParseFromMetaDataBlock added in v0.2.0

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

ParseFromMetaDataBlock parses an existing picture MetaDataBlock

func (*MetadataBlockPicture) Marshal

Marshal encodes the PictureBlock to a standard FLAC MetaDataBloc to be accepted by go-flac

func (*MetadataBlockPicture) ParsePicture added in v0.2.0

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

PictureType defines the type of this image

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

Jump to

Keyboard shortcuts

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