It is now possible to add multiple files before sending them to the processing queue.
186 lines
5.5 KiB
Go
186 lines
5.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view"
|
|
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting"
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
)
|
|
|
|
type ConvertorHandlerContract interface {
|
|
MainConvertor()
|
|
FfPathSelection()
|
|
GetFfmpegVersion() (string, error)
|
|
GetFfprobeVersion() (string, error)
|
|
GetFfplayVersion() (string, error)
|
|
}
|
|
|
|
type ConvertorHandler struct {
|
|
app kernel.AppContract
|
|
convertorView convertor.ViewContract
|
|
errorView error2.ViewContract
|
|
convertorRepository convertor.RepositoryContract
|
|
settingDirectoryForSaving setting.DirectoryForSavingContract
|
|
itemsToConvertService kernel.ItemsToConvertContract
|
|
}
|
|
|
|
func NewConvertorHandler(
|
|
app kernel.AppContract,
|
|
convertorView convertor.ViewContract,
|
|
errorView error2.ViewContract,
|
|
convertorRepository convertor.RepositoryContract,
|
|
settingDirectoryForSaving setting.DirectoryForSavingContract,
|
|
itemsToConvertService kernel.ItemsToConvertContract,
|
|
) *ConvertorHandler {
|
|
return &ConvertorHandler{
|
|
app: app,
|
|
convertorView: convertorView,
|
|
errorView: errorView,
|
|
convertorRepository: convertorRepository,
|
|
settingDirectoryForSaving: settingDirectoryForSaving,
|
|
itemsToConvertService: itemsToConvertService,
|
|
}
|
|
}
|
|
|
|
func (h ConvertorHandler) MainConvertor() {
|
|
if h.checkingFFPathUtilities() == true {
|
|
formats, err := h.app.GetConvertorService().GetSupportFormats()
|
|
if err != nil {
|
|
h.errorView.PanicError(err)
|
|
return
|
|
}
|
|
conversion := view.NewConversion(h.app, formats, h.runConvert, h.settingDirectoryForSaving, h.itemsToConvertService)
|
|
h.convertorView.Main(conversion)
|
|
return
|
|
}
|
|
h.convertorView.SelectFFPath("", "", "", h.saveSettingFFPath, nil, h.downloadFFmpeg)
|
|
}
|
|
|
|
func (h ConvertorHandler) FfPathSelection() {
|
|
ffmpeg, _ := h.convertorRepository.GetPathFfmpeg()
|
|
ffprobe, _ := h.convertorRepository.GetPathFfprobe()
|
|
ffplay, _ := h.convertorRepository.GetPathFfplay()
|
|
h.convertorView.SelectFFPath(ffmpeg, ffprobe, ffplay, h.saveSettingFFPath, h.MainConvertor, h.downloadFFmpeg)
|
|
}
|
|
|
|
func (h ConvertorHandler) GetFfmpegVersion() (string, error) {
|
|
return h.app.GetConvertorService().GetFFmpegVesrion()
|
|
}
|
|
|
|
func (h ConvertorHandler) GetFfprobeVersion() (string, error) {
|
|
return h.app.GetConvertorService().GetFFprobeVersion()
|
|
}
|
|
|
|
func (h ConvertorHandler) GetFfplayVersion() (string, error) {
|
|
return h.app.GetConvertorService().GetFFplayVersion()
|
|
}
|
|
|
|
func (h ConvertorHandler) runConvert(setting view.HandleConvertSetting) {
|
|
h.app.GetWindow().GetLayout().GetRightTabs().SelectFileQueueTab()
|
|
|
|
for _, item := range h.itemsToConvertService.GetItems() {
|
|
file := item.GetFile()
|
|
if file == nil {
|
|
continue
|
|
}
|
|
|
|
h.app.GetQueue().Add(&kernel.ConvertSetting{
|
|
VideoFileInput: *file,
|
|
VideoFileOut: kernel.File{
|
|
Path: setting.DirectoryForSave + helper.PathSeparator() + file.Name + "." + setting.Format,
|
|
Name: file.Name,
|
|
Ext: "." + setting.Format,
|
|
},
|
|
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
|
Encoder: setting.Encoder,
|
|
})
|
|
}
|
|
h.itemsToConvertService.AfterAddingQueue()
|
|
}
|
|
|
|
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|
if h.checkingFFPath() == true {
|
|
return true
|
|
}
|
|
|
|
pathsToFF := getPathsToFF()
|
|
for _, item := range pathsToFF {
|
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(item.FFmpeg)
|
|
if ffmpegChecking == false {
|
|
continue
|
|
}
|
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(item.FFprobe)
|
|
if ffprobeChecking == false {
|
|
continue
|
|
}
|
|
|
|
ffplayChecking, _ := h.app.GetConvertorService().ChangeFFplayPath(item.FFplay)
|
|
if ffplayChecking == false {
|
|
continue
|
|
}
|
|
_, _ = h.convertorRepository.SavePathFfmpeg(item.FFmpeg)
|
|
_, _ = h.convertorRepository.SavePathFfprobe(item.FFprobe)
|
|
_, _ = h.convertorRepository.SavePathFfplay(item.FFplay)
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string, ffplayPath string) error {
|
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(ffmpegPath)
|
|
if ffmpegChecking == false {
|
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
|
MessageID: "errorFFmpeg",
|
|
})
|
|
return errors.New(errorText)
|
|
}
|
|
|
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(ffprobePath)
|
|
if ffprobeChecking == false {
|
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
|
MessageID: "errorFFprobe",
|
|
})
|
|
return errors.New(errorText)
|
|
}
|
|
|
|
ffplayChecking, _ := h.app.GetConvertorService().ChangeFFplayPath(ffplayPath)
|
|
if ffplayChecking == false {
|
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
|
MessageID: "errorFFplay",
|
|
})
|
|
return errors.New(errorText)
|
|
}
|
|
|
|
_, _ = h.convertorRepository.SavePathFfmpeg(ffmpegPath)
|
|
_, _ = h.convertorRepository.SavePathFfprobe(ffprobePath)
|
|
_, _ = h.convertorRepository.SavePathFfplay(ffplayPath)
|
|
|
|
h.MainConvertor()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h ConvertorHandler) checkingFFPath() bool {
|
|
_, err := h.app.GetConvertorService().GetFFmpegVesrion()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
_, err = h.app.GetConvertorService().GetFFprobeVersion()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
_, err = h.app.GetConvertorService().GetFFplayVersion()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|