2024-01-14 16:31:07 +06:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2024-01-18 01:39:20 +06:00
|
|
|
"errors"
|
2024-02-12 22:21:47 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
2024-03-17 00:30:02 +05:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view"
|
2024-03-07 22:18:35 +05:00
|
|
|
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
2024-02-12 22:21:47 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
2024-02-17 19:08:58 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
2024-01-28 22:01:16 +06:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
2024-01-14 16:31:07 +06:00
|
|
|
)
|
|
|
|
|
2024-01-31 21:02:12 +06:00
|
|
|
type ConvertorHandlerContract interface {
|
|
|
|
MainConvertor()
|
2024-02-01 00:23:28 +06:00
|
|
|
FfPathSelection()
|
2024-02-03 17:47:32 +06:00
|
|
|
GetFfmpegVersion() (string, error)
|
|
|
|
GetFfprobeVersion() (string, error)
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
|
|
|
|
2024-01-14 16:31:07 +06:00
|
|
|
type ConvertorHandler struct {
|
2024-02-17 19:08:58 +06:00
|
|
|
app kernel.AppContract
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorView convertor.ViewContract
|
2024-03-07 22:18:35 +05:00
|
|
|
errorView error2.ViewContract
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorRepository convertor.RepositoryContract
|
2024-01-14 16:31:07 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConvertorHandler(
|
2024-02-17 19:08:58 +06:00
|
|
|
app kernel.AppContract,
|
2024-01-14 16:31:07 +06:00
|
|
|
convertorView convertor.ViewContract,
|
2024-03-07 22:18:35 +05:00
|
|
|
errorView error2.ViewContract,
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorRepository convertor.RepositoryContract,
|
2024-01-14 16:31:07 +06:00
|
|
|
) *ConvertorHandler {
|
|
|
|
return &ConvertorHandler{
|
2024-02-17 19:08:58 +06:00
|
|
|
app: app,
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorView: convertorView,
|
2024-03-07 22:18:35 +05:00
|
|
|
errorView: errorView,
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorRepository: convertorRepository,
|
2024-01-14 16:31:07 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:02:12 +06:00
|
|
|
func (h ConvertorHandler) MainConvertor() {
|
2024-01-18 01:39:20 +06:00
|
|
|
if h.checkingFFPathUtilities() == true {
|
2024-03-07 22:18:35 +05:00
|
|
|
formats, err := h.app.GetConvertorService().GetSupportFormats()
|
|
|
|
if err != nil {
|
|
|
|
h.errorView.PanicError(err)
|
|
|
|
return
|
|
|
|
}
|
2024-03-17 00:30:02 +05:00
|
|
|
conversion := view.NewConversion(h.app, formats, h.runConvert)
|
|
|
|
h.convertorView.Main(conversion)
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
2024-02-04 20:16:15 +06:00
|
|
|
h.convertorView.SelectFFPath("", "", h.saveSettingFFPath, nil, h.downloadFFmpeg)
|
2024-02-01 00:23:28 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h ConvertorHandler) FfPathSelection() {
|
|
|
|
ffmpeg, _ := h.convertorRepository.GetPathFfmpeg()
|
|
|
|
ffprobe, _ := h.convertorRepository.GetPathFfprobe()
|
2024-02-04 20:16:15 +06:00
|
|
|
h.convertorView.SelectFFPath(ffmpeg, ffprobe, h.saveSettingFFPath, h.MainConvertor, h.downloadFFmpeg)
|
2024-01-14 16:31:07 +06:00
|
|
|
}
|
|
|
|
|
2024-02-03 17:47:32 +06:00
|
|
|
func (h ConvertorHandler) GetFfmpegVersion() (string, error) {
|
2024-02-17 19:08:58 +06:00
|
|
|
return h.app.GetConvertorService().GetFFmpegVesrion()
|
2024-02-03 17:47:32 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h ConvertorHandler) GetFfprobeVersion() (string, error) {
|
2024-02-17 19:08:58 +06:00
|
|
|
return h.app.GetConvertorService().GetFFprobeVersion()
|
2024-02-03 17:47:32 +06:00
|
|
|
}
|
|
|
|
|
2024-03-17 00:30:02 +05:00
|
|
|
func (h ConvertorHandler) runConvert(setting view.HandleConvertSetting) {
|
2024-02-17 19:08:58 +06:00
|
|
|
h.app.GetQueue().Add(&kernel.ConvertSetting{
|
2024-03-17 00:30:02 +05:00
|
|
|
VideoFileInput: setting.FileInput,
|
2024-02-17 19:08:58 +06:00
|
|
|
VideoFileOut: kernel.File{
|
2024-03-17 00:30:02 +05:00
|
|
|
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.FileInput.Name + "." + setting.Format,
|
|
|
|
Name: setting.FileInput.Name,
|
2024-03-07 22:18:35 +05:00
|
|
|
Ext: "." + setting.Format,
|
2024-01-14 16:31:07 +06:00
|
|
|
},
|
2024-02-17 19:08:58 +06:00
|
|
|
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
2024-03-07 22:18:35 +05:00
|
|
|
Encoder: setting.Encoder,
|
2024-02-17 19:08:58 +06:00
|
|
|
})
|
2024-01-14 16:31:07 +06:00
|
|
|
}
|
|
|
|
|
2024-01-18 01:39:20 +06:00
|
|
|
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|
|
|
if h.checkingFFPath() == true {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-23 21:33:01 +06:00
|
|
|
pathsToFF := getPathsToFF()
|
2024-01-18 01:39:20 +06:00
|
|
|
for _, item := range pathsToFF {
|
2024-02-17 19:08:58 +06:00
|
|
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(item.FFmpeg)
|
2024-01-18 01:39:20 +06:00
|
|
|
if ffmpegChecking == false {
|
|
|
|
continue
|
|
|
|
}
|
2024-02-17 19:08:58 +06:00
|
|
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(item.FFprobe)
|
2024-01-18 01:39:20 +06:00
|
|
|
if ffprobeChecking == false {
|
|
|
|
continue
|
|
|
|
}
|
2024-02-01 00:23:28 +06:00
|
|
|
_, _ = h.convertorRepository.SavePathFfmpeg(item.FFmpeg)
|
|
|
|
_, _ = h.convertorRepository.SavePathFfprobe(item.FFprobe)
|
2024-01-18 01:39:20 +06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string) error {
|
2024-02-17 19:08:58 +06:00
|
|
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(ffmpegPath)
|
2024-01-18 01:39:20 +06:00
|
|
|
if ffmpegChecking == false {
|
2024-02-17 19:08:58 +06:00
|
|
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "errorFFmpeg",
|
|
|
|
})
|
|
|
|
return errors.New(errorText)
|
2024-01-18 01:39:20 +06:00
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(ffprobePath)
|
2024-01-18 01:39:20 +06:00
|
|
|
if ffprobeChecking == false {
|
2024-02-17 19:08:58 +06:00
|
|
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "errorFFprobe",
|
|
|
|
})
|
|
|
|
return errors.New(errorText)
|
2024-01-18 01:39:20 +06:00
|
|
|
}
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
_, _ = h.convertorRepository.SavePathFfmpeg(ffmpegPath)
|
|
|
|
_, _ = h.convertorRepository.SavePathFfprobe(ffprobePath)
|
2024-01-18 01:39:20 +06:00
|
|
|
|
2024-01-31 21:02:12 +06:00
|
|
|
h.MainConvertor()
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h ConvertorHandler) checkingFFPath() bool {
|
2024-02-17 19:08:58 +06:00
|
|
|
_, err := h.app.GetConvertorService().GetFFmpegVesrion()
|
2024-01-18 01:39:20 +06:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
_, err = h.app.GetConvertorService().GetFFprobeVersion()
|
2024-01-18 01:39:20 +06:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|