Browse Source

+ Subtitle::SSA->style_usage

master
Alex 'AdUser' Z 6 years ago
parent
commit
eb2c10edda
  1. 30
      lib/Subtitle/SSA.pm

30
lib/Subtitle/SSA.pm

@ -187,4 +187,34 @@ sub build {
return join($self->{eol}, @lines);
}
sub style_usage {
my ($self) = @_;
my $styles = {};
foreach my $s (@{ $self->{styles} }) {
$styles->{ $s->{name} } = 0;
}
my $stats = {};
foreach my $e (@{ $self->{events} }) {
my $sn = $e->{style} || 'Default';
if ($sn eq '*Default') {
# even libass author not knows what really '*' means
$sn = 'Default';
}
$stats->{$sn} //= 0;
$stats->{$sn}++;
next if exists $styles->{$sn};
my $msg = sprintf "Event uses style named '%s' but it's not defined", $sn;
$self->log(warn => $msg);
}
my @unused = grep { $stats->{$_} == 0 } keys %{ $stats };
foreach my $u (@unused) {
$self->log(warn => "Style '$u' not used by any event");
}
return $stats;
}
1;

Loading…
Cancel
Save