Sync subtitles: Difference between revisions

Added FreeBASIC
(→‎{{header|Phix}}: Added Wren)
(Added FreeBASIC)
Line 158:
 
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Wren}}
<syntaxhighlight lang="vbnet">Function addSeconds(timeStr As String, secs As Integer) As String
Dim As Integer hh, mm, ss, ttt
hh = Val(Mid(timeStr, 1, 2))
mm = Val(Mid(timeStr, 4, 2))
ss = Val(Mid(timeStr, 7, 2)) + secs
ttt = Val(Mid(timeStr, 10, 3))
While ss < 0
ss += 60
mm -= 1
Wend
While mm < 0
mm += 60
hh -= 1
Wend
While hh < 0
hh += 24
Wend
mm += ss \ 60
hh += mm \ 60
ss Mod= 60
mm Mod= 60
hh Mod= 24
Return Right("0" & Str(hh), 2) & ":" & Right("0" & Str(mm), 2) & ":" & _
Right("0" & Str(ss), 2) & "," & Right("000" & Str(ttt), 3)
End Function
 
Sub syncSubtitles(fileIn As String, fileOut As String, secs As Integer)
Dim As String linea, pio, fin, nl, fmt
Dim As Ubyte f1, f2
fmt = "hh:MM:ss,ttt"
f1 = Freefile
Open fileOut For Output As #f1
f2 = Freefile
Open fileIn For Input As #f2
While Not Eof(f2)
Line Input #f2, linea
If Instr(linea, "-->") > 0 Then
pio = Mid(linea, 1, 12)
pio = addSeconds(pio, secs)
fin = Mid(linea, 18, 12)
fin = addSeconds(fin, secs)
Print #f1, pio; " --> "; fin
Else
Print #f1, linea
End If
Wend
Close #f2, #f1
End Sub
 
Dim As String linea
Dim As Ubyte f = Freefile
 
Print !"After fast-forwarding 9 seconds:\n"
syncSubtitles("movie.srt", "movie_corrected.srt", 9)
Open "movie_corrected.srt" For Input As #f
While Not Eof(f)
Line Input #f, linea
Print linea
Wend
Close #f
 
Print !"\n\nAfter rolling-back 9 seconds:\n"
syncSubtitles("movie.srt", "movie_corrected2.srt", -9)
Open "movie_corrected2.srt" For Input As #f
While Not Eof(f)
Line Input #f, linea
Print linea
Wend
Close #f
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as Wren entry.</pre>
 
=={{header|Phix}}==
2,170

edits