Code: Select all
FileVtt = %1%
if (FileVtt = "")
{ FileSelectFile, FileVtt, M3,, Select Sub('s), Sub's, (*.vtt; *.it.srt)
if (FileVtt = "")
ExitApp
} else { Path := SubStr(FileVtt, 1, InStr(FileVtt, "\" ,, 0, 1)-1) ; else convert FileVtt to Multi-select format
NameVtt := SubStr(FileVtt, InStr(FileVtt, "\" ,, 0, 1)+1, StrLen(FileVtt)), FileVtt := Path "`n" NameVtt
} Loop, parse, FileVtt, `n
{ if (A_index = 1)
Path := A_LoopField
else { SplashTextOn, 550, 50, % "Converting in: " Path, % "#" A_index-1 ": " A_LoopField
NameVtt := A_LoopField, name := SubStr(NameVtt, 1, StrLen(NameVtt)-3), srt := ""
FileRead, vtt, %Path%\%NameVtt%
if InStr(NameVtt, ".it.srt")
gosub ItSrt
vtt := RegExReplace(vtt, "`a)WEBVTT.*"), vtt := RegExReplace(vtt, "`amS)^\d+$"), partNum := 0
vtt := RegExReplace(vtt, "`aS)</.+>"), vtt := RegExReplace(vtt, "`aSU)<c\.(.*)>(.*)", "<font color=""$1"">$2")
loop, parse, vtt, `r, `n,
{ if RegExMatch(A_LoopField, "S)(\d{2}:\d{2}:\d{2})\.(\d{3}).*-->.*(\d{2}:\d{2}:\d{2})\.(\d{3}).*", vTime)
{ Start1 := vTime1 "," vTime2, End1 := vTime3 "," vTime4
(End = End1) ? End := Start1
(partNum >= 1) ? srt .= partNum "`r`n" Start " --> " End "`r`n" Txt "`r`n"
Start := Start1, End := End1, Txt := "", partNum++
} else (A_loopfield) ? Txt .= RegExReplace(A_LoopField, "vtt_") "`r`n"
} Filedelete, %path%\%name%srt
FileAppend, %srt%, %path%\%name%srt
continue
ItSrt:
FileMove, %path%\%name%srt, %path%\%name%bak
vtt := RegExReplace(vtt, "`aS)(\d{2}:\d{2}:\d{2})\s", "$1.000 ") , vtt := RegExReplace(vtt, "`aS)(\d{2}:\d{2}:\d{2})$", "$1.000")
vtt := RegExReplace(vtt, "`aS)(\d{2}:\d{2}:\d{2}),(\d{3})0{0,4}", "$1.$2"), vtt := RegExReplace(vtt, "`aS)�", "’"),
vtt := RegExReplace(vtt, "`aS)à", "à"), vtt := RegExReplace(vtt, "`aS)è", "è"), vtt := RegExReplace(vtt, "`aS)ì", "ì")
vtt := RegExReplace(vtt, "`aS)ò", "ò"), vtt := RegExReplace(vtt, "`aS)ù", "ù"), vtt := RegExReplace(vtt, "`aS)é", "é")
return
} } SplashTextOff
MsgBox,,, Conversion completed., 1
Adapted to convert formated Italian srt to "common" srt sub's.
Designed for MPC-HC. Adapted to VLC Player. (Note: to play Italian srt sub's with VLC Player you should convert mp4 video file first to flv, avi... or even to mp4 if your converter allows that. VLC seems to have problem digesting original mp4 with "common" srt!