Browse Source

* Subtitle::MSub : implement build()

master
Alex 'AdUser' Z 9 years ago
parent
commit
37a6a6b45b
  1. 24
      lib/Subtitle/MSub.pm

24
lib/Subtitle/MSub.pm

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use Subtitle::Utils qw(:string); use Subtitle::Utils qw(:string round);
use base 'Subtitle::BASE'; use base 'Subtitle::BASE';
@ -80,6 +80,22 @@ sub parse {
return scalar @{ $self->{events} }; return scalar @{ $self->{events} };
} }
sub build {
my ($self) = @_;
my @lines;
push @lines, sprintf "{1}{1}%.3f", $self->{fps};
foreach my $e (@{ $self->{events} }) {
my $show = round($e->{timing}->[0] * $self->{fps}, 0);
my $hide = round($e->{timing}->[1] * $self->{fps}, 0);
my $text = ($e->{text} =~ s{$self->{eol}}{|}gr);
push @lines, sprintf "{%d}{%d}%s", $show, $hide, $text;
}
push @lines, "";
return join($self->{eol} => @lines);
}
1; 1;
=pod =pod
@ -110,4 +126,10 @@ Recognized keys are:
Parse subtitle from array of lines. Parse subtitle from array of lines.
Returns parsed events count on success, -1 on error Returns parsed events count on success, -1 on error
=head2 C<build>
my $text = $msub->build();
Builds parsed subtitle to string.
=cut =cut

Loading…
Cancel
Save