Что-то не получается мне мой скрипт туда засунуть.
Пишет про какие-то ошибки непонятные.
#Persistent
; переменная watcher должна содержать текст нужного скрипта перед выполнением строки DynaRun(watcher)
watcher =
(
Text = C:\1.txt ; заменить на файл с субтитрами
watchfolder = C:\222 ; заменить на истинный путь к папке с файлами титров
prtlPath = C:\111 ; заменить на истинный путь к исходным файлам (шаблону), для одной строки должно быть название "1.ptrl" , для двух "2.ptrl" и т.д.
SetBatchLines, -1
FileEncoding, UTF-16
FileRemoveDir, %watchfolder%, 1
FileCreateDir, %watchfolder%
FileRead, str, %Text%
string := RegExReplace(Trim(str,"`r`n"), "\R[\R\s]+", "`n`n")
SubStrList := RegExSplit(string, "S)\n\n")
for index, substring in SubStrList
string%A_Index% := substring, Lines%A_Index% := SymbCount(substring, "`n")+1
n := SubStrList.MaxIndex()
Loop % n
{
String := string%A_Index%
k := Lines%A_Index% - 1
FileRead, prtl, %prtlPath%\%k%.prtl
XPos := 0
Loop, parse, String, `n, `r
{
if (A_Index = 1)
{
Timecode .= A_LoopField "`n"
Continue
}
if (A_LoopField = "")
Continue
StrLength := StrLen(A_LoopField ) + 1
XPos := RegExMatch(prtl, "<XPos>", "", XPos + 1)
prtl := RegExReplace(prtl, "<CharacterAttributes RunCount="".*?"""
, "<CharacterAttributes RunCount=""" StrLength """"
, "", 1, XPos - 1)
StringReplace, LoopField, A_LoopField, &, &, 1
if (k > 1)
{
k:=k-1
prtl := RegExReplace(prtl, "<TRString TXMarker=""Booyah"">.*?</TRString>"
, "<TRString TXMarker=""Booyah"">" LoopField "</TRString>"
, "", 1, XPos - 1)
}
Else
prtl := RegExReplace(prtl, "<TRString>.*?</TRString>"
, "<TRString>" LoopField "</TRString>")
}
FileName := "title" . SubStr("000", 1, -(StrLen(A_Index))) . A_Index . ".prtl"
FileAppend, % prtl, %watchfolder%\%FileName%
}
n:=1
TimecodesList := RegExReplace(Trim(Timecode,"`r`n"), " ", "")
Loop, parse, TimecodesList, `n, `r
{
Timecodes = %A_LoopField%
StringSplit, string, Timecodes, -
varTimecode1 = % string1
varTimecode2 = % string2
StringSplit, Timecode1Array, varTimecode1, :
StringSplit, Timecode2Array, varTimecode2, :
Digit4:
if (Timecode2Array4 < Timecode1Array4)
{
Timecode2Array4 += 25
Timecode2Array3 -= 1
DurationArray4 := Timecode2Array4 - Timecode1Array4
gosub, Digit3
}
if (Timecode2Array4 >= Timecode1Array4)
DurationArray4 := Timecode2Array4 - Timecode1Array4
Digit3:
if (Timecode2Array3 < Timecode1Array3)
{
Timecode2Array3 += 60
Timecode2Array2 -= 1
DurationArray3 := Timecode2Array3 - Timecode1Array3
gosub, Digit2
}
if (Timecode2Array3 >= Timecode1Array3)
DurationArray3 := Timecode2Array3 - Timecode1Array3
Digit2:
if (Timecode2Array2 < Timecode1Array2)
{
Timecode2Array2 += 24
Timecode2Array1 -= 1
DurationArray2 := Timecode2Array2 - Timecode1Array2
gosub, Digit1
}
if (Timecode2Array2 >= Timecode1Array2)
DurationArray2 := Timecode2Array2 - Timecode1Array2
Digit1:
if (Timecode2Array1 < Timecode1Array1)
{
msgbox, Timecode2Array1 %Timecode2Array1% < Timecode1Array1 %Timecode1Array1%
msgbox, The "Start" timecode cannot be less than the "End" timecode.
ExitApp
}
if (Timecode2Array1 >= Timecode1Array1)
{
DurationArray1 := Timecode2Array1 - Timecode1Array1
goto, EndProcess
}
EndProcess:
SetFormat, Float, 02.0
Loop, 4
DurationArray%A_Index% += 0.0
TitleDuration%n% = %DurationArray1%:%DurationArray2%:%DurationArray3%:%DurationArray4%
StartTimecode%n% = % string1
n++
}
WinActivate, Adobe Premiere Pro
WinWait, Adobe Premiere Pro
Send, +1^{vkBF}Subtitri^{vk49} ; create bin, ^i
WinWait, Import ahk_class #32770
Send, c:{enter}
Sleep 400
Send, %watchfolder%{enter}
Sleep 400
Send, +{TAB 2}
Sleep 400
Send, ^{vk41}
Sleep 400
Send,{enter}
WinWaitClose, Import ahk_class #32770
WinWait, Import Files ahk_class #32770, , 0.6
WinWaitClose, Import Files ahk_class #32770
Sleep, 300
i := n - 1
Send, {up %i%}
loop % n - 1
{
TitleDuration := TitleDuration%A_Index%
StartTimecode := StartTimecode%A_Index%
Send, {down}+4{TAB}%StartTimecode%{Enter}
Sleep, 200
Send, +1^{vk52} ; Ctrl+R
WinWait, Clip Speed / Duration
Send, {TAB}%TitleDuration%{Enter}
WinWaitClose, Clip Speed / Duration
Send, {vkBE} ; .
Sleep, 200
}
Msgbox, Done
Exit
SymbCount(ByRef string, symb) {
count := 0
loop, Parse, string
(A_LoopField == symb) && ++count
return count
}
RegExSplit(ByRef in, delim = "") {
pos := 0, start := 1, Obj := []
while, pos := RegExMatch(in, delim, match, start)
Obj.Insert(SubStr(in, start, pos - start)), start := pos + StrLen(match)
Obj.Insert(SubStr(in, start))
return Obj
}
)
( Ltrim
parentHwnd := %A_ScriptHWND%
parentPath := "%A_ScriptFullPath%"
SetTitleMatchMode, 2
DetectHiddenWindows, on
WinWaitActive, Save Project
PostMessage, 0x111, 65307,,, ahk_id `%parentHwnd`%
WinWaitNotActive, Save Project
Run, `%parentPath`%
)
DynaRun(watcher) ; код сохранённый в переменной watcher будет запущен в отдельном процессе ahk при выполнении данной строки
DynaRun(tempScript, pipeName = "")
{
static DefaultArgs := ["UInt", 2, "UInt", 0, "UInt", 255, "UInt", 0, "UInt", 0, "Ptr", 0, "Ptr", 0, "Ptr"]
static BOM := Chr(0xFEFF)
(pipeName = "" && pipeName := "AHK_" . A_TickCount)
pipeGA := DllCall("CreateNamedPipe", "Str", "\\.\pipe\" . pipeName, DefaultArgs*)
pipe := DllCall("CreateNamedPipe", "Str", "\\.\pipe\" . pipeName, DefaultArgs*)
if (pipe = -1 || pipeGA = -1)
Throw Exception("Failed to create pipe")
Run, % A_AhkPath . " ""\\.\pipe\" . pipeName . """",, UseErrorLevel HIDE, processID
if ErrorLevel
Throw Exception("Could not open file:`n ""\\.\pipe\" . pipeName . """")
DllCall("ConnectNamedPipe", "Ptr", pipeGA, "Ptr", 0), DllCall("CloseHandle", "Ptr", pipeGA)
DllCall("ConnectNamedPipe", "Ptr", pipe, "Ptr", 0)
, tempScript := BOM . tempScript
, tempScriptSize := 2 + StrLen(tempScript) * 2
, res := DllCall("WriteFile", "Ptr", pipe, "Str", tempScript, "UInt", tempScriptSize, "UInt*", 0, "Ptr", 0)
, DllCall("CloseHandle", "Ptr", pipe)
if !res
Throw Exception("Unable to write temporary file")
return processID
}