govd/plugins/merge_audio.go
stefanodvx c8d0666d1d
Some checks failed
telegram message / notify (push) Has been cancelled
fixes (desc)
- m3u8 parser
- segments download
- video-audio merge
2025-04-23 01:44:25 +02:00

52 lines
963 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()
var audioFile string
var err error
if len(audioFormat.Segments) == 0 {
audioFile, err = util.DownloadFile(
ctx, audioFormat.URL,
audioFormat.GetFileName(),
nil,
)
} else {
audioFile, err = util.DownloadFileWithSegments(
ctx, audioFormat.Segments,
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
}