Browse Source

* move all formats under Subtitle::Format namespace

master
Alex 'AdUser' Z 6 years ago
parent
commit
bfa2083a24
  1. 4
      bin/ssa-info
  2. 4
      bin/ssa-retime
  3. 2
      lib/Subtitle/Format/MSub.pm
  4. 2
      lib/Subtitle/Format/SRT.pm
  5. 24
      lib/Subtitle/Format/SSA.pm
  6. 4
      lib/Subtitle/Format/SSA/Event.pm
  7. 2
      lib/Subtitle/Format/SSA/File.pm
  8. 2
      lib/Subtitle/Format/SSA/Header.pm
  9. 2
      lib/Subtitle/Format/SSA/Record.pm
  10. 4
      lib/Subtitle/Format/SSA/Style.pm
  11. 6
      t/format-msub.t
  12. 6
      t/format-srt.t
  13. 10
      t/format-ssa-event.t
  14. 8
      t/format-ssa-file.t
  15. 4
      t/format-ssa-header.t
  16. 10
      t/format-ssa-style.t

4
bin/ssa-info

@ -5,7 +5,7 @@ use warnings;
use lib 'lib';
use utf8;
use Subtitle::SSA;
use Subtitle::Format::SSA;
sub usage {
my ($msg) = @_;
@ -29,7 +29,7 @@ unless (@ARGV and -f $ARGV[0]) {
warn "no file given\n";
usage();
}
my $ssa = Subtitle::SSA->new(debug => 0);
my $ssa = Subtitle::Format::SSA->new(debug => 0);
if ($ssa->from_file($ARGV[0]) < 0) {
warn "Can't parse input file: $ARGV[0]\n";
exit 1;

4
bin/ssa-retime

@ -6,7 +6,7 @@ use lib 'lib';
use utf8;
use Getopt::Long;
use Subtitle::SSA;
use Subtitle::Format::SSA;
sub usage {
my ($msg) = @_;
@ -102,7 +102,7 @@ if ($mode eq 'framerate') {
usage("Incorrect mode: $mode (see help below)");
}
my $ssa = Subtitle::SSA->new(debug => !!$opts{loglevel});
my $ssa = Subtitle::Format::SSA->new(debug => !!$opts{loglevel});
unless ($ssa->from_file($opts{infile})) {
foreach my $line (@{ $ssa->{log} }) {
print $line, "\n";

2
lib/Subtitle/MSub.pm → lib/Subtitle/Format/MSub.pm

@ -1,4 +1,4 @@
package Subtitle::MSub;
package Subtitle::Format::MSub;
use strict;
use warnings;

2
lib/Subtitle/SRT.pm → lib/Subtitle/Format/SRT.pm

@ -1,4 +1,4 @@
package Subtitle::SRT;
package Subtitle::Format::SRT;
use strict;
use warnings;

24
lib/Subtitle/SSA.pm → lib/Subtitle/Format/SSA.pm

@ -1,13 +1,13 @@
package Subtitle::SSA;
package Subtitle::Format::SSA;
use strict;
use warnings;
use utf8;
use Subtitle::SSA::Header;
use Subtitle::SSA::Style;
use Subtitle::SSA::Event;
use Subtitle::SSA::File;
use Subtitle::Format::SSA::Header;
use Subtitle::Format::SSA::Style;
use Subtitle::Format::SSA::Event;
use Subtitle::Format::SSA::File;
use Subtitle::Utils qw(:string);
@ -71,7 +71,7 @@ sub parse {
if ($section eq 'fonts') {
if (index($line, 'fontname:') == 0) {
$line =~ m/^fontname:\s*(.*)/o;
$font = Subtitle::SSA::File->new;
$font = Subtitle::Format::SSA::File->new;
$font->type('font');
$font->name($1);
push @{ $self->{fonts} }, $font;
@ -89,7 +89,7 @@ sub parse {
# skip comments
next if $line =~ m{^ \s* ;}xo;
if ($section eq 'header') {
my $header = Subtitle::SSA::Header->new;
my $header = Subtitle::Format::SSA::Header->new;
unless ($header->parse($line)) {
$self->log(error => "Can't parse header at line $linenum: $line");
next;
@ -113,7 +113,7 @@ sub parse {
$self->log(debug => "Set style format from line $linenum");
next;
}
my $style = Subtitle::SSA::Style->new(type => $self->{type});
my $style = Subtitle::Format::SSA::Style->new(type => $self->{type});
if ($style->parse($line)) {
push @{ $self->{styles} }, $style;
} else {
@ -127,7 +127,7 @@ sub parse {
$self->log(debug => "Set event format from line $linenum");
next;
}
my $event = Subtitle::SSA::Event->new(type => $self->{type});
my $event = Subtitle::Format::SSA::Event->new(type => $self->{type});
if ($event->parse($line)) {
push @{ $self->{events} }, $event;
} else {
@ -148,7 +148,7 @@ sub build {
# headers
push @lines, "[Script Info]";
push @lines, "; generated with Subtitle::SSA";
push @lines, "; generated with Subtitle::Format::SSA";
foreach my $key (@{ $self->{h_order} }) {
my $h = $self->{headers}->{$key};
push @lines, $h->to_string();
@ -161,7 +161,7 @@ sub build {
} else {
push @lines, "[V4 Styles]";
}
push @lines, Subtitle::SSA::Style->new(type => $self->{type})->get_format_line();
push @lines, Subtitle::Format::SSA::Style->new(type => $self->{type})->get_format_line();
foreach my $s (@{ $self->{styles} }) {
push @lines, $s->to_string();
}
@ -169,7 +169,7 @@ sub build {
# events
push @lines, "[Events]";
push @lines, Subtitle::SSA::Event->new(type => $self->{type})->get_format_line();
push @lines, Subtitle::Format::SSA::Event->new(type => $self->{type})->get_format_line();
foreach my $e (@{ $self->{events} }) {
push @lines, $e->to_string();
}

4
lib/Subtitle/SSA/Event.pm → lib/Subtitle/Format/SSA/Event.pm

@ -1,10 +1,10 @@
package Subtitle::SSA::Event;
package Subtitle::Format::SSA::Event;
use strict;
use warnings;
use utf8;
use base 'Subtitle::SSA::Record';
use base 'Subtitle::Format::SSA::Record';
my @FIELDS_SSA = qw(marked start end style name marginl marginr marginv effect text);
my @FIELDS_ASS = qw(layer start end style name marginl marginr marginv effect text);

2
lib/Subtitle/SSA/File.pm → lib/Subtitle/Format/SSA/File.pm

@ -1,4 +1,4 @@
package Subtitle::SSA::File;
package Subtitle::Format::SSA::File;
use strict;
use warnings;

2
lib/Subtitle/SSA/Header.pm → lib/Subtitle/Format/SSA/Header.pm

@ -1,4 +1,4 @@
package Subtitle::SSA::Header;
package Subtitle::Format::SSA::Header;
use strict;
use warnings;

2
lib/Subtitle/SSA/Record.pm → lib/Subtitle/Format/SSA/Record.pm

@ -1,4 +1,4 @@
package Subtitle::SSA::Record;
package Subtitle::Format::SSA::Record;
use strict;
use warnings;

4
lib/Subtitle/SSA/Style.pm → lib/Subtitle/Format/SSA/Style.pm

@ -1,10 +1,10 @@
package Subtitle::SSA::Style;
package Subtitle::Format::SSA::Style;
use strict;
use warnings;
use utf8;
use base 'Subtitle::SSA::Record';
use base 'Subtitle::Format::SSA::Record';
my @FIELDS_SSA = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding);
my @FIELDS_ASS = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding);

6
t/format-msub.t

@ -3,10 +3,10 @@ use warnings;
use Test::More tests => 9;
use Subtitle::MSub;
use Subtitle::Format::MSub;
my $msub = Subtitle::MSub->new(debug => 1);
is(ref $msub, 'Subtitle::MSub');
my $msub = Subtitle::Format::MSub->new(debug => 1);
is(ref $msub, 'Subtitle::Format::MSub');
can_ok($msub, qw(new parse));
my $sample = <<"EOF";

6
t/format-srt.t

@ -3,10 +3,10 @@ use warnings;
use Test::More tests => 9;
use Subtitle::SRT;
use Subtitle::Format::SRT;
my $srt = Subtitle::SRT->new(debug => 1);
is(ref $srt, 'Subtitle::SRT');
my $srt = Subtitle::Format::SRT->new(debug => 1);
is(ref $srt, 'Subtitle::Format::SRT');
can_ok($srt, qw(new parse));
my $sample = <<"EOF";

10
t/format-ssa-event.t

@ -3,14 +3,14 @@ use warnings;
use Test::More tests => 30;
use Subtitle::SSA::Event;
use Subtitle::Format::SSA::Event;
my ($fields, @fields, $format, $sample, $event, $output);
# SSA format line
$format = 'Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text';
@fields = qw(marked start end style name marginl marginr marginv effect text);
$event = Subtitle::SSA::Event->new(type => 'ssa');
$event = Subtitle::Format::SSA::Event->new(type => 'ssa');
$fields = $event->parse_format_line($format);
is(ref $fields, 'ARRAY');
is_deeply($fields, \@fields);
@ -18,13 +18,13 @@ is_deeply($fields, \@fields);
# ASS format line
$format = 'Format:Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text';
@fields = qw(layer start end style name marginl marginr marginv effect text);
$event = Subtitle::SSA::Event->new(type => 'ass');
$event = Subtitle::Format::SSA::Event->new(type => 'ass');
$fields = $event->parse_format_line($format);
is(ref $fields, 'ARRAY');
is_deeply($fields, \@fields);
$sample = 'Dialogue: Marked=0,0:01:50.15,0:01:54.15,Main,,0000,0000,0050,,Наступило новое утро';
$event = Subtitle::SSA::Event->new(type => 'ssa');
$event = Subtitle::Format::SSA::Event->new(type => 'ssa');
ok($event->parse($sample), "SSA event parsing test");
is($event->{marked} => 'Marked=0');
is($event->{start} => 110.15);
@ -41,7 +41,7 @@ ok($output = $event->to_string(), 'converting SSA event to string');
is($output => $sample);
$sample = 'Dialogue: 1,0:01:06.68,0:01:07.49,text three,,0000,0000,0000,,Я счастлив.';
$event = Subtitle::SSA::Event->new(type => 'ass');
$event = Subtitle::Format::SSA::Event->new(type => 'ass');
ok($event->parse($sample), "ASS event parsing test");
is($event->{layer} => 1);
is($event->{start} => 66.68);

8
t/format-ssa-file.t

@ -3,7 +3,7 @@ use warnings;
use Test::More tests => 62;
use Subtitle::SSA::File;
use Subtitle::Format::SSA::File;
sub random_data {
my $data = '';
@ -15,14 +15,14 @@ sub random_data {
return $data;
}
my $file = Subtitle::SSA::File->new;
is(ref $file, 'Subtitle::SSA::File');
my $file = Subtitle::Format::SSA::File->new;
is(ref $file, 'Subtitle::Format::SSA::File');
can_ok($file, qw(new error size type name from_binary add_uue_line to_binary uue_string uue_block));
undef $file;
for (my $i = 0; $i < 15; $i++) {
my $bin = random_data();
$file = Subtitle::SSA::File->new;
$file = Subtitle::Format::SSA::File->new;
$file->from_binary($bin);
is($file->size => length $bin);
my $uue = $file->uue_string;

4
t/format-ssa-header.t

@ -3,7 +3,7 @@ use warnings;
use Test::More tests => 43;
use Subtitle::SSA::Header;
use Subtitle::Format::SSA::Header;
my $sample = <<"EOF";
[Script Info]
@ -29,7 +29,7 @@ my @headers;
my @lines = split /\n/, $sample;
splice @lines, 0, 3; # skip section header and comments
foreach my $line (@lines) {
my $header = Subtitle::SSA::Header->new;
my $header = Subtitle::Format::SSA::Header->new;
ok($header->parse($line), "line parsing");
my ($name, $value) = split(": ", $line, 2);
is($header->{name} => $name);

10
t/format-ssa-style.t

@ -3,14 +3,14 @@ use warnings;
use Test::More tests => 51;
use Subtitle::SSA::Style;
use Subtitle::Format::SSA::Style;
my ($fields, @fields, $format, $sample, $style, $output);
# SSA format line
$format = 'Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding';
@fields = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding);
$style = Subtitle::SSA::Style->new(type => 'ssa');
$style = Subtitle::Format::SSA::Style->new(type => 'ssa');
$fields = $style->parse_format_line($format);
is(ref $fields, 'ARRAY');
is_deeply($fields, \@fields);
@ -18,13 +18,13 @@ is_deeply($fields, \@fields);
# ASS format line
$format = 'Format:Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding';
@fields = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding);
$style = Subtitle::SSA::Style->new(type => 'ass');
$style = Subtitle::Format::SSA::Style->new(type => 'ass');
$fields = $style->parse_format_line($format);
is(ref $fields, 'ARRAY');
is_deeply($fields, \@fields);
$sample = 'Style: Default,Arial,20,11259130,33023,12582847,32,-1,0,1,2,1,2,10,10,2,0,204';
$style = Subtitle::SSA::Style->new(type => 'ssa');
$style = Subtitle::Format::SSA::Style->new(type => 'ssa');
ok($style->parse($sample), "SSA style parsing test");
is($style->{name} => 'Default');
is($style->{fontname} => 'Arial');
@ -49,7 +49,7 @@ ok($output = $style->to_string(), 'converting SSA style to string');
is($output, $sample);
$sample = 'Style: Default,Georgia,50,&H00F0F4F6,&H008D7127,&H00414B4C,&H00000000,0,0,0,0,100,95,0,0,1,3.5,0,2,11,11,13,204';
$style = Subtitle::SSA::Style->new(type => 'ass');
$style = Subtitle::Format::SSA::Style->new(type => 'ass');
ok($style->parse($sample), "ASS style parsing test");
is($style->{name} => 'Default');
is($style->{fontname} => 'Georgia');

Loading…
Cancel
Save