-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jerry
committed
Sep 2, 2020
1 parent
2f2aad8
commit c9f1c5f
Showing
2 changed files
with
266 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,266 @@ | ||
../autogui/autosub-ahk.ahk | ||
; Generated by AutoGUI 2.6.2 | ||
; =========================== | ||
; Author: Jerry Jian | ||
; YouTube: https://www.youtube.com/channel/UC2xBvmv-lhsY4suxv46lplg?view_as=subscriber | ||
; Blog: http://jdev.tw/blog | ||
; v1.0 2020/05/13 | ||
; Call gen.bat to generate subtitle. You can change the autosub parameters in gen.bat. | ||
; v1.0.1 2020/05/14 minor changes | ||
; v1.0.2 2020/05/16 Add .wav to allowed video format | ||
; v1.0.3 2020/05/18 Add .mp3 to allowed video format | ||
; v1.0.4 2020/05/23 Add test.bat | ||
; v1.0.5 2020/09/02 Add French language | ||
; =========================== | ||
#SingleInstance Force | ||
#NoEnv | ||
SetWorkingDir %A_ScriptDir% | ||
SetBatchLines -1 | ||
|
||
#Include %A_ScriptDir%\ControlColor.ahk | ||
|
||
I_ICON := A_ScriptDir . "\cc.ico" | ||
global videoFiles | ||
global VIDEO_FORMAT_FAILED | ||
videoFiles := [] | ||
VALID_VIDEO_FORMAT := "*.mp4;*.mp3;*.wav" | ||
|
||
version := "v1.0.5" | ||
; 多語系設定 | ||
if (A_Language in 0404, 0c04, 1404) { ; Chinese_Taiwan, Hong Kong, Macau | ||
TITLE := "AutoSub-AHK 字幕產生器" | ||
LANGUAGES := "zh-TW 中文(繁體)||zh-CN 中文(簡體)|en-US English|ja-JP 日本語|ko-KR 한국어|yue-hant-hk 粵語|fr-fr French(France)" | ||
VIDEO_LANGUAGE := "影片語言(&L)" | ||
VIDEO_FILES := "選擇影片檔案(&S)" | ||
OUTPUT_FILENAME := "輸出檔名(&O)" | ||
OUTPUT_MSG := "(副檔名必須為.txt或.srt)" | ||
DRAG_MSG := "(" . VALID_VIDEO_FORMAT . ") 拖曳功能已啟用" | ||
BTN_OK := "確定執行(&E)" | ||
BTN_CLOSE := "關閉(&C)" | ||
VIDEO_SELECT_TITLE := "選擇影片檔案(可複選)" | ||
VIDEO_FORMAT_FAILED := "影片副檔名必須是 " . VALID_VIDEO_FORMAT | ||
} else if (A_Language in 0804,1004) { ; Chinese_PRC, singapore | ||
TITLE := "AutoSub-AHK 字幕产生器" | ||
LANGUAGES := "zh-TW 中文(繁体)|zh-CN 中文(简体)||en-US English|ja-JP 日本语|ko-KR 한국어|yue-hant-hk 粤语|fr-fr French(France)" | ||
VIDEO_LANGUAGE := "视频语言(&L)" | ||
VIDEO_FILES := "选择视频文件(&S)" | ||
OUTPUT_FILENAME := "输出档名(&O)" | ||
OUTPUT_MSG := "(副档名必须为.txt或.srt)" | ||
DRAG_MSG := "(" . VALID_VIDEO_FORMAT . ") 拖拽功能已启用" | ||
BTN_OK := "确定执行(&E)" | ||
BTN_CLOSE := "关闭(&C)" | ||
VIDEO_SELECT_TITLE := "选择影片文件(可复选)" | ||
VIDEO_FORMAT_FAILED := "影片副档名必须为 " . VALID_VIDEO_FORMAT | ||
} else { | ||
TITLE := "AutoSub-AHK SubTITLEs Generator" | ||
LANGUAGES := "zh-TW Chinese(Traditional)|zh-CN Chinese(Simplified)|en-US English||ja-JP Japanese|ko-KR Korean|yue-hant-hk Hong Kong|fr-fr French(France)" | ||
VIDEO_LANGUAGE := "Video &Language" | ||
VIDEO_FILES := "&Select Video File(s)" | ||
OUTPUT_FILENAME := "&Output file name" | ||
OUTPUT_MSG := "(File extension must ends with .txt or .srt)" | ||
DRAG_MSG := "(" . VALID_VIDEO_FORMAT . ") Drag and Drop Enabled" | ||
BTN_OK := "&Execute" | ||
BTN_CLOSE := "&Close" | ||
VIDEO_SELECT_TITLE := "Select video file(s)" | ||
VIDEO_FORMAT_FAILED := "Video's extension must be " . VALID_VIDEO_FORMAT | ||
} | ||
|
||
Menu Tray, Icon, %I_ICON% | ||
|
||
Gui +hWndhMainWnd +Resize -MaximizeBox | ||
Gui Font, s12 | ||
Gui Add, ComboBox, vCmbLanguage x12 y56 w281, %LANGUAGES% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Text, x-152 y0 w120 h24 +0x200, %VIDEO_LANGUAGE% | ||
Gui Add, Text, x200 y110 w250 h24 +0x200, %DRAG_MSG% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Button, gbtnSelectFiles x12 y104 w180 h35, %VIDEO_FILES% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, ListBox, vListBox1 x8 y144 w496 h144 +0x1201 | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Text, x12 y304 w233 h24, %OUTPUT_FILENAME% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Edit, vedtOutputFilename x8 y336 w496 h27 | ||
Gui Font | ||
Gui Font, s16 cGreen | ||
Gui Add, Button, hWndhBtne2 gbtnOK x48 y392 w180 h61 +Default, %BTN_OK% | ||
Gui Font | ||
ControlColor(hBtne2, hMainWnd, 0x008000) | ||
Gui Font, s16 | ||
Gui Add, Button, gbtnClose x280 y392 w180 h61, %BTN_CLOSE% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Text, x12 y24 w120 h24 +0x200, %VIDEO_LANGUAGE% | ||
Gui Font | ||
Gui Font, s12 | ||
Gui Add, Text, x150 y304 w300 h24 +0x200, %OUTPUT_MSG% | ||
Gui Font | ||
Gui Add, Text, x6 y380 w507 h2 +0x10 | ||
|
||
Gui Show, w518 h469, %TITLE% %version% | ||
Return | ||
|
||
/* | ||
CmbLanguageChange: | ||
GuiControlGet, CmbLanguage,, | ||
msgbox lang=%CmbLanguage% | ||
Return | ||
*/ | ||
|
||
btnSelectFiles: | ||
;FileSelectFile, OutputVar , Options, RootDir\Filename, Title, Filter | ||
FileSelectFile, files, M3, , %VIDEO_SELECT_TITLE%, %VALID_VIDEO_FORMAT% ; M3 = Multiselect existing files. | ||
if (files = "") { | ||
return | ||
} | ||
;msgbox files=%files% | ||
folder := "" | ||
Loop, parse, files, `n | ||
{ | ||
if (A_Index = 1) { | ||
folder = %A_LoopField% | ||
} else { | ||
isMP4 := chkVideoFile(A_LoopField) | ||
if (isMP4 = 1) { | ||
videoFiles.push(folder . "\" . A_LoopField) | ||
} | ||
} | ||
} | ||
files := "" | ||
for index, element in videoFiles ; Enumeration is the recommended approach in most cases. | ||
{ | ||
;MsgBox % "Element number " . index . " is " . element | ||
if (index = 1) { | ||
name := element | ||
StringReplace name, name, .mp4, .srt | ||
StringReplace name, name, .wav, .srt | ||
StringReplace name, name, .mp3, .srt | ||
GuiControl, , edtOutputFilename, %name% | ||
} | ||
files := files . element . "|" | ||
} | ||
GuiControl, , ListBox1, %files% | ||
Return | ||
|
||
btnOK(CtrlHwnd, GuiEvent, EventInfo, ErrLevel := "") { | ||
Gui, Submit | ||
GuiControlGet, CmbLanguage,, | ||
iPos := InStr(CmbLanguage, " ") | ||
Language := Substr(CmbLanguage, 1, iPos-1) | ||
if (Language = "zh-TW") { | ||
Language := "cmn-hant-tw" | ||
} else if (Language = "zh-CN") { | ||
Language := "cmn-hans-cn" | ||
} | ||
|
||
;MsgBox lang=%Language%$ | ||
|
||
GuiControlGet, edtOutputFilename,, | ||
; edtOutputFilename | ||
|
||
for index, element in videoFiles | ||
{ | ||
videoFilename := element | ||
if (index = 1) { | ||
newFilename := deleteOldFile(edtOutputFilename, Language) | ||
if (InStr(edtOutputFilename, ".txt") > 0) { | ||
batFilename := "gen-txt.bat" | ||
} else { | ||
batFilename := "gen.bat" | ||
} | ||
;;MsgBox %A_ScriptDir%\%batFilename% %Language% "%videoFilename%" "%edtOutputFilename%" "%newFilename%" | ||
Run %A_ScriptDir%\%batFilename% %Language% "%videoFilename%" "%edtOutputFilename%" "%newFilename%" | ||
} else { | ||
edtOutputFilename := videoFilename | ||
StringReplace edtOutputFilename, edtOutputFilename, .mp4, .srt | ||
StringReplace edtOutputFilename, edtOutputFilename, .wav, .srt | ||
StringReplace edtOutputFilename, edtOutputFilename, .mp3, .srt | ||
newFilename := deleteOldFile(edtOutputFilename, Language) | ||
if (InStr(edtOutputFilename, ".txt") > 0) { | ||
batFilename := "gen-txt.bat" | ||
} else { | ||
batFilename := "gen.bat" | ||
} | ||
Run %A_ScriptDir%\%batFilename% %Language% "%videoFilename%" "%edtOutputFilename%" "%newFilename%" | ||
} | ||
} | ||
ExitApp | ||
} | ||
|
||
btnClose: | ||
WinClose | ||
Return | ||
|
||
GuiSize: | ||
If (A_EventInfo == 1) { | ||
Return | ||
} | ||
|
||
Return | ||
|
||
GuiContextMenu: | ||
Return | ||
|
||
GuiDropFiles(GuiHwnd, FileArray, CtrlHwnd, X, Y) { | ||
videoFiles := [] | ||
for i, file in FileArray | ||
{ | ||
;MsgBox File %i% is:`n%file% | ||
if (chkVideoFile(file)) { | ||
videoFiles.push(file) | ||
} | ||
} | ||
for index, element in videoFiles ; Enumeration is the recommended approach in most cases. | ||
{ | ||
if (index = 1) { | ||
name := element | ||
StringReplace name, name, .mp4, .srt | ||
StringReplace name, name, .mp3, .srt | ||
StringReplace name, name, .wav, .srt | ||
GuiControl, , edtOutputFilename, %name% | ||
} | ||
files := files . element . "|" | ||
} | ||
GuiControl, , ListBox1, %files% | ||
} | ||
|
||
OnClipboardChange: | ||
Return | ||
|
||
GuiClose: | ||
ExitApp | ||
|
||
ListBox1: | ||
Return | ||
|
||
/* | ||
* 檢查輸入的影片副檔名是否為.mp4、mp3或.wav | ||
*/ | ||
chkVideoFile(file) { | ||
;MsgBox file=%file% | ||
StringUpper, file, file | ||
iPos1 := InStr(file, ".MP4") | ||
iPos2 := InStr(file, ".WAV") | ||
iPos3 := InStr(file, ".MP3") | ||
if (iPos1 <= 0 && iPos2 <= 0 && iPos3 <= 0) { | ||
MsgBox %VIDEO_FORMAT_FAILED% (%file%) | ||
Return false | ||
} | ||
Return True | ||
} | ||
|
||
/* | ||
* 刪除已存在的 xxx.cmn-hant-tw.srt | ||
*/ | ||
deleteOldFile(file, language) { | ||
iPos := InStr(file, ".") | ||
newFilename := Substr(file, 1, iPos) . language . Substr(file, iPos, 10) | ||
if FileExist(newFilename) { | ||
FileDelete, %newFilename% | ||
} | ||
return newFilename | ||
} |
Binary file not shown.