REVO8100 4 sub-to-srt P local frate local psrt,astop,astart,atext local frate1,frate2,oldsrt on opencard --set things up set the menuHistory of btn omfrate1 to 3 set the menuHistory of btn omfrate2 to 4 put line (the menuHistory of btn "omfrate1") of btn "omfrate1" into frate1 put line (the menuHistory of btn "omfrate2") of btn "omfrate1" into frate2 put "Input file" into fld "infile" put empty into fld "fsub" put empty into fld "fsrt" put empty into fld "ffile" put empty into fld "ftc" put empty into fld "fsec" put empty into fld "stc1" put empty into fld "stc2" put empty into fld "etc1" put empty into fld "etc2" disconvert disable btn "btosrt" disable widget "left" disable btn "bopen3" disable btn "bopen4" disable btn "bopen2" disable btn "bstretch" disable btn "bopen6" end opencard on setttips --set the tooltips set the toolTip of btn "bindex" to "If you have removed or added subtitle entries you" & return & "will need to reindex the SRT file." set the toolTip of fld "stc1" to "The START timecode of the SRT file." set the toolTip of fld "stc2" to "The END timecode of the SRT file." set the toolTip of fld "etc1" to "Desired START timecode of SRT file." set the toolTip of fld "etc2" to "Desired END timecode of SRT file" set the toolTip of btn "bshift" to "Shifts all timecodes in SRT file according to "& return & "difference between original and desired Starting TC" set the toolTip of btn "Bstretch" to "Stretches or compresses all timecodes in SRT file to "& return & "match the desired values." set the toolTip of btn "omfrate1" to "Select the original SRT framerate" set the toolTip of btn "omfrate2" to "Select the desired SRT framerate" set the toolTip of btn "btest" to "Convert framerate and put result in RESULT field" set the toolTip of btn "bopen3" to "Convert SUB file to SRT and place in RESULT field" set the toolTip of btn "bopen2" to "Convert SSA file to SRT and place in RESULT field" set the toolTip of btn "Btosrt" to "Move text from Result field to Input/Edit field." set the toolTip of btn "bsrt" to "Save the SRT shown Result field." set the toolTip of btn "Bclear" to "Clear all fields and reset app." set the toolTip of btn "btest" to "Convert framerate and put result in Result field" set the toolTip of btn "blocksrt" to "Lock/Unlock the text of both fields." set the toolTip of btn "bopen1" to "Open a file (srt, sub, ssa) to work on." set the toolTip of fld "fsub" to "Drag a file here to work on." set the toolTip of btn "Bup" to "Update/reloads the [Shift-Stretch-Compress] values." set the toolTip of btn "Btosec" to "Convert the timecode to seconds" set the toolTip of btn "Btotc" to "Convert the time in seconds to a timecode." set the toolTip of fld "ftc" to "Enter a timecode 00:00:00,000" set the toolTip of fld "fsec" to "Enter a number of seconds 00.000" end setttips on menuPick pChosenItem -- in a pulldown menu --set conversion framerates put the target into temp if word 2 of temp is quote&"omfrate1""e then put pChosenItem into frate1 if word 2 of temp is quote&"omfrate2""e then put pChosenItem into frate2 end menuPick on opensubfile --request subtitle file and depending on file's extension, set up interface. answer file "Please locate the subtitle file" if the result is not "Cancel" then put it into tChosenFile put tChosenFile into fld "ffile" put "file:"&tChosenFile into thefile put url thefile into fld "fsub" put empty into fld "fsrt" --enable/disable options based on file extension put char -3 to -1 tChosenFile into theext switch theext case "sbv" put "Input"&& quote& "sub" & quote &&"file" into fld "infile" enable btn "bopen5" disable btn "bopen4" disable btn "bopen3" disable btn "bopen2" disconvert break case "sub" put "Input"&& quote& "sub" & quote &&"file" into fld "infile" enable btn "bopen3" disable btn "bopen2" disconvert break case "ssa" put "Input"&& quote& "ssa" & quote &&"file" into fld "infile" disable btn "bopen3" enable btn "bopen2" disconvert break case "ass" put "Input"&& quote& "ass" & quote &&"file" into fld "infile" disable btn "bopen3" enable btn "bopen2" disconvert break case "srt" put "Input"&& quote& "srt" & quote &&"file" into fld "infile" disable btn "bopen3" disable btn "bopen2" gettc enconvert break default -- default code end switch end if end opensubfile on reindex makearray --we now have a set of arrays indexed on the subtitle index (i.e. starts at 1) --as there may be empty lines and the times made be mixed (when 32 sub files are combined) --make new array keyed on start time with stop time and text as elements put empty into tcomb repeat for each key tKey in astart if atext[tkey]="" then next repeat replace return with "***" in atext[tkey] put astart[tkey] &"|"& astop [tkey] &"|"& atext[tkey] & return after tcomb end repeat --tcomb is has each line being a combination of each srt entrty, now sort it set the itemDelimiter to "|" sort lines of tcomb ascending numeric by item 1 of each put 0 into tIndex repeat for each line tLine in tcomb add 1 to tIndex put line tindex of tcomb into acomb[tindex] end repeat put 0 into tIndex repeat for each key tKey in acomb set the itemDelimiter to "|" put item 1 of acomb[tkey] into astart[tkey] put item 2 of acomb[tkey] into astop[tkey] put item 3 of acomb[tkey] into atext[tkey] replace "***" with return in atext[tkey] end repeat --reconvert arrays back to srt format. put empty into thesrt put the keys of astart into thekeys sort lines of thekeys ascending numeric put the number of lines of thekeys into thecount repeat with x = 1 to thecount put line x of thekeys into tnindex put x & return after thesrt put formattime(astart[tnindex]) & " --> "& formattime(astop[tnindex]) & return after thesrt put atext[tnindex] & return & return after thesrt end repeat put thesrt into fld "fsrt" enable btn "btosrt" enable widget "left" end reindex on clearout put empty into fld "fsrt" end clearout on disconvert --disable conversion controls disable grp "framerate conversion" disable grp "TCExpand" clearout end disconvert on enconvert --enable conversion controls enable grp "framerate conversion" enable grp "TCExpand" disable btn "btosrt" disable widget "left" clearout end enconvert on gettc --grabs first and last timecodes and places them in stc1 and etc1 put fld "fsub" into temp set the itemDelimiter to return&return --get first tc put line 2 of (item 1 of temp) into stc1 put line 2 of (item -1 of temp) into etc1 set the itemDelimiter to " " put item 1 of stc1 into fld "stc1" put item 1 of etc1 into fld "etc1" --repeat into target timecodes providing starting point. put item 1 of stc1 into fld "stc2" put item 1 of etc1 into fld "etc2" enable btn "bstretch" end gettc function subconvert psub --psub contains the sub file text --convert a sub file to an srt file --first line should be framerate but may contain other material or not the frame rate! put line 1 of psub into frate --does it have a frame rate? put empty into t1 get MatchText(frate,"(?i)(\d\d\.\d\d)",t1) if t1 <>"" then put t1 into frate else ask question "The .sub file does not contain a frame rate."&cr&"Please enter a frame rate in the form xx.xx" with "23.97" if the result = "Cancel" then return "" exit to top else put it into frate end if end if delete line 1 of psub --reformat the text replace "{" with "" in psub replace "}" with tab in psub --go through line by line and construct srt file put "" into thesrt put the number of lines of psub into tlines set the itemDelimiter to tab repeat with aline = 1 to tlines put "" into temp put line aline of psub into tsrtline put aline & return after temp put item 1 of tsrtline into f1 put item 2 of tsrtline into f2 put frameTotime(f1) into t1 put frameTotime(f2) into t2 put t1 & " --> " & t2 & return after temp put item 3 of tsrtline & return & return after temp put temp after thesrt end repeat replace "|" with return in thesrt enable btn "btosrt" enable widget "left" return thesrt end subconvert function subconvertsbv psub --psub contains the sbv file text --convert a sbv file to an srt file --the times codes for the text start are M:SS and will extend to h:mm:ss --these are followed by the text all on one line /* This makes 3 arrays indexed on subtitle index: astart - start timecodes astop - end timecodes atext - text psub is a local variable containing the text of the sbv file format is: - timecode start - text */ -- put empty into astart put empty into astop put empty into atext delete line -4 to -1 of psub put line 1 of psub into tcode --does it have a timecode? put empty into t1 get MatchText(tcode,"(?i)(\d:\d\d)",t1) if t1 <>"" then put t1 into time1 else answer question "The .sbv file does not begin with a time code."&cr&"Please edit file to start with time code" if it = "OK" then exit to top end if end if --go through line by line and construct srt file --begin by building array put the number of lines of psub into tlines put psub into psubtemp put 0 into tindex repeat forever add 1 to tindex if psubtemp is empty then exit repeat put line 1 of psubtemp into astart[tindex] put line 2 of psubtemp into atext[tindex] delete line 1 to 2 of psubtemp end repeat --convert all times to seconds repeat for each key tindex in astart put tindex into ttemp set the itemDelimiter to ":" put the number of items of astart[tindex] into itemcount switch itemcount case 2 --only mins and secs put 60*(item 1 of astart[tindex])+item 2 of astart[tindex] into astart[tindex] break case 3 --includes hour put (3600*(item 1 of astart[tindex]))+(60 *(item 2 of astart[tindex])) + item 3 of astart[tindex] into astart[tindex] break end switch end repeat repeat for each key tindex in astart put astart[tindex+1] into astop[tindex] end repeat --go through array to format times put the number of elements of astart into tcount repeat with tindex = 1 to tcount --get hour, mins and secs put astart[tindex] div 3600 into thrs if thrs <10 then put "0"& thrs into thrs put astart[tindex] mod 3600 into tminsecs put tminsecs div 60 into tmins put tminsecs mod 60 into tsecs if tmins <10 then put "0"& tmins into tmins if tsecs <10 then put "0"& tsecs into tsecs put thrs & ":"& tmins &":"& tsecs &","& "000" into astart[tindex] --now end times put astop[tindex] div 3600 into thrs if thrs <10 then put "0"& thrs into thrs put astop[tindex] mod 3600 into tminsecs put tminsecs div 60 into tmins if tmins <10 then put "0"& tmins into tmins if tsecs <10 then put "0"& tsecs into tsecs put tminsecs mod 60 into tsecs subtract 1 from tsecs put thrs & ":"& tmins &":"& tsecs &","& "900" into astop[tindex] -- code end repeat --construct srt from arrays -- index & cr & sstart --> send & cr text put empty into thesrt repeat with tindex = 1 to tcount put tindex & cr into temp put astart[tindex] & " --> " & astop[tindex] & cr after temp if the number of words in atext[tindex] > 14 then put word 1 to 14 of atext[tindex] & cr & word 15 to -1 of atext[tindex] into atext[tindex] end if put atext[tindex] & cr &cr after temp put temp after thesrt end repeat enable btn "btosrt" enable widget "left" return thesrt end subconvertsbv function subconvertssa psub --conver ssa to srt --an SSA file is basically an srt file with a lot of extra junk and laid out in a different way --grab only the dialogue entries put wordOffset("Dialogue",psub ) into tword delete word 1 to tword - 1 of psub --now we need to grab the data --items are comma delimted except for text at end which may contain commas! --Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text --we want items 2,3,10 to -1 put empty into thesrt repeat with x = 1 to the number of lines of psub put x & return after thesrt put line x of psub into tline put item 2 of tline into t1 put item 3 of tline into t2 replace "." with "," in t1 replace "." with "," in t2 put t1 & " --> "& t2 & return after thesrt put item 10 to -1 of tline & return & return after thesrt end repeat --end if --psub is now in srt format but has formats embedded. replace "\N" with return in thesrt replace "{\i1}" with "" in thesrt replace "{\i0}" with "" in thesrt replace "{\b1}" with "" in thesrt replace "{\b0}" with "" in thesrt put "\{[b]\d+\}" into regtext put replaceText(thesrt,regtext,"") enable btn "btosrt" enable widget "left" return thesrt end subconvertssa function subconvertttml psub local tlcount, ttemp --conver ttml to srt --a TTML file is a XML file with potentially extra junk --remove header stuff put wordOffset("
" into regexrep replace regexrep with "|" in psub --remove end p's replace "
" with "" in psub --items are "|" delimted --Format: num|t1|t2|text put empty into thesrt set the itemDelimiter to "|" repeat with x = 1 to tlcount put x & return after thesrt put line x of psub into tline put item 2 of tline into t1 put item 3 of tline into t2 replace "." with "," in t1 replace "." with "," in t2 put t1 & "0" into t1 put t2 & "0" into t2 put t1 & " --> "& t2 & return after thesrt put item 4 of tline & return & return after thesrt end repeat --end if --psub is now in srt format but may have formats embedded. replace "