From: Dobrica Pavlinusic Date: Sun, 12 Sep 2010 21:21:09 +0000 (+0200) Subject: convert srt to our yaml format X-Git-Url: http://git.rot13.org/?p=HTML5TV.git;a=commitdiff_plain;h=e2994de81dc9d7a230b89a9c2cb0c8e7694b5b27;hp=ee3024eed00e9b92ad6c17bd51b991c2c5d37bbd convert srt to our yaml format --- diff --git a/bin/srt2yaml.pl b/bin/srt2yaml.pl new file mode 100755 index 0000000..89414bc --- /dev/null +++ b/bin/srt2yaml.pl @@ -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;