diff --git a/api/pixiv/ugoira/ffmpeg.go b/api/pixiv/ugoira/ffmpeg.go index b92e7a3..e3e2a74 100644 --- a/api/pixiv/ugoira/ffmpeg.go +++ b/api/pixiv/ugoira/ffmpeg.go @@ -7,11 +7,10 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "sort" "strconv" - "syscall" + "github.com/KJHJason/Cultured-Downloader-Logic/configs" "github.com/KJHJason/Cultured-Downloader-Logic/constants" cdlerrors "github.com/KJHJason/Cultured-Downloader-Logic/errors" "github.com/KJHJason/Cultured-Downloader-Logic/iofuncs" @@ -135,9 +134,7 @@ func getFlagsForGif(options *ffmpegOptions, imagesFolderPath string) ([]string, "-vf", "palettegen", palettePath, ) - if runtime.GOOS == "windows" { - imagePaletteCmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} - } + configs.PrepareCmdForBgTask(imagePaletteCmd) if constants.DEBUG_MODE { imagePaletteCmd.Stdout = os.Stdout imagePaletteCmd.Stderr = os.Stderr diff --git a/api/pixiv/ugoira/process.go b/api/pixiv/ugoira/process.go index cc866cb..10bf615 100644 --- a/api/pixiv/ugoira/process.go +++ b/api/pixiv/ugoira/process.go @@ -9,7 +9,6 @@ import ( "os/exec" "os/signal" "path/filepath" - "runtime" "sync" "syscall" @@ -73,9 +72,7 @@ func ConvertUgoira(ugoiraInfo *Ugoira, imagesFolderPath string, ugoiraFfmpeg *Ug // convert the frames to a gif or a video cmd := exec.CommandContext(ugoiraFfmpeg.context, ugoiraFfmpeg.ffmpegPath, args...) - if runtime.GOOS == "windows" { - cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} - } + configs.PrepareCmdForBgTask(cmd) // cmd.Stderr = os.Stderr // cmd.Stdout = os.Stdout diff --git a/configs/cmd_darwin.go b/configs/cmd_darwin.go new file mode 100644 index 0000000..2a262b1 --- /dev/null +++ b/configs/cmd_darwin.go @@ -0,0 +1,11 @@ +// +build darwin + +package configs + +import ( + "os/exec" +) + +func PrepareCmdForBgTask(cmd *exec.Cmd) { + // do nothing +} diff --git a/configs/cmd_linux.go b/configs/cmd_linux.go new file mode 100644 index 0000000..94b7d38 --- /dev/null +++ b/configs/cmd_linux.go @@ -0,0 +1,11 @@ +// +build linux + +package configs + +import ( + "os/exec" +) + +func PrepareCmdForBgTask(cmd *exec.Cmd) { + // do nothing +} diff --git a/configs/cmd_windows.go b/configs/cmd_windows.go new file mode 100644 index 0000000..5f46817 --- /dev/null +++ b/configs/cmd_windows.go @@ -0,0 +1,12 @@ +// +build windows + +package configs + +import ( + "os/exec" + "syscall" +) + +func PrepareCmdForBgTask(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} +} diff --git a/configs/configs.go b/configs/configs.go index 59f280b..6b2cf92 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -4,9 +4,7 @@ import ( "context" "errors" "os/exec" - "runtime" "strings" - "syscall" "time" ) @@ -46,9 +44,7 @@ func ValidateFfmpegPathLogic(ctx context.Context, ffmpegPath string) error { // execute the ffmpeg binary to check if it's working cmd := exec.CommandContext(cmdCtx, ffmpegPath, "-version") - if runtime.GOOS == "windows" { - cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} - } + PrepareCmdForBgTask(cmd) stdout, ffmpegErr := cmd.Output() if ffmpegErr != nil { return ffmpegErr