Compare commits

..

No commits in common. "0cd32bb0f0f18d4838c5b25152837627713c864c" and "c572a3cabe81177379abf76629b08dc5ea5cf1a8" have entirely different histories.

20 changed files with 76 additions and 651 deletions

View File

@ -2,14 +2,11 @@ package convertor
import ( import (
"errors" "errors"
"ffmpegGui/helper"
"ffmpegGui/localizer"
"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"
"fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/nicksnyder/go-i18n/v2/i18n"
"image/color" "image/color"
) )
@ -20,8 +17,7 @@ type ViewContract interface {
} }
type View struct { type View struct {
w fyne.Window w fyne.Window
localizerService localizer.ServiceContract
} }
type HandleConvertSetting struct { type HandleConvertSetting struct {
@ -36,11 +32,8 @@ type enableFormConversionStruct struct {
form *widget.Form form *widget.Form
} }
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View { func NewView(w fyne.Window) *View {
return &View{ return &View{w}
w: w,
localizerService: localizerService,
}
} }
func (v View) Main( func (v View) Main(
@ -58,35 +51,18 @@ func (v View) Main(
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving() buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
isOverwriteOutputFiles := false isOverwriteOutputFiles := false
checkboxOverwriteOutputFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ checkboxOverwriteOutputFiles := widget.NewCheck("Разрешить перезаписать файл", func(b bool) {
MessageID: "checkboxOverwriteOutputFilesTitle",
})
checkboxOverwriteOutputFiles := widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
isOverwriteOutputFiles = b isOverwriteOutputFiles = b
}) })
form.Items = []*widget.FormItem{ form.Items = []*widget.FormItem{
{ {Text: "Файл для ковертации:", Widget: fileVideoForConversion},
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "fileVideoForConversionTitle"}), {Widget: fileVideoForConversionMessage},
Widget: fileVideoForConversion, {Text: "Папка куда будет сохраняться:", Widget: buttonForSelectedDir},
}, {Widget: buttonForSelectedDirMessage},
{ {Widget: checkboxOverwriteOutputFiles},
Widget: fileVideoForConversionMessage,
},
{
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
Widget: buttonForSelectedDir,
},
{
Widget: buttonForSelectedDirMessage,
},
{
Widget: checkboxOverwriteOutputFiles,
},
} }
form.SubmitText = v.localizerService.GetMessage(&i18n.LocalizeConfig{ form.SubmitText = "Конвертировать"
MessageID: "converterVideoFilesSubmitTitle",
})
enableFormConversionStruct := enableFormConversionStruct{ enableFormConversionStruct := enableFormConversionStruct{
fileVideoForConversion: fileVideoForConversion, fileVideoForConversion: fileVideoForConversion,
@ -96,9 +72,7 @@ func (v View) Main(
form.OnSubmit = func() { form.OnSubmit = func() {
if len(*pathToSaveDirectory) == 0 { if len(*pathToSaveDirectory) == 0 {
showConversionMessage(conversionMessage, errors.New(v.localizerService.GetMessage(&i18n.LocalizeConfig{ showConversionMessage(conversionMessage, errors.New("Не выбрали папку для сохранения!"))
MessageID: "errorSelectedFolderSave",
})))
enableFormConversion(enableFormConversionStruct) enableFormConversion(enableFormConversionStruct)
return return
} }
@ -122,10 +96,7 @@ func (v View) Main(
enableFormConversion(enableFormConversionStruct) enableFormConversion(enableFormConversionStruct)
} }
converterVideoFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ v.w.SetContent(widget.NewCard("Конвертор видео файлов в mp4", "", container.NewVBox(form, conversionMessage, progress)))
MessageID: "converterVideoFilesTitle",
})
v.w.SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVBox(form, conversionMessage, progress)))
form.Disable() form.Disable()
} }
@ -136,11 +107,7 @@ func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widge
fileVideoForConversionMessage.TextSize = 16 fileVideoForConversionMessage.TextSize = 16
fileVideoForConversionMessage.TextStyle = fyne.TextStyle{Bold: true} fileVideoForConversionMessage.TextStyle = fyne.TextStyle{Bold: true}
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ button := widget.NewButton("выбрать", func() {
MessageID: "choose",
})
button := widget.NewButton(buttonTitle, func() {
fileDialog := dialog.NewFileOpen( fileDialog := dialog.NewFileOpen(
func(r fyne.URIReadCloser, err error) { func(r fyne.URIReadCloser, err error) {
if err != nil { if err != nil {
@ -164,7 +131,6 @@ func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widge
progress.Refresh() progress.Refresh()
conversionMessage.Text = "" conversionMessage.Text = ""
}, v.w) }, v.w)
helper.FileDialogResize(fileDialog, v.w)
fileDialog.Show() fileDialog.Show()
}) })
@ -179,11 +145,7 @@ func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button,
path := "" path := ""
dirPath = &path dirPath = &path
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ button = widget.NewButton("выбрать", func() {
MessageID: "choose",
})
button = widget.NewButton(buttonTitle, func() {
fileDialog := dialog.NewFolderOpen( fileDialog := dialog.NewFolderOpen(
func(r fyne.ListableURI, err error) { func(r fyne.ListableURI, err error) {
if err != nil { if err != nil {
@ -200,7 +162,6 @@ func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button,
buttonMessage.Text = r.Path() buttonMessage.Text = r.Path()
setStringSuccessStyle(buttonMessage) setStringSuccessStyle(buttonMessage)
}, v.w) }, v.w)
helper.FileDialogResize(fileDialog, v.w)
fileDialog.Show() fileDialog.Show()
}) })

