From 524d4530b8f6527435ab4f1daa2df0d79694f6d2 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 20 Feb 2015 11:26:42 +1000 Subject: [PATCH] * Subtitle::SSA : draft --- lib/Subtitle/ASS.pm | 9 ------ lib/Subtitle/SSA.pm | 70 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 9 deletions(-) delete mode 100644 lib/Subtitle/ASS.pm create mode 100644 lib/Subtitle/SSA.pm diff --git a/lib/Subtitle/ASS.pm b/lib/Subtitle/ASS.pm deleted file mode 100644 index 76fbf79..0000000 --- a/lib/Subtitle/ASS.pm +++ /dev/null @@ -1,9 +0,0 @@ -package Subtitle::ASS; - -use strict; -use warnings; -use utf8; - -use Carp; - -1; diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/SSA.pm new file mode 100644 index 0000000..c9d4c61 --- /dev/null +++ b/lib/Subtitle/SSA.pm @@ -0,0 +1,70 @@ +package Subtitle::SSA; + +use strict; +use warnings; +use feature qw(switch); +use utf8; + +use base 'Subtitle::BASE'; + +sub new { + my ($class, %args) = @_; + my $self = { + debug => 0, + eol => "\n", + %args, + events => [], + log => [], + }; + + return bless($self, $class); +} + +sub parse_timing { + my ($self, $str) = @_; + ... + my $time = 0.0; + return unless $str =~ m/(\d+):(\d+):(\d+)([.,])(\d+)/oi; + my ($hrs, $min, $sec, $delim, $msec) = ($1, $2, $3, $4, $5); + if ($msec < 0 or $msec > 999) { + $self->log(warn => "wrong mseconds part of timing: $msec"); + return; + } + if ($sec < 0 or $sec > 59) { + $self->log(warn => "wrong seconds part of timing: $sec"); + return; + } + if ($min < 0 or $min > 59) { + $self->log(warn => "wrong minutes part of timing: $sec"); + return; + } + if ($hrs < 0) { + $self->log(warn => "wrong minutes part of timing: $sec"); + return; + } + given (length("$msec")) { + when ("3") { $time += $msec * 0.001; } + when ("2") { $time += $msec * 0.01; } + when ("1") { $time += $msec * 0.1; } + default { die("abnormal length of mseconds part"); } + } + $time += $sec; + $time += $min * 60; + $time += $hrs * 60 * 60; + return $time; +} + +sub new_event { return +{ id => undef, timing => undef, style => undef, text => undef }; } + +sub parse { + my ($self, $lines) = @_; + my $linenum = 0; + my $event; + + foreach my $line (@$lines) { + } + + return scalar @{ $self->{events} }; +} + +1;