Sync subtitles: Difference between revisions

m (→‎{{header|Phix}}: and a floor(milliseconds) issue.)
(→‎{{header|Phix}}: Added Wren)
Line 214:
00:02:13,416 --> 00:02:16,419
00:02:16,503 --> 00:02:20,048
With our advanced technology, I shrank it down.
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-date}}
{{libheader|Wren-ioutil}}
<syntaxhighlight lang="wren">import "./date" for Date
import "./ioutil" for File, FileUtil
 
var syncSubtitles = Fn.new { |fileIn, fileOut, secs|
var nl = FileUtil.lineBreak
var fmt = "hh|:|MM|:|ss|,|ttt"
var f = File.create(fileOut)
for (line in FileUtil.readLines(fileIn)) {
if (line.contains("-->")) {
var start = line[0..11]
var startDate = Date.parse(start, fmt).addSeconds(secs)
start = startDate.format(fmt)
var end = line[17..28]
var endDate = Date.parse(end, fmt).addSeconds(secs)
end = endDate.format(fmt)
f.writeBytes(start + " --> " + end + nl)
} else {
f.writeBytes(line + nl)
}
}
f.close()
}
 
System.print("After fast-forwarding 9 seconds:\n")
syncSubtitles.call("movie.srt", "movie_corrected.srt", 9)
System.print(File.read("movie_corrected.srt"))
System.print("After rolling-back 9 seconds:\n")
syncSubtitles.call("movie.srt", "movie_corrected2.srt", -9)
System.print(File.read("movie_corrected2.srt"))</syntaxhighlight>
 
{{out}}
<pre>
After fast-forwarding 9 seconds:
 
1
00:01:40,550 --> 00:01:45,347
Four billion years ago,
the first marine life forms.
 
2
00:01:45,555 --> 00:01:51,019
First came the fish...then slowly
other life forms evolved.
 
3
00:01:51,144 --> 00:01:52,979
Therefore, our ancestors...
 
4
00:01:52,979 --> 00:01:54,898
...came from fish.
 
5
00:01:55,232 --> 00:01:56,608
Everyone, come and see this.
 
6
00:01:56,733 --> 00:01:59,361
Cretaceous Tyrannosaurus.
 
7
00:01:59,736 --> 00:02:01,488
Ferocious!
 
8
00:02:07,035 --> 00:02:07,869
Red,
 
9
00:02:08,203 --> 00:02:09,079
Pong!
 
10
00:02:11,540 --> 00:02:12,999
Isn't this a gecko?
 
11
00:02:13,416 --> 00:02:16,419
How else can I get a 15 ton T-Rex in here?
 
12
00:02:16,503 --> 00:02:20,048
With our advanced technology, I shrank it down.
 
 
After rolling-back 9 seconds:
 
1
00:01:22,550 --> 00:01:27,347
Four billion years ago,
the first marine life forms.
 
2
00:01:27,555 --> 00:01:33,019
First came the fish...then slowly
other life forms evolved.
 
3
00:01:33,144 --> 00:01:34,979
Therefore, our ancestors...
 
4
00:01:34,979 --> 00:01:36,898
...came from fish.
 
5
00:01:37,232 --> 00:01:38,608
Everyone, come and see this.
 
6
00:01:38,733 --> 00:01:41,361
Cretaceous Tyrannosaurus.
 
7
00:01:41,736 --> 00:01:43,488
Ferocious!
 
8
00:01:49,035 --> 00:01:49,869
Red,
 
9
00:01:50,203 --> 00:01:51,079
Pong!
 
10
00:01:53,540 --> 00:01:54,999
Isn't this a gecko?
 
11
00:01:55,416 --> 00:01:58,419
How else can I get a 15 ton T-Rex in here?
 
12
00:01:58,503 --> 00:02:02,048
With our advanced technology, I shrank it down.
</pre>
9,490

edits