View File

@ -1,11 +1,9 @@
package error package error
import ( import (
"ffmpegGui/localizer"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/nicksnyder/go-i18n/v2/i18n"
) )
type ViewContract interface { type ViewContract interface {
@ -13,54 +11,16 @@ type ViewContract interface {
} }
type View struct { type View struct {
w fyne.Window w fyne.Window
localizerService localizer.ServiceContract
} }
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View { func NewView(w fyne.Window) *View {
return &View{ return &View{w}
w: w,
localizerService: localizerService,
}
} }
func (v View) PanicError(err error) { func (v View) PanicError(err error) {
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{ v.w.SetContent(container.NewVBox(
MessageID: "error", widget.NewLabel("Произошла ошибка!"),
}) widget.NewLabel("Ошибка: "+err.Error()),
v.w.SetContent(container.NewBorder(
container.NewVBox(
widget.NewLabel(messageHead),
widget.NewLabel(err.Error()),
),
nil,
nil,
nil,
localizer.LanguageSelectionForm(v.localizerService, func(lang localizer.Lang) {
v.PanicError(err)
}),
))
}
func (v View) PanicErrorWriteDirectoryData() {
message := v.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "errorDatabase",
})
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "error",
})
v.w.SetContent(container.NewBorder(
container.NewVBox(
widget.NewLabel(messageHead),
widget.NewLabel(message),
),
nil,
nil,
nil,
localizer.LanguageSelectionForm(v.localizerService, func(lang localizer.Lang) {
v.PanicErrorWriteDirectoryData()
}),
)) ))
} }

View File

