forked from wxbool/video-srt-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
805 lines (727 loc) · 23.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"log"
"runtime"
"strings"
"time"
. "videosrt/app"
"videosrt/app/ffmpeg"
"videosrt/app/tool"
)
//应用版本号
const APP_VERSION = "0.2.8"
var AppRootDir string
var mw *MyMainWindow
var (
outputSrtChecked *walk.CheckBox
outputLrcChecked *walk.CheckBox
outputTxtChecked *walk.CheckBox
)
func init() {
//设置可同时执行的最大CPU数
runtime.GOMAXPROCS(runtime.NumCPU())
//MY Window
mw = new(MyMainWindow)
AppRootDir = GetAppRootDir()
if AppRootDir == "" {
panic("应用根目录获取失败")
}
//校验ffmpeg环境
if e := ffmpeg.VailFfmpegLibrary(); e != nil {
//尝试自动引入 ffmpeg 环境
ffmpeg.VailTempFfmpegLibrary(AppRootDir)
}
}
func main() {
var taskFiles = new(TaskHandleFile)
var logText *walk.TextEdit
var operateEngineDb *walk.DataBinder
var operateTranslateEngineDb *walk.DataBinder
var operateTranslateDb *walk.DataBinder
var operateDb *walk.DataBinder
var operateFrom = new(OperateFrom)
var startBtn *walk.PushButton
var engineOptionsBox *walk.ComboBox
var translateEngineOptionsBox *walk.ComboBox
var dropFilesEdit *walk.TextEdit
var appSetings = Setings.GetCacheAppSetingsData()
//初始化展示配置
operateFrom.Init(appSetings)
var videosrt = NewApp(AppRootDir)
var tasklog = NewTasklog()
//注册日志事件
videosrt.SetLogHandler(func(s string, video string) {
baseName := tool.GetFileBaseName(video)
//fmt.Println("日志:" , s , baseName)
//fmt.Println("\r\n")
//fmt.Println("\r\n")
//fmt.Println("\r\n")
strs := strings.Join([]string{"【" , baseName , "】" , s} , "")
//追加日志
tasklog.AppendLogText(strs)
})
//字幕输出目录
videosrt.SetSrtDir(appSetings.SrtFileDir)
//注册多任务
var multitask = NewVideoMultitask(appSetings.MaxConcurrency)
if err := (MainWindow{
AssignTo: &mw.MainWindow,
Icon:"./data/img/index.png",
Title: "VideoSrt - 识别视频语音生成字幕文件的小工具" + " - " + APP_VERSION,
ToolBar: ToolBar{
ButtonStyle: ToolBarButtonImageBeforeText,
Items: []MenuItem{
Menu{
Text:"打开",
Image: "./data/img/open.png",
Items: []MenuItem{
Action{
Image: "./data/img/media.png",
Text: "媒体文件",
OnTriggered: func() {
dlg := new(walk.FileDialog)
//选择待操作的文件列表
//dlg.FilePath = mw.prevFilePath
dlg.Filter = "Media Files (*.mp4;*.mpeg;*.mkv;*.wmv;*.avi;*.m4v;*.mov;*.flv;*.rmvb;*.3gp;*.f4v;*.mp3;*.wav;*.aac;*.wma;*.flac)|*.mp4;*.mpeg;*.mkv;*.wmv;*.avi;*.m4v;*.mov;*.flv;*.rmvb;*.3gp;*.f4v;*.mp3;*.wav;*.aac;*.wma;*.flac"
dlg.Title = "选择待操作的媒体文件"
ok, err := dlg.ShowOpenMultiple(mw);
if err != nil {
mw.NewErrormationTips("错误" , err.Error())
return
}
if ok == false {
return
}
//校验文件数量
if len(dlg.FilePaths) == 0 {
return
}
//检测文件列表
result , err := VaildateHandleFiles(dlg.FilePaths)
if err != nil {
mw.NewErrormationTips("错误" , err.Error())
return
}
taskFiles.Files = result
dropFilesEdit.SetText(strings.Join(result, "\r\n"))
},
},
},
},
Menu{
Text: "新建",
Image: "./data/img/new.png",
Items: []MenuItem{
Action{
Image: "./data/img/voice.png",
Text: "语音引擎(阿里云)",
OnTriggered: func() {
mw.RunSpeechEngineSetingDialog(mw , func() {
thisData := Engine.GetEngineOptionsSelects()
if appSetings.CurrentEngineId == 0 {
appSetings.CurrentEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = engineOptionsBox.SetModel(thisData)
//重置index
engIndex := Engine.GetCurrentIndex(thisData , appSetings.CurrentEngineId)
if engIndex != -1 {
_ = engineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.EngineId = appSetings.CurrentEngineId
})
},
},
Action{
Image: "./data/img/translate.png",
Text: "翻译引擎(百度翻译)",
OnTriggered: func() {
mw.RunBaiduTranslateEngineSetingDialog(mw , func() {
thisData := Translate.GetTranslateEngineOptionsSelects()
if appSetings.CurrentTranslateEngineId == 0 {
appSetings.CurrentTranslateEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = translateEngineOptionsBox.SetModel(thisData)
//重置index
engIndex := Translate.GetCurrentTranslateEngineIndex(thisData , appSetings.CurrentTranslateEngineId)
if engIndex != -1 {
_ = translateEngineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.TranslateEngineId = appSetings.CurrentTranslateEngineId
})
},
},
Action{
Image: "./data/img/translate.png",
Text: "翻译引擎(腾讯云)",
OnTriggered: func() {
mw.RunTengxunyunTranslateEngineSetingDialog(mw , func() {
thisData := Translate.GetTranslateEngineOptionsSelects()
if appSetings.CurrentTranslateEngineId == 0 {
appSetings.CurrentTranslateEngineId = thisData[0].Id
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
}
//重新加载选项
_ = translateEngineOptionsBox.SetModel(thisData)
//重置index
engIndex := Translate.GetCurrentTranslateEngineIndex(thisData , appSetings.CurrentTranslateEngineId)
if engIndex != -1 {
_ = translateEngineOptionsBox.SetCurrentIndex(engIndex)
}
operateFrom.TranslateEngineId = appSetings.CurrentTranslateEngineId
})
},
},
},
},
Menu{
Text: "设置",
Image: "./data/img/setings.png",
Items: []MenuItem{
Action{
Text: "OSS对象存储设置",
Image: "./data/img/oss.png",
OnTriggered: func() {
mw.RunObjectStorageSetingDialog(mw)
},
},
Action{
Text: "软件设置",
Image: "./data/img/app-setings.png",
OnTriggered: func() {
mw.RunAppSetingDialog(mw , func(setings *AppSetings) {
//更新配置
appSetings.MaxConcurrency = setings.MaxConcurrency
appSetings.SrtFileDir = setings.SrtFileDir
//appSetings.OutputType = setings.OutputType
//appSetings.OutputEncode = setings.OutputEncode
//appSetings.SoundTrack = setings.SoundTrack
appSetings.CloseNewVersionMessage = setings.CloseNewVersionMessage
//videosrt.SetSoundTrack( setings.SoundTrack )
//videosrt.SetOutputType( setings.OutputType )
//videosrt.SetOutputEncode( setings.OutputEncode )
videosrt.SetSrtDir( setings.SrtFileDir )
multitask.SetMaxConcurrencyNumber( setings.MaxConcurrency )
})
},
},
},
},
Menu{
Text: "关于/支持",
Image: "./data/img/about.png",
Items: []MenuItem{
Action{
Text: "github",
Image: "./data/img/github.png",
OnTriggered: mw.OpenAboutGithub,
},
Action{
Text: "gitee",
Image: "./data/img/gitee.png",
OnTriggered: mw.OpenAboutGitee,
},
Action{
Text: "帮助文档",
Image: "./data/img/version.png",
OnTriggered: func() {
_ = tool.OpenUrl("https://www.yuque.com/viggo-t7cdi/videosrt")
},
},
},
},
},
},
Size: Size{800, 600},
MinSize: Size{300, 500},
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
Composite{
MinSize:Size{Height:31,Width:400},
DataBinder: DataBinder{
AssignTo: &operateEngineDb,
DataSource: operateFrom,
},
Layout: Grid{Columns: 3},
Children: []Widget{
Label{
Text: "语音引擎:",
},
ComboBox{
AssignTo:&engineOptionsBox,
Value: Bind("EngineId", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: Engine.GetEngineOptionsSelects(),
OnCurrentIndexChanged: func() {
_ = operateEngineDb.Submit()
if operateFrom.EngineId == 0 {
return
}
appSetings.CurrentEngineId = operateFrom.EngineId
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
PushButton{
Text: "删除",
MaxSize:Size{50 , 55},
OnClicked: func() {
var thisEngineOptions = make([]*EngineSelects , 0)
thisEngineOptions = Engine.GetEngineOptionsSelects()
//删除校验
if appSetings.CurrentEngineId == 0 {
mw.NewErrormationTips("错误" , "请选择要操作的语音引擎")
return
}
if len(thisEngineOptions) <= 1 {
mw.NewErrormationTips("错误" , "不能删除全部语音引擎")
return
}
//删除引擎
if ok := Engine.RemoveCacheAliyunEngineData(appSetings.CurrentEngineId);ok == false {
//删除失败
mw.NewErrormationTips("错误" , "语音引擎删除失败")
return
}
thisEngineOptions = Engine.GetEngineOptionsSelects()
//重新加载列表
_ = engineOptionsBox.SetModel(thisEngineOptions)
appSetings.CurrentEngineId = thisEngineOptions[0].Id
operateFrom.EngineId = appSetings.CurrentEngineId
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
//更新下标
_ = engineOptionsBox.SetCurrentIndex(0)
},
},
},
},
Composite{
MinSize:Size{Height:31,Width:400},
DataBinder: DataBinder{
AssignTo: &operateTranslateEngineDb,
DataSource: operateFrom,
},
Layout: Grid{Columns: 3},
Children: []Widget{
Label{
Text: "翻译引擎:",
},
ComboBox{
AssignTo:&translateEngineOptionsBox,
Value: Bind("TranslateEngineId", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: Translate.GetTranslateEngineOptionsSelects(),
OnCurrentIndexChanged: func() {
_ = operateTranslateEngineDb.Submit()
if operateFrom.TranslateEngineId == 0 {
return
}
appSetings.CurrentTranslateEngineId = operateFrom.TranslateEngineId
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
PushButton{
Text: "删除",
MaxSize:Size{50 , 55},
OnClicked: func() {
var thisEngineOptions = make([]*TranslateEngineSelects , 0)
thisEngineOptions = Translate.GetTranslateEngineOptionsSelects()
//删除校验
if appSetings.CurrentTranslateEngineId == 0 {
mw.NewErrormationTips("错误" , "请选择要删除的翻译引擎")
return
}
if len(thisEngineOptions) <= 1 {
mw.NewErrormationTips("错误" , "不能删除全部翻译引擎")
return
}
//删除引擎
if ok := Translate.RemoveCacheTranslateEngineData(appSetings.CurrentTranslateEngineId);ok == false {
//删除失败
mw.NewErrormationTips("错误" , "翻译引擎删除失败")
return
}
thisEngineOptions = Translate.GetTranslateEngineOptionsSelects()
//重新加载列表
_ = translateEngineOptionsBox.SetModel(thisEngineOptions)
appSetings.CurrentTranslateEngineId = thisEngineOptions[0].Id
operateFrom.TranslateEngineId = appSetings.CurrentTranslateEngineId
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
//更新下标
_ = translateEngineOptionsBox.SetCurrentIndex(0)
},
},
},
},
},
},
/*翻译设置*/
HSplitter{
Children:[]Widget{
Composite{
DataBinder: DataBinder{
AssignTo: &operateTranslateDb,
DataSource: operateFrom,
},
Layout: Grid{Columns: 4},
Children: []Widget{
Label{
Text: "翻译设置:",
},
CheckBox{
Text:"开启翻译",
Checked: Bind("TranslateSwitch"),
OnClicked: func() {
_ = operateTranslateDb.Submit()
appSetings.TranslateSwitch = operateFrom.TranslateSwitch
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
CheckBox{
Text:"双语字幕",
ColumnSpan: 2,
Checked: Bind("BilingualSubtitleSwitch"),
OnClicked: func() {
_ = operateTranslateDb.Submit()
appSetings.BilingualSubtitleSwitch = operateFrom.BilingualSubtitleSwitch
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
//输入语言
Label{
Text: "输入语言:",
},
ComboBox{
Value: Bind("InputLanguage", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetTranslateInputLanguageOptionsSelects(),
ColumnSpan: 3,
MaxSize:Size{Width:80},
OnCurrentIndexChanged: func() {
_ = operateTranslateDb.Submit()
appSetings.InputLanguage = operateFrom.InputLanguage
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
//输出语言
Label{
Text: "输出语言:",
},
ComboBox{
Value: Bind("OutputLanguage", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetTranslateOutputLanguageOptionsSelects(),
ColumnSpan: 3,
MaxSize:Size{Width:80},
OnCurrentIndexChanged: func() {
_ = operateTranslateDb.Submit()
appSetings.OutputLanguage = operateFrom.OutputLanguage
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
},
},
},
},
/*输出设置*/
HSplitter{
Children:[]Widget{
Composite{
DataBinder: DataBinder{
AssignTo: &operateDb,
DataSource: operateFrom,
},
Layout: Grid{Columns: 4},
Children: []Widget{
Label{
Text: "输出文件:",
},
CheckBox{
AssignTo:&outputSrtChecked,
Text:"SRT文件",
Checked: Bind("OutputSrt"),
OnClicked: func() {
_ = operateDb.Submit()
operateFrom.LoadOutputType(OUTPUT_SRT)
appSetings.OutputType = operateFrom.OutputType
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
outputSrtChecked.SetChecked(operateFrom.OutputSrt)
outputLrcChecked.SetChecked(operateFrom.OutputLrc)
outputTxtChecked.SetChecked(operateFrom.OutputTxt)
},
},
CheckBox{
AssignTo:&outputLrcChecked,
Text:"LRC文件",
Checked: Bind("OutputLrc"),
OnClicked: func() {
_ = operateDb.Submit()
operateFrom.LoadOutputType(OUTPUT_LRC)
appSetings.OutputType = operateFrom.OutputType
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
outputSrtChecked.SetChecked(operateFrom.OutputSrt)
outputLrcChecked.SetChecked(operateFrom.OutputLrc)
outputTxtChecked.SetChecked(operateFrom.OutputTxt)
},
},
CheckBox{
AssignTo:&outputTxtChecked,
Text:"普通文本",
Checked: Bind("OutputTxt"),
OnClicked: func() {
_ = operateDb.Submit()
operateFrom.LoadOutputType(OUTPUT_STRING)
appSetings.OutputType = operateFrom.OutputType
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
outputSrtChecked.SetChecked(operateFrom.OutputSrt)
outputLrcChecked.SetChecked(operateFrom.OutputLrc)
outputTxtChecked.SetChecked(operateFrom.OutputTxt)
},
},
//输出文件编码
Label{
Text: "输出编码:",
},
ComboBox{
Value: Bind("OutputEncode", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetOutputEncodeOptionsSelects(),
ColumnSpan: 3,
MaxSize:Size{Width:80},
OnCurrentIndexChanged: func() {
_ = operateDb.Submit()
appSetings.OutputEncode = operateFrom.OutputEncode
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
//输出文件音轨
Label{
Text: "输出音轨:",
},
ComboBox{
Value: Bind("SoundTrack", SelRequired{}),
BindingMember: "Id",
DisplayMember: "Name",
Model: GetSoundTrackSelects(),
ColumnSpan: 3,
MaxSize:Size{Width:60},
OnCurrentIndexChanged: func() {
_ = operateDb.Submit()
appSetings.SoundTrack = operateFrom.SoundTrack
//更新缓存
Setings.SetCacheAppSetingsData(appSetings)
},
},
},
},
},
},
HSplitter{
Children: []Widget{
TextEdit{
AssignTo: &dropFilesEdit,
ReadOnly: true,
Text: "将需要生成字幕的媒体文件,拖入放到这里\r\n\r\n支持的视频格式:.mp4 , .mpeg , .mkv , .wmv , .avi , .m4v , .mov , .flv , .rmvb , .3gp , .f4v\r\n支持的音频格式:.mp3 , .wav , .aac , .wma , .flac",
TextColor:walk.RGB(136 , 136 , 136),
VScroll:true,
},
TextEdit{
AssignTo: &logText,
ReadOnly: true,
Text:"这里是日志输出区",
TextColor:walk.RGB(136 , 136 , 136),
//HScroll:true,
VScroll:true,
},
},
},
HSplitter{
Children: []Widget{
PushButton{
AssignTo: &startBtn,
Text: "生成文件",
MinSize:Size{Height:50},
OnClicked: func() {
//设置随机种子
tool.SetRandomSeed()
if operateFrom.OutputType == 0 {
mw.NewErrormationTips("错误" , "请选择输出文件类型")
return
}
tlens := len(taskFiles.Files)
if tlens == 0 {
mw.NewErrormationTips("错误" , "请先拖入要处理的媒体文件")
return
}
ossData := Oss.GetCacheAliyunOssData()
if ossData.Endpoint == "" {
mw.NewErrormationTips("错误" , "请先设置Oss对象配置")
return
}
//查询应用配置
tempAppSetting := Setings.GetCacheAppSetingsData()
//查询选择的语音引擎
if tempAppSetting.CurrentEngineId == 0 {
mw.NewErrormationTips("错误" , "请先新建/选择语音引擎")
return
}
currentEngine , ok := Engine.GetEngineById(tempAppSetting.CurrentEngineId)
if !ok {
mw.NewErrormationTips("错误" , "你选择的语音引擎不存在")
return
}
//翻译配置
tempTranslateCfg := new(VideoSrtTranslateStruct)
tempTranslateCfg.TranslateSwitch = tempAppSetting.TranslateSwitch
tempTranslateCfg.BilingualSubtitleSwitch = tempAppSetting.BilingualSubtitleSwitch
tempTranslateCfg.InputLanguage = tempAppSetting.InputLanguage
tempTranslateCfg.OutputLanguage = tempAppSetting.OutputLanguage
if tempTranslateCfg.TranslateSwitch {
//校验选择的翻译引擎
if tempAppSetting.CurrentTranslateEngineId == 0 {
mw.NewErrormationTips("错误" , "你开启了翻译功能,请先新建/选择翻译引擎")
return
}
currentTranslateEngine , ok := Translate.GetTranslateEngineById(tempAppSetting.CurrentTranslateEngineId)
if !ok {
mw.NewErrormationTips("错误" , "你选择的翻译引擎不存在")
return
}
if currentTranslateEngine.Supplier == TRANSLATE_SUPPLIER_BAIDU {
tempTranslateCfg.BaiduTranslate = currentTranslateEngine.BaiduEngine
}
if currentTranslateEngine.Supplier == TRANSLATE_SUPPLIER_TENGXUNYUN {
tempTranslateCfg.TengxunyunTranslate = currentTranslateEngine.TengxunyunEngine
}
tempTranslateCfg.Supplier = currentTranslateEngine.Supplier //设置翻译供应商
}
//加载配置
videosrt.InitAppConfig(ossData , currentEngine)
videosrt.InitTranslateConfig(tempTranslateCfg)
videosrt.SetSrtDir(appSetings.SrtFileDir)
videosrt.SetSoundTrack(appSetings.SoundTrack)
videosrt.SetMaxConcurrency(appSetings.MaxConcurrency)
if appSetings.OutputType != 0 {
videosrt.SetOutputType(appSetings.OutputType)
}
if appSetings.OutputEncode != 0 {
videosrt.SetOutputEncode(appSetings.OutputEncode)
}
multitask.SetVideoSrt(videosrt)
//设置队列
multitask.SetQueueFile(taskFiles.Files)
var finish = false
startBtn.SetEnabled(false)
startBtn.SetText("任务运行中,请勿关闭软件窗口...")
//清除log
tasklog.ClearLogText()
tasklog.AppendLogText("任务开始... \r\n")
//运行
multitask.Run()
//回调链式执行
videosrt.SetFailHandler(func(video string) {
//运行下一任务
multitask.RunOver()
//任务完成
if ok := multitask.FinishTask(); ok && finish == false {
//延迟结束
go func() {
time.Sleep(time.Second)
finish = true
startBtn.SetEnabled(true)
startBtn.SetText("生成文件")
logText.AppendText("\r\n\r\n任务完成!")
//清空临时目录
videosrt.ClearTempDir()
}()
}
})
videosrt.SetSuccessHandler(func(video string) {
//运行下一任务
multitask.RunOver()
//任务完成
if ok := multitask.FinishTask(); ok && finish == false {
//延迟结束
go func() {
time.Sleep(time.Second)
finish = true
startBtn.SetEnabled(true)
startBtn.SetText("生成文件")
logText.AppendText("\r\n\r\n任务完成!")
//清空临时目录
videosrt.ClearTempDir()
}()
}
})
//日志输出
go func() {
for finish == false {
logText.SetText("")
logText.AppendText(tasklog.GetString())
time.Sleep(time.Millisecond * 150)
}
}()
},
},
},
},
},
OnDropFiles: func(files []string) {
//检测文件列表
result , err := VaildateHandleFiles(files)
if err != nil {
mw.NewErrormationTips("错误" , err.Error())
return
}
taskFiles.Files = result
dropFilesEdit.SetText(strings.Join(result, "\r\n"))
},
}.Create()); err != nil {
log.Fatal(err)
time.Sleep(1 * time.Second)
}
//校验依赖库
if e := ffmpeg.VailFfmpegLibrary(); e != nil {
mw.NewErrormationTips("错误" , "请先下载并安装 ffmpeg 软件,才可以正常使用软件哦")
tool.OpenUrl("https://gitee.com/641453620/video-srt-windows")
return
}
//尝试校验新版本
if appSetings.CloseNewVersionMessage == false {
go func() {
appV := new(AppVersion)
if vtag, e := appV.GetVersion(); e == nil {
if vtag != "" && tool.CompareVersion(vtag , APP_VERSION) == 1 {
_ = appV.ShowVersionNotifyInfo(vtag , mw)
}
}
}()
}
mw.Run()
}