From 8d93e4486a9ea907b53e2c5c6b7baecd5a345164 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 23 Jul 2018 02:24:42 +1000 Subject: [PATCH] + bin/ssa-info --- bin/ssa-info | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 bin/ssa-info diff --git a/bin/ssa-info b/bin/ssa-info new file mode 100755 index 0000000..c41a543 --- /dev/null +++ b/bin/ssa-info @@ -0,0 +1,70 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use lib 'lib'; +use utf8; + +use Subtitle::SSA; + +sub usage { + my ($msg) = @_; + print "ssa-info \n"; + exit 1; +} + +sub section { + my ($name) = @_; + printf "%s %s\n", '#' x 5, $name; +} + +sub line { + my ($name, $value) = @_; + printf " %-10s : %s\n", $name, $value; +} + +$| = 1; + +unless (@ARGV and -f $ARGV[0]) { + warn "no file given\n"; + usage(); +} +my $ssa = Subtitle::SSA->new(debug => 0); +if ($ssa->from_file($ARGV[0]) < 0) { + warn "Can't parse input file: $ARGV[0]\n"; + exit 1; +} + +section('Summary'); +line(Version => $ssa->{type}); +line(Headers => scalar keys %{ $ssa->{headers} }); +line(Styles => scalar @{ $ssa->{styles} }); +line(Events => scalar @{ $ssa->{events} }); +line(Fonts => scalar @{ $ssa->{fonts} }); + +section('Styles'); +{ + my $stats = $ssa->style_usage; + my @sorted = map { sprintf('%s (%d)', $_, $stats->{$_}) } + sort { $stats->{$b} <=> $stats->{$a} } keys %{ $stats }; + line(Usage => join(', ', @sorted)); +} + +if (scalar @{ $ssa->{fonts} } > 0) { + section('Fonts'); + my $i = 1; + foreach my $font (@{ $ssa->{fonts} }) { + my $name = sprintf "Font #%d", $i++; + my $value = sprintf "%s (%d bytes)", $font->name, $font->size; + line($name => $value); + } +} + +if (scalar @{ $ssa->{log} } > 0) { + section('Log records'); + foreach my $line (@{ $ssa->{log} }) { + printf "%s\n", $line; + } +} + +exit 0;