Image/ExifTool/WTV.pm

filter: Statementstmt 90.8% 89 / 98 Branchbran 66.1% 41 / 62 Conditioncond 53.3% 8 / 15 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 76.1% 147 / 193 CC 37 SCAR 28.8
CC
37
Cov
79%
ProcessWTV
27.8
ProcessMetadata
12.9
ReadSectors
8.3
CRAP 17.9
« Image/ExifTool/JPEGDigest.pm ↑ Summary Image/ExifTool/Minolta.pm »
1 #------------------------------------------------------------------------------
2 # File: WTV.pm
3 #
4 # Description: Read WTV meta information
5 #
6 # Revisions: 2018-05-30 - P. Harvey Created
7 #
8 # References: 1) https://wiki.multimedia.cx/index.php?title=WTV
9 #------------------------------------------------------------------------------
10  
11 package Image::ExifTool::WTV;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 $VERSION = '1.01';
18  
19 sub ProcessMetadata($$$);
20  
21 1 my %timeInfo = (
22 # time looks like 100 ns intervals since 0:00 UTC Jan 1, 0001 (ref PH)
23 ValueConv => q{ # (719162 days from 0001:01:01 to 1970:01:01)
24 my $t = $val / 1e7 - 719162*24*3600;
25 return Image::ExifTool::ConvertUnixTime($t) . 'Z';
26 },
27 PrintConv => '$self->ConvertDateTime($val)',
28 );
29  
30 1 my %bool = ( PrintConv => { 0 => 'No', 1 => 'Yes' }, PrintConvColumns => 2 );
31  
32 # WTV chunks
33 1 %Image::ExifTool::WTV::Main = (
34 GROUPS => { 0 => 'WTV', 1 => 'WTV', 2 => 'Video' },
35 NOTES => 'Tags found in Windows recorded TV (WTV) videos.',
36 # 'timeline.table.0.header.Events' (not decoded)
37 # 'timeline.table.0.entries.Events' (not decoded)
38 # 'timeline' (not decoded)
39 # 'table.0.header.legacy_attrib' (not decoded)
40 'table.0.entries.legacy_attrib' => {
41 Name => 'Metdata',
42 SubDirectory => { TagTable => 'Image::ExifTool::WTV::Metadata' },
43 },
44 # 'table.0.redirector.legacy_attrib' (not decoded)
45 # 'table.0.header.time' (not decoded)
46 # 'table.0.entries.time' (not decoded)
47 );
48  
49 # Note: Many of these tags are similar to those found in Image::ExifTool::Microsoft::Xtra
50 # and Image::ExifTool::ASF::ExtendedDescr
51 1 %Image::ExifTool::WTV::Metadata = (
52 GROUPS => { 0 => 'WTV', 1 => 'WTV', 2 => 'Video' },
53 PROCESS_PROC => \&ProcessMetadata,
54 NOTES => 'ExifTool will extract any tag found, even if not in this table.',
55 VARS => { ID_FMT => 'none' },
56 'Duration' => {
57 Name => 'Duration',
58 ValueConv => '$val/1e7',
59 PrintConv => 'ConvertDuration($val)',
60 },
61 'Title' => { },
62 'WM/Genre' => 'Genre',
63 'WM/Language' => 'Language',
64 'WM/MediaClassPrimaryID' => 'MediaClassPrimaryID',
65 'WM/MediaClassSecondaryID' => 'MediaClassSecondaryID',
66 'WM/MediaCredits' => 'MediaCredits',
67 'WM/MediaIsDelay' => { Name => 'MediaIsDelay', %bool },
68 'WM/MediaIsFinale' => { Name => 'MediaIsFinale', %bool },
69 'WM/MediaIsLive' => { Name => 'MediaIsLive', %bool },
70 'WM/MediaIsMovie' => { Name => 'MediaIsMovie', %bool },
71 'WM/MediaIsPremiere' => { Name => 'MediaIsPremiere', %bool },
72 'WM/MediaIsRepeat' => { Name => 'MediaIsRepeat', %bool },
73 'WM/MediaIsSAP' => { Name => 'MediaIsSAP', %bool },
74 'WM/MediaIsSport' => { Name => 'MediaIsSport', %bool },
75 'WM/MediaIsStereo' => { Name => 'MediaIsStereo', %bool, Groups => { 2 => 'Audio' } },
76 'WM/MediaIsSubtitled' => { Name => 'MediaIsSubtitled',%bool },
77 'WM/MediaIsTape' => { Name => 'MediaIsTape', %bool },
78 'WM/MediaNetworkAffiliation'=> 'MediaNetworkAffiliation',
79 'WM/MediaOriginalBroadcastDateTime' => {
80 Name => 'MediaOriginalBroadcastDateTime',
81 Groups => { 2 => 'Time' },
82 ValueConv => '$val =~ tr/-T/: /; $val',
83 PrintConv => '$self->ConvertDateTime($val)',
84 },
85 'WM/MediaOriginalChannel' => { Name => 'MediaOriginalChannel' },
86 'WM/MediaOriginalChannelSubNumber' => { Name => 'MediaOriginalChannelSubNumber' },
87 'WM/MediaOriginalRunTime' => {
88 Name => 'MediaOriginalRunTime',
89 ValueConv => '$val / 1e7',
90 PrintConv => 'ConvertDuration($val)',
91 },
92 'WM/MediaStationCallSign' => 'MediaStationCallSign',
93 'WM/MediaStationName' => 'MediaStationName',
94 'WM/MediaThumbAspectRatioX' => 'MediaThumbAspectRatioX',
95 'WM/MediaThumbAspectRatioY' => 'MediaThumbAspectRatioY',
96 'WM/MediaThumbHeight' => 'MediaThumbHeight',
97 'WM/MediaThumbRatingAttributes' => { Name => 'MediaThumbRatingAttributes' },
98 'WM/MediaThumbRatingLevel' => 'MediaThumbRatingLevel',
99 'WM/MediaThumbRatingSystem' => 'MediaThumbRatingSystem',
100 'WM/MediaThumbRet' => 'MediaThumbRet',
101 'WM/MediaThumbStride' => 'MediaThumbStride',
102 'WM/MediaThumbTimeStamp' => { Name => 'MediaThumbTimeStamp', Notes => 'unknown units', Unknown => 1 },
103 'WM/MediaThumbWidth' => 'MediaThumbWidth',
104 'WM/OriginalReleaseTime' => {
105 Name => 'OriginalReleaseTime',
106 Groups => { 2 => 'Time' },
107 ValueConv => '$val=~tr/-T/: /; $val',
108 PrintConv => '$self->ConvertDateTime($val)',
109 },
110 'WM/ParentalRating' => 'ParentalRating',
111 'WM/ParentalRatingReason' => 'ParentalRatingReason',
112 'WM/Provider' => 'Provider',
113 'WM/ProviderCopyright' => 'ProviderCopyright',
114 'WM/ProviderRating' => 'ProviderRating',
115 'WM/SubTitle' => 'Subtitle',
116 'WM/SubTitleDescription' => 'SubtitleDescription',
117 'WM/VideoClosedCaptioning' => { Name => 'VideoClosedCaptioning', %bool },
118 'WM/WMRVATSCContent' => { Name => 'ATSCContent', %bool },
119 'WM/WMRVActualSoftPostPadding' => 'ActualSoftPostPadding',
120 'WM/WMRVActualSoftPrePadding' => 'ActualSoftPrePadding',
121 'WM/WMRVBitrate' => { Name => 'Bitrate', Notes => 'unknown units', Unknown => 1 },
122 'WM/WMRVBrandingImageID' => 'BrandingImageID',
123 'WM/WMRVBrandingName' => 'BrandingName',
124 'WM/WMRVContentProtected' => { Name => 'ContentProtected', %bool },
125 'WM/WMRVContentProtectedPercent' => 'ContentProtectedPercent',
126 'WM/WMRVDTVContent' => { Name => 'DTVContent', %bool },
127 'WM/WMRVEncodeTime' => { Name => 'EncodeTime', Groups => { 2 => 'Time' }, %timeInfo },
128 'WM/WMRVEndTime' => { Name => 'EndTime', Groups => { 2 => 'Time' }, %timeInfo },
129 'WM/WMRVExpirationDate' => { Name => 'ExpirationDate', Groups => { 2 => 'Time' }, %timeInfo, Unknown => 1 },
130 'WM/WMRVExpirationSpan' => { Name => 'ExpirationSpan', Notes => 'unknown units', Unknown => 1 },
131 'WM/WMRVHDContent' => { Name => 'HDContent', %bool },
132 'WM/WMRVHardPostPadding' => 'HardPostPadding',
133 'WM/WMRVHardPrePadding' => 'HardPrePadding',
134 'WM/WMRVInBandRatingAttributes' => 'InBandRatingAttributes',
135 'WM/WMRVInBandRatingLevel' => 'InBandRatingLevel',
136 'WM/WMRVInBandRatingSystem' => 'InBandRatingSystem',
137 'WM/WMRVKeepUntil' => 'KeepUntil',
138 'WM/WMRVOriginalSoftPostPadding'=> 'OriginalSoftPostPadding',
139 'WM/WMRVOriginalSoftPrePadding' => 'OriginalSoftPrePadding',
140 'WM/WMRVProgramID' => 'ProgramID',
141 'WM/WMRVQuality' => 'Quality',
142 'WM/WMRVRequestID' => 'RequestID',
143 'WM/WMRVScheduleItemID' => 'ScheduleItemID',
144 'WM/WMRVSeriesUID' => 'SeriesUID',
145 'WM/WMRVServiceID' => 'ServiceID',
146 'WM/WMRVWatched' => { Name => 'Watched', %bool },
147 );
148  
149 #------------------------------------------------------------------------------
150 # Read specified sectors from the file
151 # Inputs: 0) raf ref, 1) sector table ref, 2) offset in sector table, 3) sector size
152 # Returns: Data or undef on error
153 sub ReadSectors($$$$)
154 3 ▶{
Subroutine ReadSectors: called CC=8 SCAR=21.1
Pod undocumented
155 3 my ($raf, $secPt, $pos, $secSize) = @_;
156 3 my ($data, $buff);
157 3 ▶ while ($pos <= length($$secPt) - 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= length($$secPt) - 4) 31 1 32
158 31 my $sec = Get32u($secPt, $pos);
159 31 ▶ return undef if $sec == 0xffff; # (just in case)
Branch: 1 branch
BranchTrueFalseTotal
if $sec == 65535 0 31 31
160 31 ▶ last unless $sec; # a null marks the end of the sector table
Branch: 1 branch
BranchTrueFalseTotal
unless $sec 2 29 31
161 29 ▶ defined($data) ? ($data .= $buff) : ($data = $buff);
Branch: 1 branch
BranchTrueFalseTotal
defined $data ? : 24 5 29
162 29 ▶ return undef unless $raf->Seek($sec*$secSize,0) and $raf->Read($buff,$secSize) == $secSize;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek($sec * $secSize, 0) and $raf->Read($buff, $secSize) == $secSize 0 29 29
Condition33%1/3
$raf->Seek($sec * $secSize, 0) and $raf->Read($buff, $secSize) == $secSize
!ll&&!rl&&r
0029
MC/DC0%0/2
$raf->Seek($sec * $secSize, 0) and $raf->Read($buff, $secSize) == $secSize
$raf->Seek($sec * $secSize, 0) $raf->Read($buff, $secSize) == $secSize
Truth table33%1/3
A and B
A= $raf->Seek($sec * $secSize, 0)B= $raf->Read($buff, $secSize) == $secSize
ABresult
0X0
100
111
163 29 $pos += 4;
164 }
165 3 ▶ return defined($data) ? $data . $buff : $buff;
Branch: 1 branch
BranchTrueFalseTotal
defined $data ? : 2 1 3
166 }
167  
168 #------------------------------------------------------------------------------
169 # Process WTV metadata
170 # Inputs: 0) ExifTool object reference, 1) dirInfo reference, 2) tag table ref
171 # Returns: 1 on success
172 sub ProcessMetadata($$$)
173 1 ▶{
Subroutine ProcessMetadata: called CC=12 SCAR=25.6
Pod undocumented
174 1 my ($et, $dirInfo, $tagTablePtr) = @_;
175 1 my $dataPt = $$dirInfo{DataPt};
176 1 my $pos = 0;
177 1 my $end = length $$dataPt;
178 1 $et->VerboseDir('WTV Metadata', undef, $end);
179 1 ▶ while ($pos + 0x18 < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + 24 < $end) 74 0 74
180 74 ▶ last unless substr($$dataPt,$pos,16) eq "\x5a\xfe\xd7\x6d\xc8\x1d\x8f\x4a\x99\x22\xfa\xb1\x1c\x38\x14\x53";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($$dataPt, $pos, 16) eq "Z\376\327m\310\35\217J\231\"\372\261\0348\24S" 1 73 74
181 73 my $fmt = Get32u($dataPt, $pos + 0x10);
182 73 my $len = Get32u($dataPt, $pos + 0x14);
183 73 my $str = '';
184 73 $pos += 0x18;
185 73 for (;;) {
186 1501 ▶ $pos + 2 > $end and $et->Warn('Corrupt metadata directory'), last;
Branch: 1 branch
BranchTrueFalseTotal
$pos + 2 > $end and $et->Warn("Corrupt metadata directory"), last 0 1501 1501
187 1501 my $ch = substr($$dataPt, $pos, 2);
188 1501 $pos += 2;
189 1501 ▶ last if $ch eq "\0\0";
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "\0\0" 73 1428 1501
190 1428 $str .= $ch;
191 }
192 73 ▶ last if $pos + $len > $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > $end 0 73 73
193 73 my $tag = $et->Decode($str, 'UTF16', undef, 'UTF8');
194 73 my $dat = substr($$dataPt, $pos, $len);
195 # add tag if not already there
196 73 ▶ unless ($$tagTablePtr{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr->{$tag}) 0 73 73
197 0 my $name = $tag;
198 0 $name =~ s{^(WTV_Metadata_)?WM/(WMRV)?}{};
199 0 AddTagToTable($tagTablePtr, $tag, $name);
200 0 $et->VPrint(0, $$et{INDENT}, "[adding WTV:$name]\n");
201 }
202 73 my $val;
203 73 ▶ if ($fmt==0 or $fmt==3) { # int32u or boolean32
Branch: 4 branches
BranchTrueFalseTotal
if ($fmt == 0 or $fmt == 3) { } 40 33 73
elsif ($fmt == 1) { } 23 10 33
elsif ($fmt == 6) { } 2 8 10
elsif ($fmt == 4) { } 8 0 8
Condition100%3/3
$fmt == 0 or $fmt == 3
l!l&&r!l&&!r
231733
MC/DC100%2/2
$fmt == 0 or $fmt == 3
$fmt == 0 $fmt == 3
Truth table100%3/3
A or B
A= $fmt == 0B= $fmt == 3
ABresult
1X1
011
000
204 40 $val = Get32s(\$dat, 0);
205 } elsif ($fmt == 1) { # string
206 23 $val = $et->Decode($dat, 'UTF16');
207 } elsif ($fmt == 6) { # GUID
208 2 $val = unpack('H*', $dat);
209 } elsif ($fmt == 4) { # int64u (date/time values use this)
210 8 $val = Get64u(\$dat, 0);
211 } else {
212 0 $val = $dat;
213 0 $fmt = "Unknown($fmt)";
214 }
215 73 $et->HandleTag($tagTablePtr, $tag, $val,
216 Format => "format $fmt",
217 Size => length $dat,
218 );
219 73 $et->VerboseDump(\$dat);
220 73 $pos += $len;
221 }
222 }
223  
224 #------------------------------------------------------------------------------
225 # Extract information from a WTV video
226 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
227 # Returns: 1 on success, 0 if this wasn't a valid WTV file
228 sub ProcessWTV($$)
229 1 ▶{
Subroutine ProcessWTV: called CC=19 SCAR=33.2
Pod undocumented
230 1 my ($et, $dirInfo) = @_;
231 1 my $raf = $$dirInfo{RAF};
232 1 my $verbose = $et->Options('Verbose');
233 1 my ($buff, $tagTablePtr, $pos, $len);
234  
235 # verify this is a valid WTV file
236 1 ▶ return 0 unless $raf->Read($buff, 0x60) == 0x60;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 96) == 96 0 1 1
237 1 ▶ return 0 unless $buff =~ /^\xb7\xd8\x00\x20\x37\x49\xda\x11\xa6\x4e\x00\x07\xe9\x5e\xad\x8d/;
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /^\xb7\xd8\x00\x20\x37\x49\xda\x11\xa6\x4e\x00\x07\xe9\x5e\xad\x8d/ 0 1 1
238 1 $et->SetFileType();
239 1 SetByteOrder('II');
240 # 0x28 - int32u: sector size? (=0x1000) (PH NC)
241 # 0x38 - int32u: sector number for main WTV directory (PH assume this is a sector table, NC)
242 # 0x58 - int32u: total number of sectors in file
243 1 my $secSize = Get32u(\$buff, 0x28);
244 # in case I'm wrong about this, constrain sector size to
245 # either 0x1000 (standard) or 0x100 (ExifTool test file) - PH
246 1 ▶ $secSize = 0x1000 unless $secSize == 0x1000 or $secSize == 0x100;
Branch: 1 branch
BranchTrueFalseTotal
unless $secSize == 4096 or $secSize == 256 0 1 1
Condition33%1/3
$secSize == 4096 or $secSize == 256
l!l&&r!l&&!r
010
MC/DC0%0/2
$secSize == 4096 or $secSize == 256
$secSize == 4096 $secSize == 256
Truth table33%1/3
A or B
A= $secSize == 4096B= $secSize == 256
ABresult
1X1
011
000
247 1 $buff = ReadSectors($raf, \$buff, 0x38, $secSize); # read the WTV directory
248 1 ▶ return 0 unless defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 0 1 1
249 1 $tagTablePtr = GetTagTable('Image::ExifTool::WTV::Main');
250 # parse the WTV directory
251 1 $et->VerboseDir('WTV');
252 1 ▶ for ($pos=0; $pos<length($buff)-0x28; $pos+=$len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length($buff) - 40) 9 0 9
253 9 ▶ unless (substr($buff,$pos,0x10) eq "\x92\xb7\x74\x91\x59\x70\x70\x44\x88\xdf\x06\x3b\x82\xcc\x21\x3d") {
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($buff, $pos, 16) eq "\222\267t\221YppD\210\337\6;\202\314!=") 1 8 9
254 1 ▶ $et->Warn("WTV directory wasn't at expected location") unless $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless $pos 0 1 1
255 1 last;
256 }
257 8 $len = Get32u(\$buff, $pos+0x10);
258 8 ▶ last if $pos + $len > length($buff);
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > length $buff 0 8 8
259 8 my $n = Get32u(\$buff, $pos + 0x20);
260 8 ▶ 0x28 + $n*2 + 8 > $len and $et->Warn('WTV directory error'), last;
Branch: 1 branch
BranchTrueFalseTotal
40 + $n * 2 + 8 > $len and $et->Warn("WTV directory error"), last 0 8 8
261 8 my $tag = $et->Decode(substr($buff,$pos+0x28,$n*2), 'UTF16', undef, 'UTF8');
262 8 my $ptr = $pos + 0x28 + $n * 2;
263 8 my $flg = Get32u(\$buff, $ptr + 4);
264 8 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 8 8
265 0 my $s = Get32s(\$buff, $ptr);
266 0 ▶ $s = sprintf('0x%x', $s) unless $s < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $s < 0 0 0 0
267 0 $et->VPrint(1,"- Tag '${tag}' (sector=$s, flag=$flg)");
268 }
269 8 ▶ next unless $$tagTablePtr{$tag} and ($flg == 0 or $flg == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $tagTablePtr->{$tag} and $flg == 0 || $flg == 1 7 1 8
Condition50%3/6
$tagTablePtr->{$tag} and $flg == 0 || $flg == 1
!ll&&!rl&&r
701
$flg == 0 or $flg == 1
l!l&&r!l&&!r
010
MC/DC33%1/3
$tagTablePtr->{$tag} and $flg == 0 || $flg == 1
$tagTablePtr->{$tag} $flg == 0 $flg == 1
Truth table50%2/4
A and B or C
A= $tagTablePtr->{$tag}B= $flg == 0C= $flg == 1
ABCresult
0XX0
1000
11X1
1011
270 1 my $sec = substr($buff, $ptr, 4);
271 1 my $data = ReadSectors($raf, \$sec, 0, $secSize);
272 1 ▶ last unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 1 1
273 # read sectors from table if necessary (flag=1 indicates a sector table)
274 1 ▶ $data = ReadSectors($raf, \$data, 0, $secSize) if $flg == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $flg == 1 1 0 1
275 1 ▶ defined $data or $et->Warn("Error fetching data for $tag"), next;
Branch: 1 branch
BranchTrueFalseTotal
defined $data or $et->Warn("Error fetching data for $tag"), next 1 0 1
276 1 $et->HandleTag($tagTablePtr, $tag, $data);
277 }
278 1 return 1;
279 }
280  
281 1 1; # end
282  
283 __END__
« Image/ExifTool/JPEGDigest.pm ↑ Summary Image/ExifTool/Minolta.pm »