@ -5,7 +5,6 @@ go 1.21
require ( require (
fyne.io/fyne/v2 v2.4.3 // indirect fyne.io/fyne/v2 v2.4.3 // indirect
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
@ -22,7 +21,6 @@ require (
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/mattn/go-sqlite3 v1.14.19 // indirect github.com/mattn/go-sqlite3 v1.14.19 // indirect
github.com/nicksnyder/go-i18n/v2 v2.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
@ -33,7 +31,7 @@ require (
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.17.0 // indirect golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.5.4 // indirect gorm.io/driver/sqlite v1.5.4 // indirect
gorm.io/gorm v1.25.5 // indirect gorm.io/gorm v1.25.5 // indirect

View File

@ -42,8 +42,6 @@ fyne.io/fyne/v2 v2.4.3/go.mod h1:1h3BKxmQYRJlr2g+RGVxedzr6vLVQ/AJmFWcF9CJnoQ=
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e h1:Hvs+kW2VwCzNToF3FmnIAzmivNgrclwPgoUdVSrjkP8= fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e h1:Hvs+kW2VwCzNToF3FmnIAzmivNgrclwPgoUdVSrjkP8=
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE= fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
@ -228,8 +226,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/nicksnyder/go-i18n/v2 v2.3.0 h1:2NPsCsNFCVd7i+Su0xYsBrIhS3bE2XMv5gNTft2O+PQ=
github.com/nicksnyder/go-i18n/v2 v2.3.0/go.mod h1:nxYSZE9M0bf3Y70gPQjN9ha7XNHX7gMc814+6wVyEI4=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -481,8 +477,6 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

View File

@ -5,12 +5,11 @@ import (
"errors" "errors"
"ffmpegGui/convertor" "ffmpegGui/convertor"
"ffmpegGui/helper" "ffmpegGui/helper"
"ffmpegGui/localizer"
"ffmpegGui/setting" "ffmpegGui/setting"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/nicksnyder/go-i18n/v2/i18n"
"io" "io"
"regexp" "regexp"
"runtime"
"strconv" "strconv"
"strings" "strings"
) )
@ -19,35 +18,23 @@ type ConvertorHandler struct {
convertorService convertor.ServiceContract convertorService convertor.ServiceContract
convertorView convertor.ViewContract convertorView convertor.ViewContract
settingView setting.ViewContract settingView setting.ViewContract
localizerView localizer.ViewContract
settingRepository setting.RepositoryContract settingRepository setting.RepositoryContract
localizerService localizer.ServiceContract
} }
func NewConvertorHandler( func NewConvertorHandler(
convertorService convertor.ServiceContract, convertorService convertor.ServiceContract,
convertorView convertor.ViewContract, convertorView convertor.ViewContract,
settingView setting.ViewContract, settingView setting.ViewContract,
localizerView localizer.ViewContract,
settingRepository setting.RepositoryContract, settingRepository setting.RepositoryContract,
localizerService localizer.ServiceContract,
) *ConvertorHandler { ) *ConvertorHandler {
return &ConvertorHandler{ return &ConvertorHandler{
convertorService: convertorService, convertorService,
convertorView: convertorView, convertorView,
settingView: settingView, settingView,
localizerView: localizerView, settingRepository,
settingRepository: settingRepository,
localizerService: localizerService,
} }
} }
func (h ConvertorHandler) LanguageSelection() {
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
h.GetConvertor()
})
}
func (h ConvertorHandler) GetConvertor() { func (h ConvertorHandler) GetConvertor() {
if h.checkingFFPathUtilities() == true { if h.checkingFFPathUtilities() == true {
h.convertorView.Main(h.runConvert) h.convertorView.Main(h.runConvert)
@ -61,7 +48,7 @@ func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, pro
if err != nil { if err != nil {
return err return err
} }
progress := NewProgress(totalDuration, progressbar, h.localizerService) progress := NewProgress(totalDuration, progressbar)
return h.convertorService.RunConvert( return h.convertorService.RunConvert(
convertor.ConvertSetting{ convertor.ConvertSetting{
@ -82,7 +69,12 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
return true return true
} }
pathsToFF := getPathsToFF() var pathsToFF []convertor.FFPathUtilities
if runtime.GOOS == "windows" {
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}}
} else {
pathsToFF = []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
}
for _, item := range pathsToFF { for _, item := range pathsToFF {
ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(item.FFmpeg) ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(item.FFmpeg)
if ffmpegChecking == false { if ffmpegChecking == false {
@ -105,18 +97,12 @@ 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 {
errorText := h.localizerService.GetMessage(&i18n.LocalizeConfig{ return errors.New("это не FFmpeg")
MessageID: "errorFFmpeg",
})
return errors.New(errorText)
} }
ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(ffprobePath) ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(ffprobePath)
if ffprobeChecking == false { if ffprobeChecking == false {
errorText := h.localizerService.GetMessage(&i18n.LocalizeConfig{ return errors.New("это не FFprobe")
MessageID: "errorFFprobe",
})
return errors.New(errorText)
} }
ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath} ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath}
@ -144,18 +130,16 @@ func (h ConvertorHandler) checkingFFPath() bool {
} }
type progress struct { type progress struct {
totalDuration float64 totalDuration float64
progressbar *widget.ProgressBar progressbar *widget.ProgressBar
protocol string protocol string
localizerService localizer.ServiceContract
} }
func NewProgress(totalDuration float64, progressbar *widget.ProgressBar, localizerService localizer.ServiceContract) progress { func NewProgress(totalDuration float64, progressbar *widget.ProgressBar) progress {
return progress{ return progress{
totalDuration: totalDuration, totalDuration: totalDuration,
progressbar: progressbar, progressbar: progressbar,
protocol: "pipe:", protocol: "pipe:",
localizerService: localizerService,
} }
} }
@ -185,15 +169,10 @@ func (p progress) Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error {
scannerOut := bufio.NewScanner(stdOut) scannerOut := bufio.NewScanner(stdOut)
for scannerOut.Scan() { for scannerOut.Scan() {
data := scannerOut.Text() if isProcessCompleted != true {
if strings.Contains(data, "progress=end") {
p.progressbar.Value = p.totalDuration
p.progressbar.Refresh()
isProcessCompleted = true isProcessCompleted = true
break
} }
data := scannerOut.Text()
re := regexp.MustCompile(`frame=(\d+)`) re := regexp.MustCompile(`frame=(\d+)`)
a := re.FindAllStringSubmatch(data, -1) a := re.FindAllStringSubmatch(data, -1)
@ -204,6 +183,11 @@ func (p progress) Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error {
} }
progress = float64(c) progress = float64(c)
} }
if strings.Contains(data, "progress=end") {
p.progressbar.Value = p.totalDuration
p.progressbar.Refresh()
isProcessCompleted = true
}
if p.progressbar.Value != progress { if p.progressbar.Value != progress {
p.progressbar.Value = progress p.progressbar.Value = progress
p.progressbar.Refresh() p.progressbar.Refresh()
@ -212,9 +196,7 @@ func (p progress) Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error {
if isProcessCompleted == false { if isProcessCompleted == false {
if len(errorText) == 0 { if len(errorText) == 0 {
errorText = p.localizerService.GetMessage(&i18n.LocalizeConfig{ errorText = "не смогли отконвертировать видео"
MessageID: "errorConverter",
})
} }
return errors.New(errorText) return errors.New(errorText)
} }

View File

@ -1,10 +0,0 @@
//go:build !windows
// +build !windows
package handler
import "ffmpegGui/convertor"
func getPathsToFF() []convertor.FFPathUtilities {
return []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
}

View File

@ -1,10 +0,0 @@
//go:build windows
// +build windows
package handler
import "ffmpegGui/convertor"
func getPathsToFF() []convertor.FFPathUtilities {
return []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}}
}

View File

@ -1,11 +1,10 @@
package helper package helper
import ( import "runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
)
func FileDialogResize(fileDialog *dialog.FileDialog, w fyne.Window) { func PathSeparator() string {
contentSize := w.Content().Size() if runtime.GOOS == "windows" {
fileDialog.Resize(fyne.Size{Width: contentSize.Width - 50, Height: contentSize.Height - 50}) return "\\"
}
return "/"
} }

View File

@ -1,8 +0,0 @@
//go:build !windows
// +build !windows
package helper
func PathSeparator() string {
return "/"
}

View File

@ -1,8 +0,0 @@
//go:build windows
// +build windows
package helper
func PathSeparator() string {
return "\\"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,75 +0,0 @@
[buttonForSelectedDirTitle]
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
other = "Folder where it will be saved:"
[checkboxOverwriteOutputFilesTitle]
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
other = "Allow file to be overwritten"
[choose]
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
other = "choose"
[converterVideoFilesSubmitTitle]
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
other = "Convert"
[converterVideoFilesTitle]
hash = "sha1-4d972809e4c7f9c9ff2c110a126bbc183c9429ce"
other = "Converter video files to mp4"
[error]
hash = "sha1-a7df8f8b5d754f226ac4cb320577fe692b33e483"
other = "An error has occurred!"
[errorConverter]
hash = "sha1-55ebddceddb8b044e33cc3893ec2eba7bbd9fcf9"
other = "Couldn't convert video"
[errorDatabase]
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "could not create file 'database' in folder 'data'"
[errorFFmpeg]
hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0"
other = "this is not FFmpeg"
[errorFFprobe]
hash = "sha1-86d1b0b4c4ccd6a4f71e758fc67ce11aff4ba9b8"
other = "this is not FFprobe"
[errorSelectedFolderSave]
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
other = "You haven't selected a folder to save!"
[fileVideoForConversionTitle]
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
other = "File for conversion:"
[languageSelectionFormHead]
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
other = "Switch language"
[languageSelectionHead]
hash = "sha1-daf1108fc10d3b1a908288d611f749b3cc651e4b"
other = "Choose language"
[pathToFfmpeg]
hash = "sha1-2eba439f365640ff77e0ed6a7486fcb662573850"
other = "Path to ffmpeg:"
[pathToFfprobe]
hash = "sha1-02ad53337801906f8ebfee4616100dd9f43eabd7"
other = "Path to ffprobe:"
[save]
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
other = "Save"
[selectFFPathTitle]
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
other = "Specify the path to FFmpeg and FFprobe"
[titleDownloadLink]
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
other = "You can download it from here"

View File

@ -1,75 +0,0 @@
[buttonForSelectedDirTitle]
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
other = "Файлды сақтауға арналған каталог:"
[checkboxOverwriteOutputFilesTitle]
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
other = "Файлды қайта жазуға рұқсат беріңіз"
[choose]
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
other = "таңдау"
[converterVideoFilesSubmitTitle]
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
other = "Файлды түрлендіру"
[converterVideoFilesTitle]
hash = "sha1-4d972809e4c7f9c9ff2c110a126bbc183c9429ce"
other = "Бейне файлдарын mp4 форматына түрлендіру"
[error]
hash = "sha1-a7df8f8b5d754f226ac4cb320577fe692b33e483"
other = "Қате орын алды!"
[errorConverter]
hash = "sha1-55ebddceddb8b044e33cc3893ec2eba7bbd9fcf9"
other = "Бейнені түрлендіру мүмкін болмады"
[errorDatabase]
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "'data' қалтасында 'database' файлын жасау мүмкін болмады"
[errorFFmpeg]
hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0"
other = "бұл FFmpeg емес"
[errorFFprobe]
hash = "sha1-86d1b0b4c4ccd6a4f71e758fc67ce11aff4ba9b8"
other = "бұл FFprobe емес"
[errorSelectedFolderSave]
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
other = "Сіз сақталатын қалтаны таңдамадыңыз!"
[fileVideoForConversionTitle]
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
other = "Түрлендіруге арналған файл:"
[languageSelectionFormHead]
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
other = "Тілді ауыстыру"
[languageSelectionHead]
hash = "sha1-daf1108fc10d3b1a908288d611f749b3cc651e4b"
other = "Тілді таңдаңыз"
[pathToFfmpeg]
hash = "sha1-2eba439f365640ff77e0ed6a7486fcb662573850"
other = "ffmpeg жол:"
[pathToFfprobe]
hash = "sha1-02ad53337801906f8ebfee4616100dd9f43eabd7"
other = "ffprobe жол:"
[save]
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
other = "Сақтау"
[selectFFPathTitle]
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
other = "FFmpeg және FFprobe жолын көрсетіңіз"
[titleDownloadLink]
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
other = "Сіз оны осы жерден жүктей аласыз"

View File

@ -1,19 +0,0 @@
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
choose = "выбрать"
converterVideoFilesSubmitTitle = "Конвертировать"
converterVideoFilesTitle = "Конвертор видео файлов в mp4"
error = "Произошла ошибка!"
errorConverter = "не смогли отконвертировать видео"
errorDatabase = "не смогли создать файл 'database' в папке 'data'"
errorFFmpeg = "это не FFmpeg"
errorFFprobe = "это не FFprobe"
errorSelectedFolderSave = "Не выбрали папку для сохранения!"
fileVideoForConversionTitle = "Файл для ковертации:"
languageSelectionFormHead = "Переключить язык"
languageSelectionHead = "Выберите язык"
pathToFfmpeg = "Путь к ffmpeg:"
pathToFfprobe = "Путь к ffprobe:"
save = "Сохранить"
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
titleDownloadLink = "Скачать можно от сюда"

View File

@ -1,128 +0,0 @@
package localizer
import (
"github.com/BurntSushi/toml"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/text/language/display"
"path/filepath"
"sort"
)
type ServiceContract interface {
GetLanguages() []Lang
GetMessage(localizeConfig *i18n.LocalizeConfig) string
SetCurrentLanguage(lang Lang) error
GetCurrentLanguage() *CurrentLanguage
}
type Lang struct {
Code string
Title string
}
type CurrentLanguage struct {
Lang Lang
localizer *i18n.Localizer
localizerDefault *i18n.Localizer
}
type Service struct {
bundle *i18n.Bundle
languages []Lang
currentLanguage *CurrentLanguage
}
func NewService(directory string, languageDefault language.Tag) (*Service, error) {
bundle := i18n.NewBundle(languageDefault)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
languages, err := initLanguages(directory, bundle)
if err != nil {
return nil, err
}
localizerDefault := i18n.NewLocalizer(bundle, languageDefault.String())
return &Service{
bundle: bundle,
languages: languages,
currentLanguage: &CurrentLanguage{
Lang: Lang{
Code: languageDefault.String(),
Title: cases.Title(languageDefault).String(display.Self.Name(languageDefault)),
},
localizer: localizerDefault,
localizerDefault: localizerDefault,
},
}, nil
}
func initLanguages(directory string, bundle *i18n.Bundle) ([]Lang, error) {
var languages []Lang
files, err := filepath.Glob(directory + "/active.*.toml")
if err != nil {
return nil, err
}
for _, file := range files {
language, err := bundle.LoadMessageFile(file)
if err != nil {
return nil, err
}
title := cases.Title(language.Tag).String(display.Self.Name(language.Tag))
languages = append(languages, Lang{Code: language.Tag.String(), Title: title})
}
sort.Sort(languagesSort(languages))
return languages, nil
}
func (s Service) GetLanguages() []Lang {
return s.languages
}
func (s Service) GetMessage(localizeConfig *i18n.LocalizeConfig) string {
message, err := s.GetCurrentLanguage().localizer.Localize(localizeConfig)
if err != nil {
message, err = s.GetCurrentLanguage().localizerDefault.Localize(localizeConfig)
if err != nil {
return err.Error()
}
}
return message
}
func (s Service) SetCurrentLanguage(lang Lang) error {
s.currentLanguage.Lang = lang
s.currentLanguage.localizer = i18n.NewLocalizer(s.bundle, lang.Code)
return nil
}
func (s Service) GetCurrentLanguage() *CurrentLanguage {
return s.currentLanguage
}
type languagesSort []Lang
func (l languagesSort) Len() int { return len(l) }
func (l languagesSort) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l languagesSort) Less(i, j int) bool {
return languagePriority(l[i]) < languagePriority(l[j])
}
func languagePriority(l Lang) int {
priority := 0
switch l.Code {
case "ru":
priority = -3
case "kk":
priority = -2
case "en":
priority = -1
}
return priority
}

View File

@ -1,76 +0,0 @@
package localizer
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"github.com/nicksnyder/go-i18n/v2/i18n"
)
type ViewContract interface {
LanguageSelection(funcSelected func(lang Lang))
}
type View struct {
w fyne.Window
localizerService ServiceContract
}
func NewView(w fyne.Window, localizerService ServiceContract) *View {
return &View{
w: w,
localizerService: localizerService,
}
}
func (v View) LanguageSelection(funcSelected func(lang Lang)) {
languages := v.localizerService.GetLanguages()
listView := widget.NewList(
func() int {
return len(languages)
},
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(i widget.ListItemID, o fyne.CanvasObject) {
block := o.(*widget.Label)
block.SetText(languages[i].Title)
})
listView.OnSelected = func(id widget.ListItemID) {
_ = v.localizerService.SetCurrentLanguage(languages[id])
funcSelected(languages[id])
}
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "languageSelectionHead",
})
v.w.SetContent(widget.NewCard(messageHead, "", listView))
}
func LanguageSelectionForm(localizerService ServiceContract, funcSelected func(lang Lang)) fyne.CanvasObject {
languages := localizerService.GetLanguages()
currentLanguage := localizerService.GetCurrentLanguage()
listView := widget.NewList(
func() int {
return len(languages)
},
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(i widget.ListItemID, o fyne.CanvasObject) {
block := o.(*widget.Label)
block.SetText(languages[i].Title)
if languages[i].Code == currentLanguage.Lang.Code {
block.TextStyle = fyne.TextStyle{Bold: true}
}
})
listView.OnSelected = func(id widget.ListItemID) {
_ = localizerService.SetCurrentLanguage(languages[id])
funcSelected(languages[id])
}
messageHead := localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "languageSelectionFormHead",
})
return widget.NewCard(messageHead, "", listView)
}

