Made it possible to choose where to save.
This commit is contained in:
parent
5051c65ec6
commit
ebc8832d4d
@ -33,8 +33,10 @@ type File struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConvertSetting struct {
|
type ConvertSetting struct {
|
||||||
VideoFileInput *File
|
VideoFileInput *File
|
||||||
SocketPath string
|
VideoFileOut *File
|
||||||
|
SocketPath string
|
||||||
|
OverwriteOutputFiles bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConvertData struct {
|
type ConvertData struct {
|
||||||
@ -48,13 +50,11 @@ func NewService(ffPathUtilities FFPathUtilities) *Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) RunConvert(setting ConvertSetting) error {
|
func (s Service) RunConvert(setting ConvertSetting) error {
|
||||||
//args := strings.Split("-report -n -c:v libx264", " ")
|
overwriteOutputFiles := "-n"
|
||||||
//args := strings.Split("-n -c:v libx264", " ")
|
if setting.OverwriteOutputFiles == true {
|
||||||
//args = append(args, "-progress", "unix://"+setting.SocketPath, "-i", setting.VideoFileInput.Path, "file-out.mp4")
|
overwriteOutputFiles = "-y"
|
||||||
//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 := []string{overwriteOutputFiles, "-i", setting.VideoFileInput.Path, "-c:v", "libx264", "-progress", "unix://" + setting.SocketPath, setting.VideoFileOut.Path}
|
||||||
//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"}
|
|
||||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, args...)
|
cmd := exec.Command(s.ffPathUtilities.FFmpeg, args...)
|
||||||
|
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package convertor
|
package convertor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
@ -21,12 +22,15 @@ type View struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HandleConvertSetting struct {
|
type HandleConvertSetting struct {
|
||||||
VideoFileInput *File
|
VideoFileInput *File
|
||||||
SocketPath string
|
DirectoryForSave string
|
||||||
|
SocketPath string
|
||||||
|
OverwriteOutputFiles bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type enableFormConversionStruct struct {
|
type enableFormConversionStruct struct {
|
||||||
fileVideoForConversion *widget.Button
|
fileVideoForConversion *widget.Button
|
||||||
|
buttonForSelectedDir *widget.Button
|
||||||
form *widget.Form
|
form *widget.Form
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,23 +49,40 @@ func (v View) Main(
|
|||||||
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
progress := widget.NewProgressBar()
|
progress := widget.NewProgressBar()
|
||||||
progress.Hide()
|
|
||||||
|
|
||||||
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, progress, conversionMessage)
|
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{
|
form.Items = []*widget.FormItem{
|
||||||
{Text: "Файл для ковертации:", Widget: fileVideoForConversion},
|
{Text: "Файл для ковертации:", Widget: fileVideoForConversion},
|
||||||
{Widget: fileVideoForConversionMessage},
|
{Widget: fileVideoForConversionMessage},
|
||||||
|
{Text: "Папка куда будет сохранятся:", Widget: buttonForSelectedDir},
|
||||||
|
{Widget: buttonForSelectedDirMessage},
|
||||||
|
{Widget: checkboxOverwriteOutputFiles},
|
||||||
}
|
}
|
||||||
form.SubmitText = "Конвертировать"
|
form.SubmitText = "Конвертировать"
|
||||||
|
|
||||||
enableFormConversionStruct := enableFormConversionStruct{
|
enableFormConversionStruct := enableFormConversionStruct{
|
||||||
fileVideoForConversion: fileVideoForConversion,
|
fileVideoForConversion: fileVideoForConversion,
|
||||||
|
buttonForSelectedDir: buttonForSelectedDir,
|
||||||
form: form,
|
form: form,
|
||||||
}
|
}
|
||||||
|
|
||||||
form.OnSubmit = func() {
|
form.OnSubmit = func() {
|
||||||
|
if len(*pathToSaveDirectory) == 0 {
|
||||||
|
showConversionMessage(conversionMessage, errors.New("Не выбрали папку для сохранения!"))
|
||||||
|
enableFormConversion(enableFormConversionStruct)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conversionMessage.Text = ""
|
||||||
|
|
||||||
fileVideoForConversion.Disable()
|
fileVideoForConversion.Disable()
|
||||||
|
buttonForSelectedDir.Disable()
|
||||||
form.Disable()
|
form.Disable()
|
||||||
|
|
||||||
socketPath, err := getSocketPath(fileInput, progress)
|
socketPath, err := getSocketPath(fileInput, progress)
|
||||||
@ -73,8 +94,10 @@ func (v View) Main(
|
|||||||
}
|
}
|
||||||
|
|
||||||
setting := HandleConvertSetting{
|
setting := HandleConvertSetting{
|
||||||
VideoFileInput: fileInput,
|
VideoFileInput: fileInput,
|
||||||
SocketPath: socketPath,
|
DirectoryForSave: *pathToSaveDirectory,
|
||||||
|
SocketPath: socketPath,
|
||||||
|
OverwriteOutputFiles: isOverwriteOutputFiles,
|
||||||
}
|
}
|
||||||
err = runConvert(setting)
|
err = runConvert(setting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,6 +148,37 @@ func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widge
|
|||||||
return button, fileVideoForConversionMessage, fileInput
|
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) {
|
func setStringErrorStyle(text *canvas.Text) {
|
||||||
text.Color = color.RGBA{255, 0, 0, 255}
|
text.Color = color.RGBA{255, 0, 0, 255}
|
||||||
text.Refresh()
|
text.Refresh()
|
||||||
@ -142,5 +196,6 @@ func showConversionMessage(conversionMessage *canvas.Text, err error) {
|
|||||||
|
|
||||||
func enableFormConversion(enableFormConversionStruct enableFormConversionStruct) {
|
func enableFormConversion(enableFormConversionStruct enableFormConversionStruct) {
|
||||||
enableFormConversionStruct.fileVideoForConversion.Enable()
|
enableFormConversionStruct.fileVideoForConversion.Enable()
|
||||||
|
enableFormConversionStruct.buttonForSelectedDir.Enable()
|
||||||
enableFormConversionStruct.form.Enable()
|
enableFormConversionStruct.form.Enable()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"ffmpegGui/convertor"
|
"ffmpegGui/convertor"
|
||||||
|
"ffmpegGui/helper"
|
||||||
"ffmpegGui/setting"
|
"ffmpegGui/setting"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
@ -48,7 +49,7 @@ func (h ConvertorHandler) GetConvertor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) getSockPath(file *convertor.File, progressbar *widget.ProgressBar) (string, error) {
|
func (h ConvertorHandler) getSockPath(file *convertor.File, progressbar *widget.ProgressBar) (string, error) {
|
||||||
totalDuration, err := h.getTotalDuration(file)
|
totalDuration, err := h.convertorService.GetTotalDuration(file)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -102,18 +103,21 @@ func (h ConvertorHandler) getSockPath(file *convertor.File, progressbar *widget.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting) error {
|
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting) error {
|
||||||
|
|
||||||
return h.convertorService.RunConvert(
|
return h.convertorService.RunConvert(
|
||||||
convertor.ConvertSetting{
|
convertor.ConvertSetting{
|
||||||
VideoFileInput: setting.VideoFileInput,
|
VideoFileInput: setting.VideoFileInput,
|
||||||
SocketPath: setting.SocketPath,
|
VideoFileOut: &convertor.File{
|
||||||
|
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.VideoFileInput.Name + ".mp4",
|
||||||
|
Name: setting.VideoFileInput.Name,
|
||||||
|
Ext: ".mp4",
|
||||||
|
},
|
||||||
|
SocketPath: setting.SocketPath,
|
||||||
|
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) getTotalDuration(file *convertor.File) (float64, error) {
|
|
||||||
return h.convertorService.GetTotalDuration(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
||||||
if h.checkingFFPath() == true {
|
if h.checkingFFPath() == true {
|
||||||
return true
|
return true
|
||||||
@ -121,7 +125,7 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
|
|
||||||
var pathsToFF []convertor.FFPathUtilities
|
var pathsToFF []convertor.FFPathUtilities
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg.exe", "ffmpeg/bin/ffprobe.exe"}}
|
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}}
|
||||||
} else {
|
} else {
|
||||||
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
|
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
|
||||||
}
|
}
|
||||||
@ -135,9 +139,9 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: item.FFmpeg}
|
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: item.FFmpeg}
|
||||||
h.settingRepository.Create(ffmpegEntity)
|
_, _ = h.settingRepository.Create(ffmpegEntity)
|
||||||
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: item.FFprobe}
|
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: item.FFprobe}
|
||||||
h.settingRepository.Create(ffprobeEntity)
|
_, _ = h.settingRepository.Create(ffprobeEntity)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,18 +151,18 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string) error {
|
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string) error {
|
||||||
ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(ffmpegPath)
|
ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(ffmpegPath)
|
||||||
if ffmpegChecking == false {
|
if ffmpegChecking == false {
|
||||||
return errors.New("Это не FFmpeg")
|
return errors.New("это не FFmpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(ffprobePath)
|
ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(ffprobePath)
|
||||||
if ffprobeChecking == false {
|
if ffprobeChecking == false {
|
||||||
return errors.New("Это не FFprobe")
|
return errors.New("это не FFprobe")
|
||||||
}
|
}
|
||||||
|
|
||||||
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath}
|
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath}
|
||||||
h.settingRepository.Create(ffmpegEntity)
|
_, _ = h.settingRepository.Create(ffmpegEntity)
|
||||||
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
|
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
|
||||||
h.settingRepository.Create(ffprobeEntity)
|
_, _ = h.settingRepository.Create(ffprobeEntity)
|
||||||
|
|
||||||
h.GetConvertor()
|
h.GetConvertor()
|
||||||
|
|
||||||
|
10
src/helper/helper.go
Normal file
10
src/helper/helper.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
|
func PathSeparator() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "\\"
|
||||||
|
}
|
||||||
|
return "/"
|
||||||
|
}
|
@ -15,17 +15,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const appVersion string = "0.1.0"
|
//const appVersion string = "0.1.0"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.New()
|
a := app.New()
|
||||||
w := a.NewWindow("GUI FFMpeg!")
|
w := a.NewWindow("GUI FFMpeg!")
|
||||||
w.Resize(fyne.Size{800, 600})
|
w.Resize(fyne.Size{Width: 800, Height: 600})
|
||||||
|
|
||||||
errorView := myError.NewView(w)
|
errorView := myError.NewView(w)
|
||||||
|
|
||||||
if canCreateFile("data/database") != true {
|
if canCreateFile("data/database") != true {
|
||||||
errorView.PanicError(errors.New("Не смогли создать файл 'database' в папке 'data'"))
|
errorView.PanicError(errors.New("не смогли создать файл 'database' в папке 'data'"))
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user