Info.pm

filter: Statementstmt 80.0% 64 / 80 Branchbran 70.0% 14 / 20 Conditioncond 10.0% 1 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 9 / 12 Podpod 37.5% 3 / 8 totaltotal 67.4% 91 / 135 CC 19 SCAR 21.4
CC
19
Cov
72%
probe
30.0
init
8.0
init_attributes
4.0
CRAP 8.5
« Info/MPEG.pm ↑ Summary Info/MPEG/Video.pm »
1 ##------------------------------------------------------------------------
2 ## Package: Info.pm
3 ## Author: Benjamin R. Ginter, Allen Day
4 ## Notice: Copyright (c) 2002 Benjamin R. Ginter, Allen Day
5 ## Purpose: Retrieve Video Properties
6 ## Comments: None
7 ## CVS: $Id
8 ##------------------------------------------------------------------------
9  
10 package Video::Info;
11  
12 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Video::Info::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 our $VERSION = '0.993';
17  
18 use Class::MakeMethods::Emulator::MethodMaker
19 4 ▶ get_set => [
Subroutine BEGIN: called CC=1 SCAR=0.0
20 'type', #ASF,MPEG,RIFF...
21 'title', #ASF media title
22 'author', #ASF author
23 'date', #ASF date (units???)
24 'copyright', #ASF copyright
25 'description', #ASF description (freetext)
26 'rating', #ASF MPAA rating
27 'packets', #ASF ???
28 'comments', #MPEG
29  
30 'astreams', #no. of audio streams. can this clash with achans?
31 #this has special behavior, method is below
32 # 'acodec', #audio codec
33 'acodecraw', #audio codec (numeric)
34 'arate', #audio bitrate
35 'afrequency', #audio sampling frequency, in Hz
36 'achans', #no. of audio channels. can this clash with astreams?
37  
38 'vstreams', #no. of video streams
39 'vcodec', #video codec
40 'vrate', #video bitrate
41 'vframes', #no. of video frames
42  
43 'fps', #video frames/second
44 'scale', #quoeth transcode: if(scale!=0) AVI->fps = (double)rate/(double)scale;
45 'duration', #duration of video, in seconds
46  
47 'width', #frame width
48 'height', #frame height
49  
50 'aspect_raw', #how to handle this? 16:9 scalar, or 16/9 float?
51 'aspect', #not sure what this is. from MPEG
52  
53 'filename', #the sourcefile name
54 'filesize', #the size of the source file
55  
56 '_handle', #filehandle to bitstream
57 ],
58 4 ;
59  
60 12 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
61 12 my $proto = shift;
62 12 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
63 12 my $self = bless {}, $class;
64  
65 12 $self = $self->init(@_);
66  
67 12 return $self;
68 }
69  
70 6 ▶sub init {
Subroutine init: called CC=8 SCAR=20.9
Pod undocumented
71 6 my($self,%raw) = @_;
72 # my($proto,%raw) = @_;
73 # my $class = ref($proto) || $proto;
74 # my $self = bless {}, $class;
75  
76 6 my %param;
77 6 foreach(keys %raw){/^-?(.+)/;$param{$1} = $raw{$_}};
78  
79 6 ▶ if($param{file}){
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"file"}) 6 0 6
80 6 my($filetype,$handler) = @{ divine($param{file}) };
81  
82 6 ▶ if($handler){
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 6 0 6
83 6 my $class = __PACKAGE__ . '::' . $handler;
84  
85 6 ▶ $class = 'MP3::Info' if $handler eq 'MP3';
Branch: 1 branch
BranchTrueFalseTotal
if $handler eq "MP3" 2 4 6
86  
87 6 my $has_class = eval "require $class";
88 6 $param{subtype} = $filetype;
89  
90 6 ▶ if($has_class){
Branch: 1 branch
BranchTrueFalseTotal
if ($has_class) 6 0 6
91 6 ▶ if($handler eq 'MP3'){
Branch: 1 branch
BranchTrueFalseTotal
if ($handler eq 'MP3') { } 2 4 6
92 2 $self = $class->new( $param{file} );
93 2 return $self;
94 } else {
95 4 $self = $class->new(%param);
96 4 $self->probe( $param{file}, [ $filetype, $handler ] );
97 }
98 }
99 }
100 }
101  
102 4 $self->{$_} = $param{$_} foreach(keys %param);
103  
104 4 $self->init_attributes(%param) ;
105  
106 4 $self->probe( $param{file} );
107  
108 4 return $self;
109 }
110  
111 8 ▶sub init_attributes {
Subroutine init_attributes: called CC=4 SCAR=13.9
Pod undocumented
112 8 my $self = shift;
113 8 my %raw = @_;
114 8 my %param;
115 8 foreach(keys %raw){/^-?(.+)/;$param{$1} = $raw{$_}};
116  
117 8 foreach my $attr (qw(
118 astreams arate achans vstreams vrate vframes fps
119 scale duration width height aspect aspect_raw
120 )
121 ) {
122 104 $self->$attr(0);
123 }
124  
125 8 $self->filename($param{file});
126 8 $self->filesize(-s $param{file});
127 8 ▶ $self->handle($param{file}) if $param{file};
Branch: 1 branch
BranchTrueFalseTotal
if $param{"file"} 8 0 8
128 }
129  
130 ##------------------------------------------------------------------------
131 ## Extra methods
132 ##
133 ##------------------------------------------------------------------------
134 10 ▶sub acodec {
Subroutine acodec: called CC=3 SCAR=11.0
Pod documented
135 10 my($self,$arg) = @_;
136 10 ▶ if($arg){
Branch: 2 branches
BranchTrueFalseTotal
if ($arg) { } 4 6 10
elsif (not $self->{'acodec'}) { } 1 5 6
137 4 $self->{acodec} = acodec2str($arg);
138 } elsif(!$self->{acodec}){
139 1 $self->{acodec} = acodec2str($self->acodecraw);
140 }
141 10 return $self->{acodec};
142 }
143  
144 0 ▶sub minutes {
Subroutine minutes: not called CC=1 SCAR=6.9
Pod documented
145 0 my $self = shift;
146 0 my $seconds = int($self->duration) % 60;
147 0 my $minutes = (int($self->duration) - $seconds) / 60;
148 0 return $minutes;
149 }
150  
151 0 ▶sub MMSS {
Subroutine MMSS: not called CC=1 SCAR=6.9
Pod documented
152 0 my $self = shift;
153 0 my $mm = $self->minutes;
154 0 my $ss = int($self->duration) - ($self->minutes * 60);
155  
156 0 my $return = sprintf( "%02d:%02d",$mm,$ss );
157 }
158  
159 ##------------------------------------------------------------------------
160 ## handle()
161 ##
162 ## Open a file handle or return an existing one
163 ##------------------------------------------------------------------------
164 16 ▶sub handle {
Subroutine handle: called CC=2 SCAR=6.9
Pod undocumented
165 16 my($self,$file) = @_;
166  
167 16 ▶ if(defined $file){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 8 8 16
168 8 my $fh = new IO::File;
169 8 $fh->open($file);
170 8 $self->_handle($fh);
171 }
172 16 return $self->_handle;
173 }
174  
175 ##------------------------------------------------------------------------
176 ## probe()
177 ##
178 ## Open a video file and gather the stats
179 ##------------------------------------------------------------------------
180 0 ▶sub probe {
Subroutine probe: not called CC=5 SCAR=34.0
Pod undocumented
181 0 my $self = shift;
182 0 ▶ my $file = shift || die "probe(): A filename argument is required.\n";
Condition0%0/2
shift() || die("probe(): A filename argument is required.\n")
l!l
00
MC/DC0%0/1
shift() || die("probe(): A filename argument is required.\n")
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
183 0 ▶ my $type = shift || divine($file) || die "probe(): Couldn't divine $file";
Condition0%0/5
shift() || divine($file) || die("probe(): Couldn't divine $file")
l!l
00
shift() or divine($file)
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || divine($file) || die("probe(): Couldn't divine $file")
shift() divine($file)
Truth table0%0/3
A or B
A= shift()B= divine($file)
ABresult
1X1
011
000
184  
185 0 my $warn;
186 0 ▶ if ( $type->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->[1]) { } 0 0 0
187 0 $warn .= "s of type $type->[1]\n";
188 }
189 else {
190 0 $warn .= " type $type->[0]\n";
191 }
192 0 warn( ref( $self ),
193 '::probe() abstract method -- Create a child class for file',
194 $warn );
195
196 }
197  
198 4 1;
199  
200 __END__
« Info/MPEG.pm ↑ Summary Info/MPEG/Video.pm »