View File

@ -3,44 +3,30 @@ package main
import ( import (
"errors" "errors"
"ffmpegGui/convertor" "ffmpegGui/convertor"
error2 "ffmpegGui/error" myError "ffmpegGui/error"
"ffmpegGui/handler" "ffmpegGui/handler"
"ffmpegGui/localizer"
"ffmpegGui/migration" "ffmpegGui/migration"
"ffmpegGui/setting" "ffmpegGui/setting"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"golang.org/x/text/language"
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
"os" "os"
) )
//const appVersion string = "0.2.0" //const appVersion string = "0.1.1"
func main() { func main() {
a := app.New() a := app.New()
iconResource, err := fyne.LoadResourceFromPath("icon.png")
if err == nil {
a.SetIcon(iconResource)
}
w := a.NewWindow("GUI FFMpeg!") w := a.NewWindow("GUI FFMpeg!")
w.Resize(fyne.Size{Width: 800, Height: 600}) w.Resize(fyne.Size{Width: 800, Height: 600})
w.CenterOnScreen() w.CenterOnScreen()
localizerService, err := localizer.NewService("languages", language.Russian) errorView := myError.NewView(w)
if err != nil {
panicErrorLang(w, err)
w.ShowAndRun()
return
}
errorView := error2.NewView(w, localizerService)
if canCreateFile("data/database") != true { if canCreateFile("data/database") != true {
errorView.PanicErrorWriteDirectoryData() errorView.PanicError(errors.New("не смогли создать файл 'database' в папке 'data'"))
w.ShowAndRun() w.ShowAndRun()
return return
} }
@ -77,14 +63,13 @@ func main() {
ffPathUtilities := convertor.FFPathUtilities{FFmpeg: pathFFmpeg, FFprobe: pathFFprobe} ffPathUtilities := convertor.FFPathUtilities{FFmpeg: pathFFmpeg, FFprobe: pathFFprobe}
localizerView := localizer.NewView(w, localizerService) convertorView := convertor.NewView(w)
convertorView := convertor.NewView(w, localizerService) settingView := setting.NewView(w)
settingView := setting.NewView(w, localizerService)
convertorService := convertor.NewService(ffPathUtilities) convertorService := convertor.NewService(ffPathUtilities)
defer appCloseWithConvert(convertorService) defer appCloseWithConvert(convertorService)
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, localizerView, settingRepository, localizerService) mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, settingRepository)
mainHandler.LanguageSelection() mainHandler.GetConvertor()
w.ShowAndRun() w.ShowAndRun()
} }
@ -110,10 +95,3 @@ func canCreateFile(path string) bool {
_ = file.Close() _ = file.Close()
return true return true
} }
func panicErrorLang(w fyne.Window, err error) {
w.SetContent(container.NewVBox(
widget.NewLabel("Произошла ошибка!"),
widget.NewLabel("произошла ошибка при получении языковых переводах. \n\r"+err.Error()),
))
}

