|
|
@ -203,4 +203,48 @@ sub parse { |
|
|
|
return scalar @{ $self->{events} }; |
|
|
|
return scalar @{ $self->{events} }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub build { |
|
|
|
|
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
my $out = "[Script Info]\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# headers |
|
|
|
|
|
|
|
foreach my $h (sort keys($self->{headers})) { |
|
|
|
|
|
|
|
$out .= sprintf "%s: %s\n", $h, $self->{headers}->{$h}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$out .= "\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# styles |
|
|
|
|
|
|
|
if ($self->{type} eq 'ass') { |
|
|
|
|
|
|
|
$out .= "[V4+ Styles]\n"; |
|
|
|
|
|
|
|
$out .= sprintf "Format: %s\n", join(', ' => @{ $self->ASS_STYLE_FMT }); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$out .= "[V4 Styles]\n"; |
|
|
|
|
|
|
|
$out .= sprintf "Format: %s\n", join(', ' => @{ $self->SSA_STYLE_FMT }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
my @fields = @{ $self->{style_fmt} }; |
|
|
|
|
|
|
|
foreach my $s (@{ $self->{styles} }) { |
|
|
|
|
|
|
|
$out .= sprintf "Style: %s\n", join(",", @{$s}{@fields}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$out .= "\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# events |
|
|
|
|
|
|
|
$out .= "[Events]\n"; |
|
|
|
|
|
|
|
if ($self->{type} eq 'ass') { |
|
|
|
|
|
|
|
$out .= sprintf "Format: %s\n", join(', ' => @{ $self->ASS_EVENT_FMT }); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$out .= sprintf "Format: %s\n", join(', ' => @{ $self->SSA_EVENT_FMT }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@fields = @{ $self->{event_fmt} }; |
|
|
|
|
|
|
|
foreach my $e (@{ $self->{events} }) { |
|
|
|
|
|
|
|
my %event = %{$e}; |
|
|
|
|
|
|
|
$event{start} = $self->build_timing($event{start}); |
|
|
|
|
|
|
|
$event{end} = $self->build_timing($event{end}); |
|
|
|
|
|
|
|
$event{marked} =~ s/^/Marked=/o if $self->{type} eq 'ssa'; |
|
|
|
|
|
|
|
$out .= sprintf "%s: %s\n", ucfirst($e->{type}), join(',' => @event{@fields}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$out .= "\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
1; |
|
|
|
1; |
|
|
|