The goal of this rework is to make it so I can pass around platform.User instead of a pair of models.Organization and models.User. This is useful for reason I kind of forget now, but it started with working on notifications and ballooned massively from there into refactoring a number of things that were bugging me. This also includes a tiny amount of work on server-side events (SSE). * background stuff lives inside the platform now, which I need for having it push updates through SSE * userfile now lives in the platform, under file, so other platform functions can safely use it * oauth is broken into pieces and inside platform because other stuff was calling it already, but badly. * notifications go into the platform as well
60 lines
2.2 KiB
Go
60 lines
2.2 KiB
Go
package subprocess
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/file"
|
|
"github.com/google/uuid"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func fileContentPathAudioNormalized(u uuid.UUID) string {
|
|
//destination := AudioFileContentPathNormalized(audioUUID.String())
|
|
return file.ContentPath(file.CollectionAudioNormalized, u)
|
|
}
|
|
func NormalizeAudio(audioUUID uuid.UUID) error {
|
|
//source := AudioFileContentPathRaw(audioUUID.String())
|
|
source := file.ContentPath(file.CollectionAudioRaw, audioUUID)
|
|
_, err := os.Stat(source)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
log.Warn().Str("source", source).Msg("file doesn't exist, skipping normalization")
|
|
return nil
|
|
}
|
|
log.Info().Str("source", source).Msg("Normalizing")
|
|
//destination := AudioFileContentPathNormalized(audioUUID.String())
|
|
destination := fileContentPathAudioNormalized(audioUUID)
|
|
// Use "ffmpeg" directly, assuming it's in the system PATH
|
|
cmd := exec.Command("ffmpeg", "-i", source, "-filter:a", "loudnorm", destination)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
log.Printf("FFmpeg output for normalization: %s", out)
|
|
return fmt.Errorf("ffmpeg normalization failed: %v", err)
|
|
}
|
|
log.Info().Str("destination", destination).Msg("Normalized audio")
|
|
return nil
|
|
}
|
|
|
|
func TranscodeToOgg(audioUUID uuid.UUID) error {
|
|
//source := AudioFileContentPathNormalized(audioUUID.String())
|
|
source := fileContentPathAudioNormalized(audioUUID)
|
|
_, err := os.Stat(source)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
log.Warn().Str("source", source).Msg("file doesn't exist, skipping OGG transcoding")
|
|
return nil
|
|
}
|
|
log.Info().Str("source", source).Msg("Transcoding to ogg")
|
|
//destination := userfile.AudioFileContentPathOgg(audioUUID.String())
|
|
destination := file.ContentPath(file.CollectionAudioTranscoded, audioUUID)
|
|
// Use "ffmpeg" directly, assuming it's in the system PATH
|
|
cmd := exec.Command("ffmpeg", "-i", source, "-vn", "-acodec", "libvorbis", destination)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
log.Error().Err(err).Bytes("out", out).Msg("FFmpeg output for OGG transcoding")
|
|
return fmt.Errorf("ffmpeg OGG transcoding failed: %v", err)
|
|
}
|
|
log.Info().Str("destination", destination).Msg("Transcoded audio")
|
|
return nil
|
|
}
|