Made it possible to choose where to save.
This commit is contained in:
@@ -33,8 +33,10 @@ type File struct {
|
||||
}
|
||||
|
||||
type ConvertSetting struct {
|
||||
VideoFileInput *File
|
||||
SocketPath string
|
||||
VideoFileInput *File
|
||||
VideoFileOut *File
|
||||
SocketPath string
|
||||
OverwriteOutputFiles bool
|
||||
}
|
||||
|
||||
type ConvertData struct {
|
||||
@@ -48,13 +50,11 @@ func NewService(ffPathUtilities FFPathUtilities) *Service {
|
||||
}
|
||||
|
||||
func (s Service) RunConvert(setting ConvertSetting) error {
|
||||
//args := strings.Split("-report -n -c:v libx264", " ")
|
||||
//args := strings.Split("-n -c:v libx264", " ")
|
||||
//args = append(args, "-progress", "unix://"+setting.SocketPath, "-i", setting.VideoFileInput.Path, "file-out.mp4")
|
||||
//args := "-report -n -i " + setting.VideoFileInput.Path + " -c:v libx264 -progress unix://" + setting.SocketPath + " output-file.mp4"
|
||||
//args := "-n -i " + setting.VideoFileInput.Path + " -c:v libx264 -progress unix://" + setting.SocketPath + " output-file.mp4"
|
||||
//args := "-y -i " + setting.VideoFileInput.Path + " -c:v libx264 -progress unix://" + setting.SocketPath + " output-file.mp4"
|
||||
args := []string{"-y", "-i", setting.VideoFileInput.Path, "-c:v", "libx264", "-progress", "unix://" + setting.SocketPath, "output-file.mp4"}
|
||||
overwriteOutputFiles := "-n"
|
||||
if setting.OverwriteOutputFiles == true {
|
||||
overwriteOutputFiles = "-y"
|
||||
}
|
||||
args := []string{overwriteOutputFiles, "-i", setting.VideoFileInput.Path, "-c:v", "libx264", "-progress", "unix://" + setting.SocketPath, setting.VideoFileOut.Path}
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, args...)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -21,12 +22,15 @@ type View struct {
|
||||
}
|
||||
|
||||
type HandleConvertSetting struct {
|
||||
VideoFileInput *File
|
||||
SocketPath string
|
||||
VideoFileInput *File
|
||||
DirectoryForSave string
|
||||
SocketPath string
|
||||
OverwriteOutputFiles bool
|
||||
}
|
||||
|
||||
type enableFormConversionStruct struct {
|
||||
fileVideoForConversion *widget.Button
|
||||
buttonForSelectedDir *widget.Button
|
||||
form *widget.Form
|
||||
}
|
||||
|
||||
@@ -45,23 +49,40 @@ func (v View) Main(
|
||||
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
progress := widget.NewProgressBar()
|
||||
progress.Hide()
|
||||
|
||||
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, progress, conversionMessage)
|
||||
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
|
||||
|
||||
isOverwriteOutputFiles := false
|
||||
checkboxOverwriteOutputFiles := widget.NewCheck("Разрешить перезаписать файл", func(b bool) {
|
||||
isOverwriteOutputFiles = b
|
||||
})
|
||||
|
||||
form.Items = []*widget.FormItem{
|
||||
{Text: "Файл для ковертации:", Widget: fileVideoForConversion},
|
||||
{Widget: fileVideoForConversionMessage},
|
||||
{Text: "Папка куда будет сохранятся:", Widget: buttonForSelectedDir},
|
||||
{Widget: buttonForSelectedDirMessage},
|
||||
{Widget: checkboxOverwriteOutputFiles},
|
||||
}
|
||||
form.SubmitText = "Конвертировать"
|
||||
|
||||
enableFormConversionStruct := enableFormConversionStruct{
|
||||
fileVideoForConversion: fileVideoForConversion,
|
||||
buttonForSelectedDir: buttonForSelectedDir,
|
||||
form: form,
|
||||
}
|
||||
|
||||
form.OnSubmit = func() {
|
||||
if len(*pathToSaveDirectory) == 0 {
|
||||
showConversionMessage(conversionMessage, errors.New("Не выбрали папку для сохранения!"))
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
return
|
||||
}
|
||||
conversionMessage.Text = ""
|
||||
|
||||
fileVideoForConversion.Disable()
|
||||
buttonForSelectedDir.Disable()
|
||||
form.Disable()
|
||||
|
||||
socketPath, err := getSocketPath(fileInput, progress)
|
||||
@@ -73,8 +94,10 @@ func (v View) Main(
|
||||
}
|
||||
|
||||
setting := HandleConvertSetting{
|
||||
VideoFileInput: fileInput,
|
||||
SocketPath: socketPath,
|
||||
VideoFileInput: fileInput,
|
||||
DirectoryForSave: *pathToSaveDirectory,
|
||||
SocketPath: socketPath,
|
||||
OverwriteOutputFiles: isOverwriteOutputFiles,
|
||||
}
|
||||
err = runConvert(setting)
|
||||
if err != nil {
|
||||
@@ -125,6 +148,37 @@ func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widge
|
||||
return button, fileVideoForConversionMessage, fileInput
|
||||
}
|
||||
|
||||
func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button, buttonMessage *canvas.Text, dirPath *string) {
|
||||
buttonMessage = canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
||||
buttonMessage.TextSize = 16
|
||||
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
path := ""
|
||||
dirPath = &path
|
||||
|
||||
button = widget.NewButton("выбрать", func() {
|
||||
fileDialog := dialog.NewFolderOpen(
|
||||
func(r fyne.ListableURI, err error) {
|
||||
if err != nil {
|
||||
buttonMessage.Text = err.Error()
|
||||
setStringErrorStyle(buttonMessage)
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
path = r.Path()
|
||||
|
||||
buttonMessage.Text = r.Path()
|
||||
setStringSuccessStyle(buttonMessage)
|
||||
}, v.w)
|
||||
fileDialog.Show()
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func setStringErrorStyle(text *canvas.Text) {
|
||||
text.Color = color.RGBA{255, 0, 0, 255}
|
||||
text.Refresh()
|
||||
@@ -142,5 +196,6 @@ func showConversionMessage(conversionMessage *canvas.Text, err error) {
|
||||
|
||||
func enableFormConversion(enableFormConversionStruct enableFormConversionStruct) {
|
||||
enableFormConversionStruct.fileVideoForConversion.Enable()
|
||||
enableFormConversionStruct.buttonForSelectedDir.Enable()
|
||||
enableFormConversionStruct.form.Enable()
|
||||
}
|
||||
|
Reference in New Issue
Block a user