#! /usr/bin/perl -w
########################################################################
#### file : srt2ltt.pl
#### date : april 28 1998
#### author : Cedric Auzanne for NIST
#### description : parses a srt file to create a ltt file
####
########################################################################
#### usage : srt2ltt.pl srtfile_full_path
####
########################################################################
########################################################################
#### check parameters
die "\nERROR : no srt filename supplied\n" if ($#ARGV != 0);
$srtfilename = $ARGV[0];
$lttfilename = "$1.ltt" if ($srtfilename =~ /(.*?).srt/);
die "\nERROR : srt file $srtfilename not found\n" if (! -f $srtfilename);
print "Processing file $srtfilename to $lttfilename\n";
########################################################################
#### open output file, print comments
open OFD, ">$lttfilename" or die "\nERROR : can't open output file $lttfilename\n";
print OFD "\n";
print OFD "\tThis file was generated by srt2ltt.pl\n";
print OFD "\tdate : ", scalar localtime, "\n";
print OFD "\tsrt file : $srtfilename\n";
print OFD "\n\n";
########################################################################
########################################################################
########################################################################
#### start processing
$string = ""; # output string, needed to wrap words.
# read each line in srt file and process
open SRTFD, "<$srtfilename" or die "ERROR : can't open srt file $srtfilename\n";
while ()
{
# line is episode tag
if ((/^\s+(.*?)\s+<\/Word>/)
{
my $word = $3;
$word =~ tr/A-Z/a-z/;
my $wordsize = length $word;
if (((length $string) >= 78) || (($wordsize + (length $string)) >= 76))
{
print OFD "$string\n";
$string = "";
}
$string = "$string $word";
}
# evrything else is lost.
} # while
close SRTFD;
# finish processing
print OFD "\n\n\tend of file\n\n";
close OFD;
print "Done.\n";