id3v24

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 10 Imported by: 0

README

github.com/sa6mwa/id3v24

This is a Go package that extends https://github.com/bogem/id3v2 with structured chapter — CHAP — and CTOC frame support and writing ID3v2.4 tags. Main use case is in mkpod available from https://github.com/sa6mwa/mkpod.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadChapterStartTime error = errors.New("bad chapter start time format (expected HH:MM:SS.mmm)")
	ErrZeroDuration        error = errors.New("duration can not be zero")
)

Functions

func AddCHAPAndCTOC

func AddCHAPAndCTOC(duration mp3duration.Info, tag *id3v2.Tag, chapters []Chapter) error

AddCHAPAndCTOC adds each CHAP and a final CTOC frame to tag from a slice of Chapter structs. duration is an Info struct returned by mp3duration.Read or ReadFile as AddCHAPAndCTOC need to know the duration of the underlying MP3 in order to calculate end of last chapter. If chapters is an empty slice, no frames will be added. Returns error if something failed, in which case tag is to be considered corrupt (should not be saved via tag.Save).

func AddCoverJPEG

func AddCoverJPEG(tag *id3v2.Tag, jpegPath string) error

AddCoverJPEG adds a cover picture (jpegPath) to tag or return error.

func GetFFmpegChaptersTXT added in v0.2.0

func GetFFmpegChaptersTXT(duration mp3duration.Info, chapters []Chapter) ([]byte, error)

GetFFmpegChaptersTXT returns a chapters.txt file for use with FFmpeg when generating e.g m4b files. Maybe strange to also support ffmpeg and m4b in a package for MP3 ID3 tags, but the functionality is already here and chapters in m4b is much better. Returns a chapters.txt as a byte slice or error if something failed.

func GetMP3Duration

func GetMP3Duration(mp3path string) (time.Duration, error)

func StringTimeToMillis added in v0.4.0

func StringTimeToMillis(t string) (uint32, error)

func StringTimeToTime added in v0.4.0

func StringTimeToTime(t string) (time.Time, error)

func TextFrame

func TextFrame(title string) []byte

TextFrame returns an UTF-16 ID3v2.4 Text Frame from title string.

func WriteFFmpegChaptersTXT added in v0.2.0

func WriteFFmpegChaptersTXT(duration mp3duration.Info, chapters []Chapter) (string, error)

WriteFFmpegChaptersTXT returns a temporary (os.CreateTemp) ffmpeg-compatible chapters.txt file for use if generating e.g an m4b instead of an mp3. Returns full path to tempfile or error if something failed.

func WriteFFmpegMetadataFile added in v0.2.0

func WriteFFmpegMetadataFile(duration time.Duration, input TrackInfo) (string, error)

WriteFFmpegMetadataFile returns a temporary (os.CreateTemp) ffmpeg-compatible metadata file for use with illustrative example:

ffmpeg -i input.flac output.m4a
ffmpeg -i output.m4a -i metadata.txt -map_metadata 1 -codec copy final_output.m4a

Returns full path to tempfile or error if something failed.

func WriteID3v2Tag

func WriteID3v2Tag(mp3file string, input TrackInfo) error

WriteID3v2Tag writes everything this package is designed for; title, album, arist, genre, year, cover picture (jpeg), and chapters. If any field is empty (zero length or empty slice, etc), it will not be added to the tag. The output mp3 will be modified.

Types

type Chapter

type Chapter struct {
	Title string `json:"title" yaml:"title,omitempty"`
	Start string `json:"start" yaml:"start,omitempty"` // e.g. "00:05:00.500"
}

type TrackInfo

type TrackInfo struct {
	Title       string    `json:"title" yaml:"title,omitempty"`
	Album       string    `json:"album" yaml:"album,omitempty"`
	Artist      string    `json:"artist" yaml:"artist,omitempty"`
	Genre       string    `json:"genre" yaml:"genre,omitempty"`
	Year        string    `json:"year" yaml:"year,omitempty"`
	Date        time.Time `json:"date" yaml:"date,omitempty"` // yyyy-mm-dd
	Track       string    `json:"track" yaml:"track,omitempty"`
	Comment     string    `json:"comment" yaml:"comment,omitempty"`
	Description string    `json:"description" yaml:"description,omitempty"`
	Language    string    `json:"language" yaml:"language,omitempty"`
	Copyright   string    `json:"copyright" yaml:"copyright,omitempty"`
	CoverJPEG   string    `json:"coverJPEG" yaml:"coverJPEG,omitempty"`
	Chapters    []Chapter `json:"chapters" yaml:"chapters,omitempty"`
}

Jump to

Keyboard shortcuts

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