mp3joiner

package module
v0.0.0-...-0e151d4 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 14 Imported by: 0

README

MP3 Joiner

GoDoc Test Status Coverage Status Lint Status Go Report Card

Allow the merge of MP3 files while honoring chapter metadata. This library requires FFmeg to be installed on the target system.

Requirements

Example

package main

import (
 "github.com/jo-hoe/mp3-joiner"
)

func main() {
 builder := NewMP3Builder()
 builder.Append("/path/to/myAudioFile.mp3", 0, 10)
 builder.Append("/path/to/myOtherAudioFile.mp3", 0, -1)
 builder.Build("/path/to/mergedAudioFile.mp3")
}

Development

Linting

Project used golangci-lint for linting.

Installation

https://golangci-lint.run/usage/install/

Execution

Run the linting locally by executing

golangci-lint run ./...

in the working directory

Further Details

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEFAULT_TIME_BASE_INT = 1000000000
	DEFAULT_TIME_BASE     = fmt.Sprintf("1/%d", DEFAULT_TIME_BASE_INT)
	TIME_BASE_REGEX       = regexp.MustCompile("1/([0-9]*)")
)
View Source
var (
	ILLEGAL_METADATA_CHARATERS = regexp.MustCompile(`(#|;|=|\\)`)
	FFMPEG_STATS_REGEX         = regexp.MustCompile(`.+time=(?:.*)([0-9]{2,99}):([0-9]{2}):([0-9]{2}).([0-9]{2})`)
)

Functions

func GetBitrate

func GetBitrate(mp3Filepath string) (result int, err error)

func GetFFmpegMetadataTag

func GetFFmpegMetadataTag(mp3Filepath string) (result map[string]string, err error)

Gets a map of ffmpeg MP3 metadata tags. Note that the ID3 tags and ffmpeg tags are not equivalent. See this documentation for the mapping: https://wiki.multimedia.cx/index.php/FFmpeg_Metadata#MP3

func GetLengthInSeconds

func GetLengthInSeconds(mp3Filepath string) (result float64, err error)

This function does not read the length from the metadata of the file, as metadata and actual length can be inconsistent. Instead this implementation decodes the file and returns the actual length of the audio stream. This is slower but more accurate then reading the length from the metadata.

func SetFFmpegMetadataTag

func SetFFmpegMetadataTag(mp3Filepath string, metadata map[string]string, chapters []Chapter) (err error)

Sets FFmpeg MP3 metadata tag. Note that the ID3 tags and ffmpeg tags are not equivalent. See this documentation for the mapping: https://wiki.multimedia.cx/index.php/FFmpeg_Metadata#MP3

This function creates a new temp file and replaces the initial file.

Types

type Chapter

type Chapter struct {
	TimeBase string `json:"time_base,omitempty"`
	Start    int    `json:"start,omitempty"`
	End      int    `json:"end,omitempty"`
	Tags     Tags   `json:"tags,omitempty"`
	// contains filtered or unexported fields
}

func GetChapterMetadata

func GetChapterMetadata(mp3Filepath string) (result []Chapter, err error)

func (*Chapter) GetEndTimeInSeconds

func (c *Chapter) GetEndTimeInSeconds() float64

func (*Chapter) GetStartTimeInSeconds

func (c *Chapter) GetStartTimeInSeconds() float64

func (*Chapter) SetEndTime

func (c *Chapter) SetEndTime(seconds float64)

func (*Chapter) SetStartTime

func (c *Chapter) SetStartTime(seconds float64)

type MP3Builder

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

func NewMP3Builder

func NewMP3Builder() *MP3Builder

Builder that holds the added MP3 sections

func (*MP3Builder) Append

func (b *MP3Builder) Append(mp3Filepath string, startInSeconds float64, endInSeconds float64) (err error)

Adds a MP3 file to the builder. If endInSeconds is set to "-1" the stream will be read until the end of the file.

func (*MP3Builder) Build

func (b *MP3Builder) Build(filePath string) (err error)

Creates the MP3 file a the chosen path

type Tags

type Tags struct {
	Title string `json:"title,omitempty"`
}

Jump to

Keyboard shortcuts

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