File: QuickTime.t

package info (click to toggle)
libimage-exiftool-perl 13.25%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,600 kB
  • sloc: perl: 297,808; xml: 123; makefile: 22; sh: 15
file content (339 lines) | stat: -rw-r--r-- 11,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/QuickTime.t".

BEGIN {
    $| = 1; print "1..22\n"; $Image::ExifTool::configFile = '';
    require './t/TestLib.pm'; t::TestLib->import();
}
END {print "not ok 1\n" unless $loaded;}

# test 1: Load the module(s)
use Image::ExifTool 'ImageInfo';
use Image::ExifTool::QuickTime;
$loaded = 1;
print "ok 1\n";

my $testname = 'QuickTime';
my $testnum = 1;

# tests 2-3: Extract information from QuickTime.mov and QuickTime.m4a
{
    my $ext;
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        my $exifTool = Image::ExifTool->new;
        my $info = $exifTool->ImageInfo("t/images/QuickTime.$ext");
        notOK() unless check($exifTool, $info, $testname, $testnum);
        print "ok $testnum\n";
    }
}

# tests 4-5: Try writing XMP to the different file formats
{
    my $ext;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(SavePath => 1); # to save group 5 names
    $exifTool->SetNewValue('XMP:Title' => 'x');
    $exifTool->SetNewValue('TrackCreateDate' => '2000:01:02 03:04:05');
    $exifTool->SetNewValue('Track1:TrackModifyDate' => '2013:11:04 10:32:15');
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        unless (eval { require Time::Local }) {
            print "ok $testnum # skip Requires Time::Local\n";
            next;
        }
        my $testfile = "t/${testname}_${testnum}_failed.$ext";
        unlink $testfile;
        my $rtnVal = $exifTool->WriteInfo("t/images/QuickTime.$ext", $testfile);
        my $info = $exifTool->ImageInfo($testfile, 'title', 'time:all');
        if (check($exifTool, $info, $testname, $testnum, undef, 5)) {
            unlink $testfile;
        } else {
            notOK();
        }
        print "ok $testnum\n";
    }
}

# test 6: Write video rotation
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->SetNewValue('Rotation' => '270', Protected => 1);
    my $testfile = "t/${testname}_${testnum}_failed.mov";
    unlink $testfile;
    my $rtnVal = $exifTool->WriteInfo('t/images/QuickTime.mov', $testfile);
    my $info = $exifTool->ImageInfo($testfile, 'Rotation', 'MatrixStructure');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 7: Add a bunch of new tags and delete one
{
    ++$testnum;
    my @writeInfo = (
        ['QuickTime:Artist' => 'me'],
        ['QuickTime:Model' => 'model'],
        ['UserData:Genre' => 'rock'],
        ['UserData:Album' => 'albumA'],
        ['ItemList:Album' => 'albumB'],
        ['ItemList:ID-albm:Album' => 'albumC'],
        ['QuickTime:Comment-fra-FR' => 'fr comment'],
        ['Keys:Director' => 'director'],
        ['Keys:CameraDirection' => '90'],
        ['Keys:Album' => undef ],
    );
    my @extract = ('ItemList:all', 'UserData:all', 'Keys:all');
    notOK() unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/QuickTime.mov', \@extract);
    print "ok $testnum\n";
}

# test 8-9: Delete everything then add back some tags in one step
{
    my $ext;
    my $exifTool = Image::ExifTool->new;
    my @writeInfo = (
        ['all' => undef],
        ['artist' => 'me'],
        ['keys:director' => 'dir'],
        ['userdata:arranger' => 'arr'],
    );
    my @extract = ('QuickTime:all', 'XMP:all');
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        notOK() unless writeCheck(\@writeInfo, $testname, $testnum, "t/images/QuickTime.$ext", \@extract);
        print "ok $testnum\n";
    }
}

