What Thorsten meant is something like this:
#!/usr/bin/perl
use strict;
use warnings FATAL => qw(all);
my $END = '!!ZZ_END';
my $LastTitleDuration = 5;
my $count = 1;
my $line = <STDIN>;
chomp $line;
my $next = <STDIN>;
while ($line) {
$next = lastSubtitle($line) if !$next;
last if !$next;
chomp $next;
if (!($next =~ m/^\d\d:\d\d:\d\d:.+/)) {
print STDERR 'Skipping bad data at line '.($count+1).":\n$line\n";
$next = <STDIN>;
next;
}
printf STDOUT
"%d\r\n%s,100 --> %s,000\r\n%s\r\n\r\n",
$count++,
substr($line, 0, 8),
substr($next, 0, 8),
substr($line, 9)
;
} continue {
$line = $next;
$next = <STDIN>;
}
sub lastSubtitle {
my $line = shift;
$line =~ /^(\d\d:\d\d:)(\d\d):(.+)/;
return 0 if $3 eq $END;
return sprintf("$1%2d:$END", $2 + $LastTitleDuration);
}
When I feed your sample data into this, I get:
1
00:00:44,100 --> 00:01:01,000
" Myślę, więc jestem".|Kartezjusz, 1596-1650
2
00:01:01,100 --> 00:01:06,000
Trzynaste Pietro
3
00:01:06,100 --> 00:01:10,000
Podobno niewiedza uszczęśliwia.
4
00:01:10,100 --> 00:01:13,000
Po raz pierwszy w życiu|zgadzam się z tym.
5
00:01:13,100 --> 00:01:15,000
Wolałbym...
6
00:01:15,100 --> 00:01:19,000
nigdy nie odkryć|tej straszliwej prawdy.
7
00:01:19,100 --> 00:01:24,000
Teraz już wiem...
Couple of points:
The subtitles actually start 1/10th second late so they do not overlap, and because I was too lazy to add in some math involving the second timestamp. They then stay on until 1/10th second before the next title.
The last title stays up for $LastTitleDuration (5 seconds).
I used CRLF line endings as per the SupRip wikipedia article although that may not be necessary.
It presumes the first line of input is not malformed. Beyond that, they are checked, and errors are reported to stdout, so:
readAlongToSRT.pl < readAlong.txt > whatever.srt
Should create the file but still print errors to the screen.
Processing will stop at a blank line.
See terdon's comment below re: the possible significance of | in the subtitle content. You may want to insert $line =~ s/|/\r\n/g; before the printf STDOUT line.
This took me 20 minutes and the only test data I had was those 7 lines, so don't count on it being perfect. If there are ever line breaks in the subtitles, that will cause a problem. I presumed there aren't; if that is the case I suggest you remove them from the input first rather than trying to deal with them here.