govd/plugins/merge_audio.go
stefanodvx 3faede7b1c Init
2025-04-14 13:05:43 +02:00

40 lines
747 B
Go

package plugins
import (
"context"
"fmt"
"govd/models"
"govd/util"
"govd/util/av"
"github.com/pkg/errors"
)
func MergeAudio(media *models.DownloadedMedia) error {
audioFormat := media.Media.GetDefaultAudioFormat()
if audioFormat == nil {
return errors.New("no audio format found")
}
// download the audio file
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
audioFile, err := util.DownloadFile(
ctx, audioFormat.URL,
audioFormat.GetFileName(), nil,
)
if err != nil {
return fmt.Errorf("failed to download audio file: %w", err)
}
err = av.MergeVideoWithAudio(
media.FilePath,
audioFile,
)
if err != nil {
return fmt.Errorf("failed to merge video with audio: %w", err)
}
return nil
}