# test 10: Delete everything then add back some tags in two steps
{
    ++$testnum;
    my $testfile = "t/${testname}_${testnum}a_failed.mov";
    unlink $testfile;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(QuickTimeHandler => 1);
    $exifTool->SetNewValue('all' => undef);
    writeInfo($exifTool, 't/images/QuickTime.mov', $testfile);
    my @writeInfo = (
        ['quicktime:artist' => 'me'],
        ['keys:director' => 'dir'],
        ['userdata:arranger' => 'arr'],
    );
    my @extract = ('QuickTime:all', 'XMP:all', '-Track1:all', '-Track2:all');
    notOK() unless writeCheck(\@writeInfo, $testname, $testnum, $testfile, \@extract);
    print "ok $testnum\n";
}

# tests 11-13: HEIC write tests
{
    ++$testnum;
    my $testfile = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(Composite => 0);
    $exifTool->SetNewValue('XMP-dc:Title' => 'a title');
    writeInfo($exifTool, 't/images/QuickTime.heic', $testfile);
    my $info = $exifTool->ImageInfo($testfile, '-file:all');
    unless (check($exifTool, $info, $testname, $testnum)) {
        notOK();
    }
    print "ok $testnum\n";

    ++$testnum;
    my $testfile2 = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile2;
    $exifTool->SetNewValue();
    $exifTool->SetNewValue('XMP:all' => undef);
    $exifTool->SetNewValue('EXIF:Artist' => 'an artist');
    writeInfo($exifTool, $testfile, $testfile2);
    $info = $exifTool->ImageInfo($testfile2, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";

    ++$testnum;
    $testfile = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile;
    $exifTool->SetNewValue();
    $exifTool->SetNewValue('EXIF:all' => undef);
    $exifTool->SetNewValue('EXIF:UserComment' => 'a comment');
    $exifTool->SetNewValue('XMP:Subject' => 'a subject');
    $exifTool->SetNewValue('XMP:Subject' => 'another subject');
    writeInfo($exifTool, $testfile2, $testfile);
    $info = $exifTool->ImageInfo($testfile, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
        unlink $testfile2;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 14: Delete everything then add back a tag without specifying the group
{
    ++$testnum;
    my $testfile = "t/${testname}_10a_failed.mov";  # use source file from test 10
    my @writeInfo = ( ['publisher' => 'pub'] );
    my @extract = ('QuickTime:all', 'XMP:all', '-Track1:all', '-Track2:all');
    if (writeCheck(\@writeInfo, $testname, $testnum, $testfile, \@extract)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 15: Test WriteMode option with QuickTime tags
{
    ++$testnum;
    my $exifTool = Image::ExifTool->new;
    $exifTool->Options(WriteMode => 'c');
    $exifTool->SetNewValue('ItemList:Composer' => 'WRONG');
    $exifTool->SetNewValue('ItemList:Author' => 'aut');
    $exifTool->SetNewValue('Keys:Artist' => 'WRONG');
    $exifTool->SetNewValue('UserData:Artist' => 'art');
    my $testfile = "t/${testname}_${testnum}_failed.m4a";
    unlink $testfile;
    my $rtnVal = $exifTool->WriteInfo('t/images/QuickTime.m4a', $testfile);
    my $info = $exifTool->ImageInfo($testfile, 'ItemList:all', 'Keys:all', 'UserData:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 16: Write some Microsoft Xtra tags
{
    ++$testnum;
    my @writeInfo = (
        ['Microsoft:Director' => 'dir1'],
        ['Microsoft:Director' => 'dir2'],
        ['Microsoft:SharedUserRating' => 75],
    );
    my @extract = ('Microsoft:all');
    notOK() unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/QuickTime.mov', \@extract);
    print "ok $testnum\n";
}

# test 17: Write some 3gp tags
{
    ++$testnum;
    my @writeInfo = (
        ['UserData:LocationInformation' => 'test comment role=Shooting lat=1.2 lon=-2.3 alt=100 body=earth notes=a note'],
        ['UserData:Rating' => 'entity=ABCD criteria=1234 a rating'],
    );
    notOK() unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/QuickTime.mov', 1);
    print "ok $testnum\n";
}

# test 18-20: Write to audio and video tracks, clear the data and write again
{
    ++$testnum;
    my @writeInfo = (
        ['VideoKeys:LensModel' => 'test lens'],
        ['AudioKeys:Treble' => '50'],
    );
    my @writeMore = (
        ['Keys:Title' => 'Keys'],
        ['ItemList:Title' => 'ItemList'],
        ['UserData:Title' => 'UserData'],
    );
    my @tags = (qw(keys:all audiokeys:all videokeys:all itemlist:all userdata:all));
    my $testfile = "t/${testname}_${testnum}_failed.mov";
    my $exifTool = Image::ExifTool->new;
    $exifTool->SetNewValue(@$_) foreach @writeInfo;
    unlink $testfile;
    my $ok = writeInfo($exifTool, 't/images/QuickTime.mov', $testfile);
    if ($ok) {
        my $info = $exifTool->ImageInfo($testfile,{Duplicates=>1,Unknown=>1},@tags);
        $ok = check($exifTool, $info, $testname, $testnum);
    }
    notOK() unless $ok;
    print "ok $testnum\n";

    ++$testnum;
    my $testfile2 = "t/${testname}_${testnum}_failed.mov";
    $exifTool->SetNewValue();
    $exifTool->SetNewValue(all => undef);   # delete all
    unlink $testfile2;
    $ok = writeInfo($exifTool, $testfile, $testfile2);
    if ($ok) {
        my $info = $exifTool->ImageInfo($testfile2,{Duplicates=>1,Unknown=>1},@tags);
        $ok = check($exifTool, $info, $testname, $testnum);
    }
    if ($ok) {
        unlink $testfile;
    } else {
        notOK();
    }
    print "ok $testnum\n";

    ++$testnum;
    my $testfile3 = "t/${testname}_${testnum}_failed.mov";
    $exifTool->SetNewValue();
    $exifTool->SetNewValue(@$_) foreach @writeInfo, @writeMore;
    unlink $testfile3;
    $ok = writeInfo($exifTool, $testfile2, $testfile3);
    if ($ok) {
        my $info = $exifTool->ImageInfo($testfile3,{Duplicates=>1,Unknown=>1},@tags);
        $ok = check($exifTool, $info, $testname, $testnum);
    }
    if ($ok) {
        unlink $testfile2;
        unlink $testfile3;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

# test 21-22: Write and delete alternate language tags
{
    ++$testnum;
    my $testfile = "t/${testname}_${testnum}_failed.mov";
    my $exifTool = Image::ExifTool->new;
    $exifTool->SetNewValue('Keys:Title-eng-ca' => 'test');
    $exifTool->SetNewValue('ItemList:all' => undef);
    $exifTool->SetNewValue('ItemList:Title-eng-ca' => 'test');
    $exifTool->SetNewValue('ItemList:Title' => 'test');
    unlink $testfile;
    my $ok = writeInfo($exifTool, 't/images/QuickTime.mov', $testfile);
    if ($ok) {
        my $info = $exifTool->ImageInfo($testfile,{Duplicates=>1,Unknown=>1},'Keys:all','ItemList:all');
        $ok = check($exifTool, $info, $testname, $testnum);
    }
    notOK() unless $ok;
    print "ok $testnum\n";

    ++$testnum;
    my $testfile2 = "t/${testname}_${testnum}_failed.mov";
    $exifTool->SetNewValue();
    $exifTool->SetNewValue('Keys:Title-eng-ca' => undef);
    $exifTool->SetNewValue('ItemList:Title-eng-ca' => undef);
    unlink $testfile2;
    $ok = writeInfo($exifTool, $testfile, $testfile2);
    if ($ok) {
        my $info = $exifTool->ImageInfo($testfile2,{Duplicates=>1,Unknown=>1},'Keys:all','ItemList:all');
        $ok = check($exifTool, $info, $testname, $testnum);
    }
    if ($ok) {
        unlink $testfile;
        unlink $testfile2;
    } else {
        notOK();
    }
    print "ok $testnum\n";
}

done(); # end