112 lines
2.7 KiB
Go
112 lines
2.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"errors"
|
|
"fyne.io/fyne/v2/lang"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg/download/service"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/gui/view"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
|
)
|
|
|
|
func (c *controller) convertor() {
|
|
formats, err := c.app.GetConvertorService().GetSupportFormats()
|
|
if err != nil {
|
|
c.startWithError(err)
|
|
return
|
|
}
|
|
|
|
content := view.Convertor(
|
|
c.window,
|
|
c.addFileForConversion,
|
|
c.app.GetSetting().GetDirectoryForSaving(),
|
|
c.setDirectoryForSaving,
|
|
formats,
|
|
c.addToConversion,
|
|
)
|
|
c.window.SetContent(content)
|
|
}
|
|
|
|
func (c *controller) addFileForConversion(file ffmpeg.File) {
|
|
c.app.GetItemsToConvert().Add(&file)
|
|
c.window.GetLayout().GetRContainer().SelectAddedFilesTab()
|
|
}
|
|
|
|
func (c *controller) setDirectoryForSaving(path string) {
|
|
c.app.GetSetting().SetDirectoryForSaving(path)
|
|
}
|
|
|
|
func (c *controller) addToConversion(convertSetting view.ConvertSetting) error {
|
|
if len(c.app.GetItemsToConvert().GetItems()) == 0 {
|
|
return errors.New(lang.L("errorNoFilesAddedForConversion"))
|
|
}
|
|
c.window.GetLayout().GetRContainer().SelectFileQueueTab()
|
|
for _, item := range c.app.GetItemsToConvert().GetItems() {
|
|
file := item.GetFile()
|
|
if file == nil {
|
|
continue
|
|
}
|
|
|
|
c.app.GetQueueService().Add(&ffmpeg.ConvertSetting{
|
|
FileInput: *file,
|
|
FileOut: ffmpeg.File{
|
|
Path: convertSetting.DirectoryForSave + utils.PathSeparator() + file.Name + "." + convertSetting.Format,
|
|
Name: file.Name,
|
|
Ext: "." + convertSetting.Format,
|
|
},
|
|
OverwriteOutputFiles: convertSetting.OverwriteOutputFiles,
|
|
Encoder: convertSetting.Encoder,
|
|
})
|
|
}
|
|
c.app.GetItemsToConvert().AfterAddingQueue()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *controller) settingConvertor(isAllowCancellation bool) {
|
|
ffmpegPath := c.app.GetFFmpegService().GetFFmpegPath()
|
|
ffprobePath := c.app.GetFFmpegService().GetFFprobePath()
|
|
ffplayPath := c.app.GetFFmpegService().GetFFplayPath()
|
|
|
|
var cancel func()
|
|
cancel = nil
|
|
if isAllowCancellation {
|
|
cancel = func() {
|
|
c.convertor()
|
|
}
|
|
}
|
|
|
|
content := view.ConfiguringFFmpegUtilities(
|
|
c.window,
|
|
ffmpegPath,
|
|
ffprobePath,
|
|
ffplayPath,
|
|
c.saveSettingConvertor,
|
|
cancel,
|
|
service.DownloadFFmpeg(c.app, c.saveSettingConvertor),
|
|
)
|
|
c.window.SetContent(content)
|
|
}
|
|
|
|
func (c *controller) saveSettingConvertor(ffmpegPath string, ffprobePath string, ffplayPath string) error {
|
|
var err error
|
|
|
|
err = c.app.GetFFmpegService().ChangeFFmpeg(ffmpegPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.app.GetFFmpegService().ChangeFFprobe(ffprobePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.app.GetFFmpegService().ChangeFFplay(ffplayPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.convertor()
|
|
return nil
|
|
}
|