From e2994de81dc9d7a230b89a9c2cb0c8e7694b5b27 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 12 Sep 2010 23:21:09 +0200 Subject: [PATCH] convert srt to our yaml format --- bin/srt2yaml.pl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 bin/srt2yaml.pl 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; -- 2.20.1