diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | README | 9 | ||||
-rwxr-xr-x | renrot | 75 |
3 files changed, 77 insertions, 14 deletions
@@ -1,10 +1,15 @@ $Log$ +Revision 1.57 2006/05/03 21:59:52 zeus +file aggregation via option --aggr-template has been implemented. +control code for file name originality has been moved from template2name() to main(). +README edited + Revision 1.56 2006/05/02 19:08:59 zeus item about aggregation is added to TODO. -minor language ixes in README +minor language ixes in README. Revision 1.55 2006/05/02 09:07:02 andy Wrote RESTRICTIONS section in README. Revision 1.54 2006/05/01 10:22:08 andy Bugfix release 0.16.1. @@ -5,13 +5,13 @@ according to their EXIF tags. For prevent incorrect associations some explanations are needed here. The name of project is short form of 'REName and ROTate' and no other interpretation will be used. Renrot is intended to work only in current directory with all files of the -extension, specified after --ext. You can change the behaviour by specify +extension, specified after --ext. You can change the behaviour by specifying --work-directory option. New template ideology was implemented. It includes flexibility in file name construction. In version 0.16 and later the previous behaviour still present with default NameTemplate. The template can contain different data, from direct name to EXIF data (the date, id or shooting details such as @@ -25,12 +25,14 @@ well as it's thumbnail "by hands". Furthermore, the script can put a comment to: - Comment tag if comment file provided with --comment-file option - UserComment tag if $COMMENTARY variable set in configuration file Personal data could be specified via XMP tags defined in configuration file. +In addition renrot can aggregate all files in directories according the given +date/time pattern template, set with --aggr-template. WHY RenRot? Several projects like RenRot are available in the net, but why to choose namely RenRot? Because: - it does just what it would do - renames and rotates, nothing more than @@ -38,12 +40,13 @@ namely RenRot? Because: - it is pure CLI with all it's advantage (no need KDE or any other monster to run); - it uses Image::ExifTool (the best open tool to work with EXIF data) and libjpeg6 (the best open tool to operate JPEG format files, to correctly rotate both, the very file and the thumbnail inside it); - it has very much flex file naming template engine; + - it has very much flex file aggregation template engine; - it works in batch mode. GETTING RenRot home page is an ftp site for now. You can download script package from @@ -58,12 +61,16 @@ RUNNING After installation process was done renrot is being running by typing its name in console as usual. The next several examples provide general applications of the script: rename each file according to the given template renrot --name-template="01.%c.%Y%m%d%H%M%S.%i.%E%F%W%I" --ext JPG + rename each file according to the given template and files aggregation + according the date + renrot --name-template="%y%m%d%H%M%S.%i" --aggr-template "%Y%m%d" --ext JPG + rotate each file and their thumbnail by 90CW in specified directory renrot --rotate 90 --ext '*.jpg' --work-directory="/tmp/images" rotate thumbnails, included to EXIF, for each file by 90CCW renrot --rotate-thumb 270 --ext jpg @@ -16,12 +16,13 @@ our $VERSION = "0.16.1"; # the version of this script my $noRotation; # no rotation needed, default is to rotate my $rotate; # define the angle, to rotate on, 90 or 270 my $rotateThumbnail; # define the angle, to rotate on, 90 or 270 my $noRename; # no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg my $noComment; # no comment needed my $nameTemplate; # template for the filename taken from CLI +my $aggrTemplate; # template for the files aggregation taken from CLI my $extentionToProcess; # the extention of files to work with my $extentionToProcessLowCase; # lowercased extention of files to work with my $usageOutput = 0; # flag to show the usage my $configFile; # config file my $comfile; # file with commentary my $verbose = 0; # verbosity of output @@ -68,12 +69,13 @@ sub getopt { "rotate|r=i" => \$rotate, "rotate-thumb=i" => \$rotateThumbnail, "no-rotate" => \$noRotation, "no-rename" => \$noRename, "comment-file=s" => \$comfile, "name-template=s" => \$nameTemplate, + "aggr-template=s" => \$aggrTemplate, "mtime" => \$mtime, "config-file|c=s" => \$configFile, "v+" => \$verbose, "version" => \$ver, "help|?" => \$help); @@ -244,21 +246,29 @@ foreach $file ( @files ) { ################################################################################# # ## analyzing whether and how to rename file # if ( defined $noRename ) { infomsg ("No renaming asked, filename is left untouched.\n"); - $newfilename = $file; + if ( ($newfilename) = ( $file =~ /^(.*)\.jpg/ ) ) { + $filenameshash{$newfilename} = 1; + } } else { - $newfilename = sprintf("%s.%s", template2name($NameTemplate), $extentionToProcessLowCase); + $newfilename = template2name($NameTemplate); + if ( $filenameshash{$newfilename} ) { + $newfilename = sprintf("%s.%.4d",$newfilename,$filecounter); + } + $filenameshash{$newfilename} = 1; + + $newfilename = sprintf("%s.%s", $newfilename, $extentionToProcessLowCase); if ( $file ne $newfilename ) { if ( -f $newfilename ) { - fatalmsg ("File $newfilename already exists!\n"), die - }; + fatalmsg ("File $newfilename already exists!\n"), die; + } rename ( $file, $newfilename ) || ( fatalmsg ("Unable to rename $file -> $newfilename.\n"), die ); print "Renamed: $file -> $newfilename\n"; } else { warnmsg ("No renaming needed for $newfilename, it looks as needed!\n"); } } @@ -339,12 +349,33 @@ foreach $file ( @files ) { print "\n"; $filecounter++; } closedir(DIR); +######################################################################################## +# +# file aggregation if requested +# +if ( defined $aggrTemplate ) { + infomsg ("NOW IS FILE AGGREGATION\n=======================\n\n"); + $filecounter=1; + foreach $file ( sort ( keys %filenameshash ) ) { + $file .= ".jpg"; + $info = $exifTool->ImageInfo($file); + $newfilename = template2name($aggrTemplate); + if ( not -d $newfilename ) { + unless ( mkdir $newfilename ) { errmsg ("$newfilename wasn't created!\n"); } + } + infomsg ( "$file has been aggregated to the directory $newfilename\n" ); + $newfilename .= "/" . $file; + rename ( $file, $newfilename ) || ( fatalmsg ("$file -> $newfilename\n"), die ); + $filecounter++; + } +} + exit 0; ######################################################################################## # # timeNow() returns timestamp in form YYYYmmddHHMMSS # @@ -401,13 +432,13 @@ sub getTimestamp { $timestamp = $info->{"FileModifyDate"}; } else { $timestamp = timeNow(); warnmsg ("EXIF timestamp isn't correct, using timeNow()!\n"); } - + return $timestamp; } ######################################################################################## # # getUnixTime() converts timestamp to unix time form @@ -550,12 +581,13 @@ infomsg ( 90 or 270. it's for the files where no Orientation tag is present and set right way --rotate-thumb <90|270> rotate thumbnail ONLY. 90 or 270 degree it's for the files which were rotated, but thumbnail wasn't --no-rename no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg --name-template <TPL> filename template (see manual for details) + --aggr-template <TPL> aggregation template (see manual for details) --mtime to set file mtime according DateTimeOriginal tag value --comment-file <FILE> file with commentary --version the version of this script "); } @@ -634,18 +666,12 @@ sub template2name { $thename .= $templatehash{$substrchar}; } } else { $thename .= $substrchar; } } - if ( $filenameshash{$thename} ) { - $thename = sprintf("%s.%s",$thename,$templatehash{"c"}); - } - - $filenameshash{$thename} = 1; - return $thename; } __END__ =head1 NAME @@ -656,13 +682,13 @@ renrot - rename and rotate images according EXIF data renrot [OPTIONS] =head1 DESCRIPTION B<RenRot> is intended to work ONLY in current directory. You can change the -behaviour by specify B<--work-directory> option. +behaviour by specifying B<--work-directory> option. Renrot renames files according the DateTimeOriginal and FileModifyDate EXIF tags, if they exist. Otherwise, the name will be set according to the current time stamp and will look as YYYYmmddHHMMSS.XXXX.jpg, where XXXX is whether file ID, if exists in EXIF (as for Canon) or incremental suffix to the name YYYYmmddHHMMSS. @@ -681,12 +707,15 @@ The script can also put commentary into: =back Personal details can be specified via XMP tags defined in a configuration file, look L<CONFIG> section. +In addition renrot can aggregate all files in directories according the given +date/time pattern template, set with B<--aggr-template>. + =head1 OPTIONS =over =item B<-h> or B<--help> @@ -777,12 +806,34 @@ B<%W> WhiteBalance tag value if defined, otherwise W B<%Y> year (1900, 1901, and so on) B<%y> last two digits of year (00..99) =back +=item B<--aggr-template> I<Aggregation TEMPLATE> + +template, which is used for file aggregation. Aggragation fulfils according date/time patterns. + +=over + +B<%d> day of the month (01-31) + +B<%H> hour (00-23) + +B<%M> minute (00-59) + +B<%m> month (01-12) + +B<%S> second (00-59) + +B<%Y> year (1900, 1901, and so on) + +B<%y> last two digits of year (00..99) + +=back + =back =head1 B<EXAMPLES> The template C<01.%c.%Y%m%d%H%M%S.%i.%E%F%W%I> may produces following names: |