|
|
@ -5,6 +5,8 @@ use warnings; |
|
|
|
use feature qw(switch); |
|
|
|
use feature qw(switch); |
|
|
|
use utf8; |
|
|
|
use utf8; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use base 'Subtitle::BASE'; |
|
|
|
|
|
|
|
|
|
|
|
sub new { |
|
|
|
sub new { |
|
|
|
my ($class, %args) = @_; |
|
|
|
my ($class, %args) = @_; |
|
|
|
my $self = { |
|
|
|
my $self = { |
|
|
@ -18,26 +20,6 @@ sub new { |
|
|
|
return bless($self, $class); |
|
|
|
return bless($self, $class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub trim { |
|
|
|
|
|
|
|
my ($self, $line) = @_; |
|
|
|
|
|
|
|
return unless defined $line; |
|
|
|
|
|
|
|
return $line =~ s/(^\s+|\s+$)//or; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub log { |
|
|
|
|
|
|
|
my ($self, $level, $msg) = @_; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
given ($level) { |
|
|
|
|
|
|
|
when ("error") { push @{ $self->{log} }, "E: $msg"; } |
|
|
|
|
|
|
|
when ("warn") { push @{ $self->{log} }, "W: $msg"; } |
|
|
|
|
|
|
|
when ("info") { push @{ $self->{log} }, "I: $msg"; } |
|
|
|
|
|
|
|
when ("debug") { push @{ $self->{log} }, "D: $msg" if $self->{debug}; } |
|
|
|
|
|
|
|
default { warn "Unknown loglevel $level of $msg\n"; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub parse_timing { |
|
|
|
sub parse_timing { |
|
|
|
my ($self, $str) = @_; |
|
|
|
my ($self, $str) = @_; |
|
|
|
my $time = 0.0; |
|
|
|
my $time = 0.0; |
|
|
@ -81,7 +63,7 @@ sub parse { |
|
|
|
|
|
|
|
|
|
|
|
foreach my $line (@$lines) { |
|
|
|
foreach my $line (@$lines) { |
|
|
|
$linenum++; |
|
|
|
$linenum++; |
|
|
|
$line =~ s/[\r\n]+$//o; # chomp |
|
|
|
$line = $self->chomp($line); |
|
|
|
# expected: event id |
|
|
|
# expected: event id |
|
|
|
if ($line and not $event) { |
|
|
|
if ($line and not $event) { |
|
|
|
$event = $self->new_event; |
|
|
|
$event = $self->new_event; |
|
|
|