diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/SSA.pm index 4e40b7f..b479277 100644 --- a/lib/Subtitle/SSA.pm +++ b/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;