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.3.5"
var AppRootDir string
var mw *MyMainWindow
var (
outputSrtChecked *walk.CheckBox
outputLrcChecked *walk.CheckBox
outputTxtChecked *walk.CheckBox
globalFilterChecked *walk.CheckBox
definedFilterChecked *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 operateFilter *walk.DataBinder
var operateFrom = new(OperateFrom)
var startBtn *walk.PushButton //生成字幕Btn
var startTranslateBtn *walk.PushButton //字幕翻译Btn
var engineOptionsBox *walk.ComboBox
var translateEngineOptionsBox *walk.ComboBox
var dropFilesEdit *walk.TextEdit
var appSetings = Setings.GetCacheAppSetingsData()
var appFilter = Filter.GetCacheAppFilterData()
//初始化展示配置
operateFrom.Init(appSetings)
//日志
var tasklog = NewTasklog(logText)
//字幕生成应用
var videosrt = NewApp(AppRootDir)
//注册日志事件
videosrt.SetLogHandler(func(s string, video string) {
baseName := tool.GetFileBaseName(video)
strs := strings.Join([]string{"【" , baseName , "】" , s} , "")
//追加日志
tasklog.AppendLogText(strs)
})
//字幕输出目录
videosrt.SetSrtDir(appSetings.SrtFileDir)
//注册[字幕生成]多任务
var multitask = NewVideoMultitask(appSetings.MaxConcurrency)
//字幕翻译应用
var srtTranslateApp = NewSrtTranslateApp(AppRootDir)
//注册日志回调事件
srtTranslateApp.SetLogHandler(func(s string, file string) {
baseName := tool.GetFileBaseName(file)
strs := strings.Join([]string{"【" , baseName , "】" , s} , "")
//追加日志
tasklog.AppendLogText(strs)
})
//文件输出目录
srtTranslateApp.SetSrtDir(appSetings.SrtFileDir)
//注册[字幕翻译]多任务
var srtTranslateMultitask = NewTranslateMultitask(appSetings.MaxConcurrency)
if err := (MainWindow{
AssignTo: &mw.MainWindow,
Icon:"./data/img/index.png",
Title: "VideoSrt - 一键字幕生成、字幕翻译小工具" + " - " + APP_VERSION,
Font:Font{Family: "微软雅黑", PointSize: 9},
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;*.m4a;*.srt)|*.mp4;*.mpeg;*.mkv;*.wmv;*.avi;*.m4v;*.mov;*.flv;*.rmvb;*.3gp;*.f4v;*.mp3;*.wav;*.aac;*.wma;*.flac;*.m4a;*.srt"
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 , true , true)
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()
//校验选择的翻译引擎是否存在
_ , ok := Engine.GetEngineById(appSetings.CurrentEngineId)
if appSetings.CurrentEngineId == 0 || !ok {
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()
//校验选择的翻译引擎是否存在
_ , ok := Engine.GetEngineById(appSetings.CurrentEngineId)
if appSetings.CurrentTranslateEngineId == 0 || !ok {
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.CloseNewVersionMessage = setings.CloseNewVersionMessage
appSetings.CloseAutoDeleteOssTempFile = setings.CloseAutoDeleteOssTempFile
appSetings.CloseIntelligentBlockSwitch = setings.CloseIntelligentBlockSwitch
multitask.SetMaxConcurrencyNumber( setings.MaxConcurren
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7524
最新资源
- finger-server-0.17-52.el7.x64-86.rpm.tar.gz
- fio-3.7-2.el7.x64-86.rpm.tar.gz
- 基于CAVLC 拖 尾 系数的H.264AVC 视 频 信息 隐 藏算法.pdf
- fipscheck-devel-1.4.1-6.el7.x64-86.rpm.tar.gz
- 超级好用的比较工具,版本2.16.8 64位
- fipscheck-lib-1.4.1-6.el7.x64-86.rpm.tar.gz
- firefox-115.12.0-1.el7.centos.x64-86.rpm.tar.gz
- firewall-applet-0.6.3-13.el7-9.x64-86.rpm.tar.gz
- firewall-config-0.6.3-13.el7-9.x64-86.rpm.tar.gz
- 第11讲:深入理解指针(1).pdf
- 第14讲:深入理解指针(4).pdf
- 第13讲:深入理解指针(3).pdf
- 第9讲:函数递归.pdf
- 第10讲:操作符详解.pdf
- 第15讲:深入理解指针(5).pdf
- 第3讲:分支和循环(上).pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