View File

@ -1,14 +1,11 @@
package setting package setting
import ( import (
"ffmpegGui/helper"
"ffmpegGui/localizer"
"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"
"fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/nicksnyder/go-i18n/v2/i18n"
"image/color" "image/color"
"net/url" "net/url"
) )
@ -18,15 +15,11 @@ type ViewContract interface {
} }
type View struct { type View struct {
w fyne.Window w fyne.Window
localizerService localizer.ServiceContract
} }
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View { func NewView(w fyne.Window) *View {
return &View{ return &View{w}
w: w,
localizerService: localizerService,
}
} }
func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) { func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) {
@ -45,37 +38,14 @@ func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) erro
form := &widget.Form{ form := &widget.Form{
Items: []*widget.FormItem{ Items: []*widget.FormItem{
{ {Text: "Скачать можно от сюда", Widget: link},
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{ {Text: "Путь к ffmpeg:", Widget: buttonFFmpeg},
MessageID: "titleDownloadLink", {Widget: buttonFFmpegMessage},
}), {Text: "Путь к ffprobe:", Widget: buttonFFprobe},
Widget: link, {Widget: buttonFFprobeMessage},
}, {Widget: errorMessage},
{
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "pathToFfmpeg",
}),
Widget: buttonFFmpeg,
},
{
Widget: buttonFFmpegMessage,
},
{
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "pathToFfprobe",
}),
Widget: buttonFFprobe,
},
{
Widget: buttonFFprobeMessage,
},
{
Widget: errorMessage,
},
}, },
SubmitText: v.localizerService.GetMessage(&i18n.LocalizeConfig{ SubmitText: "Сохранить",
MessageID: "save",
}),
OnSubmit: func() { OnSubmit: func() {
err := save(string(*ffmpegPath), string(*ffprobePath)) err := save(string(*ffmpegPath), string(*ffprobePath))
if err != nil { if err != nil {
@ -83,10 +53,7 @@ func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) erro
} }
}, },
} }
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ v.w.SetContent(widget.NewCard("Укажите путь к FFmpeg и к FFprobe", "", container.NewVBox(form)))
MessageID: "selectFFPathTitle",
})
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(form)))
} }
func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, buttonMessage *canvas.Text) { func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
@ -97,11 +64,7 @@ func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, bu
buttonMessage.TextSize = 16 buttonMessage.TextSize = 16
buttonMessage.TextStyle = fyne.TextStyle{Bold: true} buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{ button = widget.NewButton("выбрать", func() {
MessageID: "choose",
})
button = widget.NewButton(buttonTitle, func() {
fileDialog := dialog.NewFileOpen( fileDialog := dialog.NewFileOpen(
func(r fyne.URIReadCloser, err error) { func(r fyne.URIReadCloser, err error) {
if err != nil { if err != nil {
@ -118,7 +81,6 @@ func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, bu
buttonMessage.Text = r.URI().Path() buttonMessage.Text = r.URI().Path()
setStringSuccessStyle(buttonMessage) setStringSuccessStyle(buttonMessage)
}, v.w) }, v.w)
helper.FileDialogResize(fileDialog, v.w)
fileDialog.Show() fileDialog.Show()
}) })