Sync subtitles: Difference between revisions
Content added Content deleted
(Added various BASIC dialects (Gambas y PureBasic)) |
(Added Yabasic) |
||
Line 600: | Line 600: | ||
Close #f2, #f1 |
Close #f2, #f1 |
||
End Sub</syntaxhighlight> |
End Sub</syntaxhighlight> |
||
==={{header|Yabasic}}=== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="yabasic">print "After fast-forwarding 9 seconds:\n" |
|||
syncSubtitles("movie.srt", "movie_corrected.srt", 9) |
|||
f = open("movie_corrected.srt") |
|||
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) |
|||
f = open("movie_corrected2.srt") |
|||
while not eof(f) |
|||
line input #f linea$ |
|||
print linea$ |
|||
wend |
|||
close #f |
|||
end |
|||
sub addSeconds$ (timeStr$, secs) |
|||
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 = ss + 60 |
|||
mm = mm - 1 |
|||
wend |
|||
while mm < 0 |
|||
mm = mm + 60 |
|||
hh = hh - 1 |
|||
wend |
|||
while hh < 0 |
|||
hh = hh + 24 |
|||
wend |
|||
mm = mm + int(ss / 60) |
|||
hh = hh + int(mm / 60) |
|||
ss = mod(ss, 60) |
|||
mm = mod(mm, 60) |
|||
hh = mod(hh, 24) |
|||
return right$("0" + str$(hh), 2) + ":" + right$("0" + str$(mm), 2) + ":" + right$("0" + str$(ss), 2) + "," + right$("000" + str$(ttt), 3) |
|||
end sub |
|||
sub syncSubtitles (fileIn$, fileOut$, secs) |
|||
fmt$ = "hh:MM:ss,ttt" |
|||
nl$ = chr$(10) |
|||
open fileOut$ for writing as #1 |
|||
open fileIn$ for reading as #2 |
|||
while not eof(2) |
|||
line input #2 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 #1, pio$ + " --> " + fin$ + nl$; |
|||
else |
|||
print #1, linea$ + nl$; |
|||
fi |
|||
wend |
|||
close #2 |
|||
close #1 |
|||
end sub</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |