gui, font, bold gui, add, text,, MicroDVD <-|-> SubRip converter gui, font gui, add, text,, Input subtitle file`n(SubRip *.srt or MicroDVD *.sub) gui, add, edit, w200 ReadOnly vInputEdit, gui, add, button, xp+200 vInput gBrowse, B&rowse gui, add, text,xm, Subtitle FPS gui, add, combobox, vFPS, 12.000|15.000|20.000|23.976|23.978|23.990|24.000|25.000||29.970|30.000 gui, add, text, xm, Output subtitle file gui, add, edit, w200 ReadOnly vOutputEdit, gui, add, button, xp+200 vOutput gBrowse, Br&owse gui, add, text,, gui, add, button,xm gConvert w70, &Convert it! gui, add, button, xp+80 gExit w70, E&xit gui, add, button, xp+100 gAbout w70, A&bout gui, show,, MicroDVD <> SubRip converter return Browse: Gui, +owndialogs if (A_GuiControl = "Input") { FileSelectFile, s_path,1,, Select a subtitle file to convert (MicroDVD *.sub or SubRip *.srt), MicroDVD or SubRip (*.sub; *.srt) if ErrorLevel return SplitPath, s_path,, i_dir,i_ext,i_file if i_ext not in sub,srt { MsgBox, 64, Error!, You must select either a MicroDVD (.sub) or a SubRip (.srt) file! return } GuiControl,, InputEdit, %s_path% GuiControl,, OutputEdit, % i_dir "\" i_file "." (i_ext="srt" ? "sub" : "srt") } else { if i_file && i_ext s_cfile := i_file "." (i_ext="sub" ? "srt" : "sub") else s_cfile :="" FileSelectFile, s_path,S,%s_cfile%, Save it!, MicroDVD or SubRip (*.sub; *.srt) if ErrorLevel return GuiControl,, OutputEdit, %s_path% } return Convert: Gui, +owndialogs gui, submit, nohide SplitPath, OutputEdit,,c_dir,c_ext,c_file if FileExist(OutputEdit) Loop if FileExist(c_dir "\" c_file "(" a_index ")." c_ext) Continue else { OutputEdit := c_dir "\" c_file "(" a_index ")." c_ext break } FileRead, s_temp, %InputEdit% FileDelete, %outputedit% if (i_ext="sub") FileAppend, % Sub2Srt(s_temp,FPS), %OutputEdit% else if (i_ext="srt") FileAppend, % Srt2Sub(s_temp,FPS), %OutputEdit% else return if !ErrorLevel msgbox, 64, Successful!, Conversion successful:`n%OutputEdit% else msgbox, 64, Error!, Conversion not successful.`nPlease try again! return About: Gui, +owndialogs msgbox, 64, About MicroDVD (.sub) <> SubRip (.srt) converter,MicroDVD (.sub) <> SubRip (.srt) converter`nv1.0`n`nYear: 2010`nAuthor: gahks`nWebsite: http://autohotkey.net/~gahks`n`nLicense: GPL v3`nFree, open source application.`n`nWritten in AutoHotkey`nhttp://autohotkey.com/ return Exit: GuiClose: ExitApp Srt2Sub(InputSubtitles,FPS){ if (!InputSubtitles) || (!FPS) return false Loop, Parse, InputSubtitles, `r`n { if a_loopfield is digit Continue ;line numbers discarded if RegexMatch(a_loopfield,"(\d+):(\d\d):(\d\d),(\d\d\d)\s-->\s(\d+):(\d\d):(\d\d),(\d\d\d)",match) { o_frame_start := (match1*3600)+(match2*60)+match3 "." match4 o_frame_start *= FPS, o_frame_start := Round(o_frame_start) o_frame_end := (match5*3600)+(match6*60)+match7 "." match8 o_frame_end *= FPS, o_frame_end := Round(o_frame_end) o_temp .= "`r`n" "{" o_frame_start "}{" o_frame_end "}" } else o_temp .= RegExReplace(a_loopfield, "<([a-zA-Z0-9\\]+)>\s?", "") "|" ;removing tags --> currently doesn't support converting tags } o_temp .= "`r`n" ;an ugly tweak ;Taking care of the extra "|"-s and line breaks Loop, Parse, o_temp, `n { if a_index=1 continue ;first line is a line break o_temp := "" if (SubStr(a_loopfield,-1,1) = "|") StringTrimRight, o_temp, a_loopfield, 2 ;extra pipes at the ends of lines OutputSubtitles .= (o_temp ? o_temp : a_loopfield) "`r`n" } return OutputSubtitles } Sub2Srt(InputSubtitles,FPS){ if (!InputSubtitles) return false if (!FPS) { if (!RegExMatch(SubStr(InputSubtitles,1,InStr(InputSubtitles,"`n")-1), "\Q{1}{1}\E([\d]+[.][\d]+)", match)) return false else FPS := match1, o_temp := true } formatfloat := a_formatfloat SetFormat, float, 0.3 Loop, Parse, InputSubtitles, `r`n { if (a_index = 1 && o_temp) || (!RegexMatch(a_loopfield, "{(\d+)}{(\d+)}(.*)", match)) continue o_line++ ;line number timer_start := match1/FPS ;eg. 3712.123 s timer_end := match2/FPS StringReplace, o_text, match3, |, `r`n ;line breaks RegExReplace(o_text, "{([a-zA-Z0-9:\$]+)}\s?", "") ;removing tags --> currently doesn't support converting tags Loop, 2 { c_timer := a_index=1 ? "start" : "end" ;timer consists of two parts StringSplit, temp, timer_%c_timer%, . ;splitting by the decimal dot o_ms_%c_timer% := temp2 ;eg. 123 ms o_temp := temp1 ;eg. 3712 s ;eg. o_temp/3600 = 1.031 o_hh_%c_timer% := SubStr(o_temp/3600,1,InStr(o_temp/3600,".")-1) ;eg. 1 h o_temp := Mod(o_temp,3600) ;eg. 112 (s) ;eg. o_temp/60 = 1.866 o_mm_%c_timer% := SubStr(o_temp/60,1,InStr(o_temp/60,".")-1) ;eg. 1 m o_ss_%c_timer% := Mod(o_temp,60) ;eg. 52 s ;taking care of single-digit timer parts, applying padding with zeros ;eg. 1 h 1 m 52 s -> 01 h 01 m 52 s o_temp = hh|mm|ss StringSplit, o_temp, o_temp, | Loop, 3 { o_temp := o_temp%a_index% o_%o_temp%_%c_timer% := (StrLen(o_%o_temp%_%c_timer%)=1 ? "0" : "") o_%o_temp%_%c_timer% } } OutputSubtitles .= o_line "`r`n" o_hh_start ":" o_mm_start ":" o_ss_start "," o_ms_start . " --> " o_hh_end ":" o_mm_end ":" o_ss_end "," o_ms_end "`r`n" o_text "`r`n`r`n" } SetFormat, float, %formatfloat% return OutputSubtitles }