From eb2c10eddab44505385423d78f212629a7f8ae44 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 23 Jul 2018 02:24:17 +1000 Subject: [PATCH] + Subtitle::SSA->style_usage --- lib/Subtitle/SSA.pm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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;