85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package task
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"git.lastassault.de/speatzle/morffix/config"
|
|
"git.lastassault.de/speatzle/morffix/constants"
|
|
"git.lastassault.de/speatzle/morffix/task/log"
|
|
"git.lastassault.de/speatzle/morffix/types"
|
|
)
|
|
|
|
func RunTranscode(conf config.Config, t *types.Task, data types.TranscodeData) {
|
|
ctx := context.TODO()
|
|
l := log.GetTaskLogger(t)
|
|
|
|
// TODO Figure out how to get correct file ending
|
|
src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-src-%v-%v.mkv", t.ID, t.FileID))
|
|
dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-dst-%v-%v.mkv", t.ID, t.FileID))
|
|
|
|
// Set ffmpeg input path
|
|
if len(t.FfmpegCommand.InputFiles) == 0 {
|
|
l.ErrorContext(ctx, "FFmpeg Command has no input files", "command", t.FfmpegCommand)
|
|
return
|
|
}
|
|
|
|
t.FfmpegCommand.InputFiles[0].Path = src_path
|
|
|
|
// Set ffmpeg output path
|
|
if len(t.FfmpegCommand.OutputFiles) == 0 {
|
|
l.ErrorContext(ctx, "FFmpeg Command has no output files", "command", t.FfmpegCommand)
|
|
return
|
|
}
|
|
|
|
t.FfmpegCommand.OutputFiles[0].Path = dst_path
|
|
|
|
// TODO cleanup file when done
|
|
defer func() {
|
|
err := os.Remove(src_path)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Removing Source File", "err", err, "path", src_path)
|
|
} else {
|
|
l.InfoContext(ctx, "Source File Removed Succesfully", "path", src_path)
|
|
}
|
|
}()
|
|
|
|
err := downloadFile(ctx, l, conf, src_path, t)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Source File Download Failed", "err", err)
|
|
return
|
|
}
|
|
|
|
// TODO cleanup file when done
|
|
defer func() {
|
|
err := os.Remove(dst_path)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Removing Destination File", "err", err, "path", dst_path)
|
|
} else {
|
|
l.InfoContext(ctx, "File Destination Removed Succesfully", "path", dst_path)
|
|
}
|
|
}()
|
|
|
|
err = runFfmpegCommand(ctx, l, conf, t.FfmpegCommand)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "FFmpeg Failed", "err", err)
|
|
return
|
|
}
|
|
|
|
hash, err := hashFile(dst_path)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Generating Hash", "err", err)
|
|
return
|
|
}
|
|
|
|
err = uploadFile(ctx, l, conf, dst_path, t, hash)
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "File Upload Failed", "err", err)
|
|
return
|
|
}
|
|
|
|
l.InfoContext(ctx, "Task Success")
|
|
t.Status = constants.TASK_STATUS_SUCCESS
|
|
}
|