6 # Created by Pierre Andrews on 01/07/2007.
7 # Copyright 2007 Pierre Andrews. All rights reserved.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # add our 'lib' directory to the include list BEFORE 'use Image::ExifTool'
26 $exeDir = ($0 =~ /(.*)[\\\/]/) ?
$1 : '.';
27 # add lib directory at start of include path
28 unshift @INC, "$exeDir/lib";
36 #my $homedir=`ksh -c "(cd ~ 2>/dev/null && /bin/pwd)"`;
38 $homedir = $ENV{'HOME'};
40 my $exifTool = new Image
::ExifTool
;
41 my $pattern = $ENV{'pathPattern'};
43 $pattern = "%Y_%m_%d/";
45 $exifTool->Options(DateFormat
=> $pattern);
57 ($name,$dir,$suffix) = fileparse
($file,qr/\.[^.]*$/);
58 my $destPath = $ENV{'directoryPath'};
59 if(!$destPath) { $destPath = $dir; }
60 my $info = $exifTool->ImageInfo($file, 'DateTimeOriginal');
61 my $path = $$info{'DateTimeOriginal'};
63 $info = $exifTool->ImageInfo($file, 'FileModifyDate');
64 $path = $$info{'FileModifyDate'};
66 if(!$path && $pattern !~ /%[A-Za-z]/) {
70 while($path =~ /:([a-zA-Z]+):/g) {
72 if($label =~ /basename/i) {
74 $path =~ s/:basename:/$name/g;
75 } elsif($label =~ /ext/i) {
76 $path =~ s/:ext:/$suffix/g;
78 my $info = $exifTool->ImageInfo($_, "$label");
79 if($$info{"$label"}) {
80 my $value = $$info{"$label"};
86 $path =~ s/:$label:/$value/g;
88 $path =~ s/:$label://g;
92 $path =~ s/[^A-Za-z0-9_\/.\-~]/_
/g
;
93 $path = $destPath.'/'.$path;
94 $path =~ s/^~/$homedir/;
96 ($new_name,$new_dir,$new_suffix) = fileparse
($path,qr/\.[^.]*$/);
97 if($new_name && !$with_basename) {
98 $path = $new_dir.'/'.$new_name.$new_suffix;
101 $path .= $name.$suffix;
103 $new_suffix = $suffix;
105 if(!$new_suffix || $new_suffix!=$suffix) {
110 if(!$ENV{'test'}) { mkpath
($new_dir); }
111 if(!$ENV{'overwrite'}) {
113 if($path !~ /:cnt:/i) {
114 $path =~ s/(\.[^.]*)$/_:cnt:$1/;
118 $new_path =~ s/:cnt:/$local_cnt/g;
119 while(-e
$new_path) {
122 $new_path =~ s/:cnt:/$local_cnt/g;
127 $path =~ s/_:cnt://g;
133 if($ENV{'action'} == 1) {