convert srt to our yaml format
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 12 Sep 2010 21:21:09 +0000 (23:21 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 12 Sep 2010 21:21:09 +0000 (23:21 +0200)
bin/srt2yaml.pl [new file with mode: 0755]

diff --git a/bin/srt2yaml.pl b/bin/srt2yaml.pl
new file mode 100755 (executable)
index 0000000..89414bc
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+# ./bin/srt2yaml.pl media/_editing/captions.srt > media/_editing/video.srt.yaml
+
+use warnings;
+use strict;
+
+use YAML;
+use Data::Dump qw(dump);
+
+my @subtitles;
+
+my $nr = 0;
+our @s;
+
+sub to_t {
+       my $txt = shift;
+       $txt =~ s/,/./; # fix decimal
+       my @t = split(/:/,$txt);
+       my $t = ( $t[0] * 60 * 60 ) + ( $t[1] * 60 ) + $t[2];
+       warn "# $txt -> $t\n";
+       return $t;
+}
+
+while(<>) {
+       s/^\xEF\xBB\xBF//; # strip utf-8 marker
+       s/[\n\r]+$//;
+       warn "# ",dump $_;
+       if ( length($_) == 0 ) {
+
+               warn "s = ",dump(@s);
+
+               my ( $f,$t ) = split(/\s*-->\s*/, $s[1], 2);
+
+               $subtitles[ $s[0] ] = [ to_t($f), to_t($t), join(" ", @s[ 2 .. $#s ]) ];
+
+               @s = ();
+               next;
+       }
+       push @s, $_;
+
+}
+
+$subtitles[0] ||= [ 0, 0.001, "[1]" ]; # fake first slide
+
+print Dump @subtitles;