line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Media::DateTime::JPEG; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A plugin for the C module to support JPEG files |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
3651
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
82
|
|
6
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
127
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.49'; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
13
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
225
|
|
11
|
3
|
|
|
3
|
|
4114
|
use Image::ExifTool; |
|
3
|
|
|
|
|
116074
|
|
|
3
|
|
|
|
|
329
|
|
12
|
3
|
|
|
3
|
|
28
|
use DateTime; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
97
|
|
13
|
3
|
|
|
3
|
|
17
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
276
|
|
14
|
3
|
|
|
3
|
|
15
|
use Try::Tiny; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1160
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $exifTool; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub datetime { |
19
|
8
|
|
|
8
|
1
|
10
|
my ( $self, $f ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
8
|
100
|
|
|
|
37
|
$exifTool = Image::ExifTool->new() unless $exifTool; |
22
|
8
|
100
|
|
|
|
49321
|
$exifTool->ExtractInfo($f) or do { |
23
|
2
|
|
|
|
|
63530
|
warn "Exiftool unable to read: $f\nFallback to file timestamp.\n"; |
24
|
2
|
|
|
|
|
15
|
return; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $datetime = $exifTool->GetValue('DateTimeOriginal') |
28
|
6
|
100
|
|
|
|
125466
|
or do { |
29
|
2
|
|
|
|
|
158
|
warn "JPEG does not contain DateTimeOriginal exif entry ($f),\n" |
30
|
|
|
|
|
|
|
. "Fallback to file timestamp.\n"; |
31
|
2
|
|
|
|
|
11
|
return; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# DateTime format = yyyy:mm:dd hh:mm:ss |
35
|
|
|
|
|
|
|
my ( $y, $m, $d, $h, $min, $s ) = $datetime =~ m/ |
36
|
|
|
|
|
|
|
(\d{4}) : # year |
37
|
|
|
|
|
|
|
(\d{2}) : # month |
38
|
|
|
|
|
|
|
(\d{2}) # day |
39
|
|
|
|
|
|
|
\s # space |
40
|
|
|
|
|
|
|
(\d{2}) : # hour |
41
|
|
|
|
|
|
|
(\d{2}) : # min |
42
|
|
|
|
|
|
|
(\d{2}) # sec |
43
|
|
|
|
|
|
|
/x |
44
|
4
|
50
|
|
|
|
520
|
or do { |
45
|
0
|
|
|
|
|
0
|
warn "failed DateTime pattern match in $f\n" |
46
|
|
|
|
|
|
|
. "Fallback to file timestamp"; |
47
|
0
|
|
|
|
|
0
|
return; |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $date = try { |
51
|
4
|
|
|
4
|
|
210
|
DateTime->new( |
52
|
|
|
|
|
|
|
year => $y, |
53
|
|
|
|
|
|
|
month => $m, |
54
|
|
|
|
|
|
|
day => $d, |
55
|
|
|
|
|
|
|
hour => $h, |
56
|
|
|
|
|
|
|
minute => $min, |
57
|
|
|
|
|
|
|
second => $s, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
catch { |
61
|
2
|
50
|
33
|
2
|
|
1338
|
if ((blessed $_ && $_->isa('Specio::Exception')) || /to DateTime::new did not pass/) { |
|
|
|
33
|
|
|
|
|
62
|
2
|
|
|
|
|
228
|
warn |
63
|
|
|
|
|
|
|
"JPEG's DateTimeOriginal exif entry ($f) not a valid datetime.\n" |
64
|
|
|
|
|
|
|
. "Fallback to file timestamp.\n"; |
65
|
2
|
|
|
|
|
16
|
return undef; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
0
|
die; |
68
|
|
|
|
|
|
|
} |
69
|
4
|
|
|
|
|
65
|
}; |
70
|
|
|
|
|
|
|
|
71
|
4
|
|
|
|
|
1238
|
return $date; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub match { |
75
|
10
|
|
|
10
|
1
|
16
|
my ( $self, $f ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
10
|
|
|
|
|
75
|
return $f =~ /\.jpe?g$/i; ## no critic |
78
|
|
|
|
|
|
|
# TODO: should we use something more complicated here? maybe mime type? |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |