| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Image::Nikon::Index; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use 5.018002; |
|
4
|
1
|
|
|
1
|
|
20113
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
2184
|
use Image::ExifTool; |
|
|
1
|
|
|
|
|
70107
|
|
|
|
1
|
|
|
|
|
1318
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(); |
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# methods |
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
1
|
|
|
1
|
0
|
12
|
my $class = shift; |
|
14
|
1
|
|
|
|
|
2
|
my %args = @_; |
|
15
|
|
|
|
|
|
|
my $self = { |
|
16
|
|
|
|
|
|
|
folder => ".", # present working directory |
|
17
|
|
|
|
|
|
|
prefix => $args{'prefix'} || undef, |
|
18
|
|
|
|
|
|
|
suffix => $args{'suffix'} || undef, |
|
19
|
|
|
|
|
|
|
exif => Image::ExifTool->new, |
|
20
|
|
|
|
|
|
|
tags => [ 'SubSecDateTimeOriginal', 'ModifyDate' ], |
|
21
|
|
|
|
|
|
|
tree => undef, |
|
22
|
|
|
|
|
|
|
# tree => { |
|
23
|
|
|
|
|
|
|
# date => { |
|
24
|
|
|
|
|
|
|
# key => { |
|
25
|
|
|
|
|
|
|
# name=>'original name', |
|
26
|
|
|
|
|
|
|
# code=>'new date code', |
|
27
|
|
|
|
|
|
|
# index=>'sequence number', |
|
28
|
|
|
|
|
|
|
# }, |
|
29
|
|
|
|
|
|
|
# }, |
|
30
|
|
|
|
|
|
|
# } |
|
31
|
|
|
|
|
|
|
files => undef, |
|
32
|
|
|
|
|
|
|
inityear=> $args{'initialyear'} || 2011, |
|
33
|
1
|
|
50
|
|
|
19
|
debug => $args{'debug'} || 1, |
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
|
|
|
|
|
|
}; |
|
35
|
1
|
|
|
|
|
34716
|
bless $self, $class; |
|
36
|
1
|
|
|
|
|
6
|
return $self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# list directory and populate files |
|
40
|
|
|
|
|
|
|
sub _list { |
|
41
|
1
|
|
|
1
|
|
3
|
my ($self)=(@_); |
|
42
|
1
|
|
|
|
|
2
|
my @files; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# always open current directory |
|
45
|
1
|
|
50
|
|
|
77
|
opendir DIR, $self->{'folder'} || die "$!\n"; |
|
46
|
1
|
|
|
|
|
74
|
@files = readdir DIR; |
|
47
|
1
|
|
|
|
|
19
|
closedir DIR; |
|
48
|
1
|
|
|
|
|
5
|
chomp @files; |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
@files = grep { !/^\.+/ } @files; # ignore hidden files, starting with dot |
|
|
15
|
|
|
|
|
37
|
|
|
51
|
1
|
50
|
|
|
|
5
|
@files = grep { /^$self->{'prefix'}/ } @files if defined $self->{'prefix'}; # match prefix |
|
|
0
|
|
|
|
|
0
|
|
|
52
|
1
|
50
|
|
|
|
5
|
@files = grep { /$self->{'suffix'}$/ } @files if defined $self->{'suffix'}; # match extension |
|
|
0
|
|
|
|
|
0
|
|
|
53
|
1
|
|
|
|
|
8
|
$self->{'files'} = \@files; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# extract file name and process |
|
57
|
|
|
|
|
|
|
sub _file { |
|
58
|
13
|
|
|
13
|
|
36
|
my ($self, %opts)=(@_); |
|
59
|
13
|
|
|
|
|
16
|
my %dummy; |
|
60
|
13
|
|
|
|
|
19
|
my $f = $opts{'file'}; |
|
61
|
13
|
|
|
|
|
24
|
my $t = $self->{'exif'}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
13
|
50
|
|
|
|
270
|
$t->ExtractInfo ( $f, \%dummy ) || return; # if not an image, skip. |
|
64
|
|
|
|
|
|
|
#my $value = $t->GetValue('SubSecDateTimeOriginal', 1) || return; # if not an image, skip. |
|
65
|
0
|
|
0
|
|
|
0
|
my $value = $t->GetValue($self->{'tags'}->[0], 1) || return; # if not an image, skip. |
|
66
|
0
|
|
|
|
|
0
|
my ($date, $time) = split /\s+/, $value, 2 || die $!; |
|
67
|
0
|
|
|
|
|
0
|
my $datestr = $self->_date ($date); |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
$date =~ s/\://g; |
|
70
|
0
|
|
|
|
|
0
|
$time =~ s/\:|\.//g; |
|
71
|
0
|
|
|
|
|
0
|
$time = $date.$time; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my ($updated) = $t->GetValue($self->{'tags'}->[1], 1); |
|
74
|
0
|
|
|
|
|
0
|
$updated =~ s/\:|\s+//g; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
$f =~ s/\_//g; |
|
77
|
0
|
|
|
|
|
0
|
$f =~ s/\./\_/g; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
$self->{'tree'}->{$date}->{$time.$updated.$f}->{'name'} = $opts{'file'}; |
|
80
|
0
|
|
|
|
|
0
|
$self->{'tree'}->{$date}->{$time.$updated.$f}->{'code'} = $datestr; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# changing date format |
|
84
|
|
|
|
|
|
|
sub _date { |
|
85
|
0
|
|
|
0
|
|
0
|
my ($self, $datestr) = (@_); |
|
86
|
0
|
|
|
|
|
0
|
my ($y, $m, $d) = split /:/, $datestr; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$datestr =~ s/^\s+|\s+$//g; |
|
89
|
0
|
|
|
|
|
0
|
($y, $m, $d) = split /:/, $datestr; |
|
90
|
0
|
|
|
|
|
0
|
$y = chr ( $y - $self->{'inityear'} + ord('A') ); |
|
91
|
0
|
|
|
|
|
0
|
$datestr = sprintf "%s%1X%02d", $y, $m, $d; |
|
92
|
0
|
|
|
|
|
0
|
return $datestr; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# indexing |
|
96
|
|
|
|
|
|
|
sub _index { |
|
97
|
0
|
|
|
0
|
|
0
|
my ($self, %opts) = (@_); |
|
98
|
0
|
|
|
|
|
0
|
my $hash = $opts{'hash'}; |
|
99
|
0
|
|
|
|
|
0
|
my $i = 1; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
foreach my $key ( sort keys %{$hash} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
102
|
0
|
|
|
|
|
0
|
$hash->{$key}->{'index'} = sprintf "%03d", $i; |
|
103
|
0
|
|
|
|
|
0
|
$i++; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# file extension |
|
108
|
|
|
|
|
|
|
sub _ext { |
|
109
|
0
|
|
|
0
|
|
0
|
my ($self, $name) = (@_); |
|
110
|
0
|
|
|
|
|
0
|
my ($junk, $x) = split /\./, $name; |
|
111
|
0
|
|
|
|
|
0
|
return $x; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# print all files - key, oldname, newname |
|
115
|
|
|
|
|
|
|
sub print { |
|
116
|
0
|
|
|
0
|
0
|
0
|
my ($self) = (@_); |
|
117
|
0
|
|
|
|
|
0
|
my $hash; |
|
118
|
|
|
|
|
|
|
my $newname; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
foreach my $date ( keys %{$self->{'tree'}} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
121
|
0
|
0
|
|
|
|
0
|
print "__".$date."__\n" if $self->{'debug'}; |
|
122
|
0
|
|
|
|
|
0
|
$hash = $self->{'tree'}->{$date}; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
foreach my $key ( sort keys %{$hash} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
125
|
0
|
|
|
|
|
0
|
$newname = $hash->{$key}->{'code'}."_".$hash->{$key}->{'index'}.".".$self->_ext($hash->{$key}->{'name'}); |
|
126
|
0
|
|
|
|
|
0
|
print sprintf " %-45s %-15s %-15s\n", $key, $hash->{$key}->{'name'}, " ".$newname; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# rename of each file |
|
132
|
|
|
|
|
|
|
sub _rename { |
|
133
|
0
|
|
|
0
|
|
0
|
my ($self, %opts) =(@_); |
|
134
|
0
|
|
|
|
|
0
|
rename ($opts{'oldname'}, $opts{'newname'}); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# mass rename |
|
138
|
|
|
|
|
|
|
sub transform { |
|
139
|
0
|
|
|
0
|
0
|
0
|
my ($self) =(@_); |
|
140
|
0
|
|
|
|
|
0
|
my $hash; |
|
141
|
|
|
|
|
|
|
my $newname; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
foreach my $date ( keys %{$self->{'tree'}} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
144
|
0
|
|
|
|
|
0
|
$hash = $self->{'tree'}->{$date}; |
|
145
|
0
|
|
|
|
|
0
|
foreach my $key ( sort keys %{$hash} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
146
|
0
|
|
|
|
|
0
|
$newname = $hash->{$key}->{'code'}."_".$hash->{$key}->{'index'}.".".$self->_ext($hash->{$key}->{'name'}); |
|
147
|
0
|
0
|
|
|
|
0
|
print $hash->{$key}->{'name'}." ".$newname."\n" if $self->{'debug'}; |
|
148
|
0
|
|
|
|
|
0
|
$self->_rename ( oldname=>$hash->{$key}->{'name'}, newname=>$newname ); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub process { |
|
154
|
1
|
|
|
1
|
0
|
7
|
my ($self) = (@_); |
|
155
|
1
|
|
|
|
|
6
|
my $list = $self->_list; |
|
156
|
1
|
|
|
|
|
2
|
my $hash; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# create node for each file |
|
159
|
1
|
|
|
|
|
3
|
foreach my $f ( @{$list} ) { |
|
|
1
|
|
|
|
|
3
|
|
|
160
|
13
|
|
|
|
|
82084
|
$self->_file (file=>$f); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# do indexing for each available date |
|
164
|
1
|
|
|
|
|
4000
|
foreach my $date ( keys %{$self->{'tree'}} ) { |
|
|
1
|
|
|
|
|
6
|
|
|
165
|
0
|
|
|
|
|
0
|
$hash = $self->{'tree'}->{$date}; |
|
166
|
0
|
|
|
|
|
0
|
$self->_index (hash=>$hash); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
1
|
|
|
|
|
4
|
return $self; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
|
173
|
|
|
|
|
|
|
__END__ |