diff options
author | Andy Shevchenko <andy@smile.org.ua> | 2006-08-19 06:27:25 +0000 |
---|---|---|
committer | Andy Shevchenko <andy@smile.org.ua> | 2006-08-19 06:27:25 +0000 |
commit | 97daff9a3404219369d46e6fe829db1edb316849 (patch) | |
tree | 949158d1da3f5db462ced47365b04932bab37223 | |
parent | f2a891eb581dab8339867caf7e69770d3594f170 (diff) | |
download | renrot-97daff9a3404219369d46e6fe829db1edb316849.tar.gz renrot-97daff9a3404219369d46e6fe829db1edb316849.tar.bz2 |
Add original file name counter template sequence "%C" and the base part of the original file name to "%O".
%o represents the original filename without modifications.
Tag RenRotFileNameOriginal writing is added.
Fix usage() output formatting and groupping options.
git-svn-id: file:///svnroot/renrot/branches/RENROT_STABLE@244 fe2816f4-e837-0410-b10a-f608c9d244a1
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | etc/renrot.conf | 4 | ||||
-rwxr-xr-x | renrot | 118 |
5 files changed, 104 insertions, 36 deletions
@@ -1,16 +1,22 @@ $Log$ +Revision 1.148.2.1 2006/08/19 06:27:25 andy +Add original file name counter template sequence "%C" and the base part of the original file name to "%O". +%o represents the original filename without modifications. +Tag RenRotFileNameOriginal writing is added. +Fix usage() output formatting and groupping options. + Revision 1.148 2006/07/16 16:59:44 andy Release as 0.22. Revision 1.147 2006/07/16 10:02:12 andy Remove fatal case when keywords file isn't exist. Fix return value in the getFileDataLines() and keywordizer(). Now skip empty keywords, and remove tail \r if occurs. Add 'no'-prefixed aliases to exist 'no-' options: --norename, --norotate. -New option --no-tags (with alias --notags) switches tags writting. +New option --no-tags (with alias --notags) switches tags writing. Revision 1.146 2006/07/13 13:07:39 zeus Tags initialization moved from tagWriter() to the renRotProcess(). Revision 1.145 2006/07/13 11:41:10 andy TODO cleanup. @@ -270,13 +276,13 @@ Remove deprecated --rotate and --ext options. Revision 1.81 2006/05/17 17:05:09 andy Implement exclude list (option --exclude <FILE>). Release as 0.19.1. Revision 1.80 2006/05/17 12:07:14 andy -Unify EXIF writtings to exifWritting(). +Unify EXIF writings to exifWritting(). First attempt to rotation by Orientation tag (new option --only-orientation). Remove unused variables. Revision 1.79 2006/05/15 17:49:06 andy Add TODO and README.russian to %doc section in spec file. @@ -316,13 +322,13 @@ Fix internal documentation according to last changes. Revision 1.71 2006/05/13 14:33:33 andy Change --files to --file, --rotate to --rotate-angle and --ext to --extension. Revert back --no-rotate and --no-rename. Exclude single quotas from README examples part due to undesired interpretation in cmd.exe. Also, put note to README.Windows. Add no warranty part to README. Correct low case makeup. -Always writting Software tag. +Always writing Software tag. Release as 0.18.3. Revision 1.70 2006/05/11 10:11:47 zeus fixing typo in parameter to template2name. adding FileModifyDate writing in DateTimeOriginal tag absence. @@ -1,13 +1,13 @@ * 0.22 * A new option --no-tags has been added. Use it when you don't want to write EXIF tags. The 'no'-prefixed aliases to the 'no-' options were added: --norename, --norotate, and --notags. The main functionality has been expanded -with keywordizer procedure. See the applied manual to get details of usaging -it. +with the keywordizer procedure. See the applied manual to get details for +using it. * 0.21.1 * The new template parameters %n and %e have been added, representing the original name and the extension of the given file, respectively. A new @@ -62,8 +62,10 @@ Code - to tune style look of comments, code, e.t.c. Other +- to implement --include-file option (andy) + - UTF8fy (comments, tags, ...) since it's not implemented in ExifTool yet diff --git a/etc/renrot.conf b/etc/renrot.conf index e24d66a..bf531af 100644 --- a/etc/renrot.conf +++ b/etc/renrot.conf @@ -15,21 +15,25 @@ # Process files with or without mtime modification. #mtime = Yes # Template is used for file name building while renaming. Interpreted # sequences are: # %% a literal % +# %C numeric part of the original file name # %c file order number in the processed file set # %d day of the month (01-31) # %E ExposureTime tag value if defined # %F FNumber tag value if defined # %H hour (00-23) # %I ISO tag value if defined # %i FileNumber tag if exists (otherwise, it'll be replaced by string "NA") # %M minute (00-59) # %m month (01-12) +# %n previous file name +# %O original file name without extension +# %o original file name # %S second (00-59) # %W WhiteBalance tag value if defined # %Y year (1900, 1901, and so on) # %y last two digits of year (00..99) #name template = '%Y%m%d%H%M%S' @@ -2,12 +2,13 @@ # # $Id$ # use strict; +use warnings; require 5.006; use Time::localtime; use Time::Local; use Image::ExifTool; use Getopt::Long; @@ -25,12 +26,13 @@ if (defined %Image::ExifTool::UserDefined::RenRot) { } %Image::ExifTool::UserDefined::RenRot = ( GROUPS => { 0 => 'XMP', 1 => 'RenRot', 2 => 'Image' }, NAMESPACE => [ 'RenRot' => 'http://freshmeat.net/projects/renrot/' ], WRITABLE => 'string', + RenRotFileNameOriginal => { }, RenRotProcessingTimestamp => { }, RenRotVersion => { }, RenRotURL => { }, ); # The %Image::ExifTool::UserDefined hash defines new tags to be added to @@ -88,13 +90,13 @@ my $keywordize; # keywordize or not my $keywordsReplace; # whether to add keywords to the existent ones or replace them my $keywordsFile; # file with keyword set my $mtime; # mtime taken from CLI my $nameTemplate; # template for the filename taken from CLI my $noRename = 0; # no rename needed, default is to rename to the YYYYmmddHHMMSS.ext my $noRotation = 0; # no rotation needed, default is to rotate -my $noTags = 0; # no tags writting needed +my $noTags = 0; # no tags writing needed my $orientTag = 0; # rotate by changing Orientation tag (no real rotation) my $quiet = 0; # suppressing messages my $rotateAngle; # define the angle to rotate on 90, 180 or 270 my $rotateThumbnail; # define the angle to rotate on 90, 180 or 270 my %tagsFromCli; # tags are got from CLI my $trim; # jpegtran -trim @@ -698,13 +700,14 @@ sub renRotProcess { dbgmsg (1, "renRotProcess(): Initializing tags ...\n"); foreach my $key (sort (keys %tags)) { $exifTool->SetNewValue($key, $tags{$key}{value}, Group => $tags{$key}{group}); } - procmsg ("RENAMING / ROTATING\n===================\n"); + procmsg ("RENAMING / ROTATING\n"); + procmsg ("===================\n"); foreach my $file (@files) { procmsg ("Processing file: $file ...\n"); # Setup defaults $info = $exifTool->ImageInfo($file); @@ -791,12 +794,23 @@ sub renameFile { if ($noRename != 0) { dbgmsg (2, "renameFile(): No renaming asked, filename is left untouched.\n"); $newFileName = $file; $filenameshash{$newFileName} = $unixTime; } else { + my $fileNameOriginal = $exifToolObj->GetValue("RenRotFileNameOriginal"); + if (not defined $fileNameOriginal) { + $tags{'RenRotFileNameOriginal'} = {value => $file, group => 'RenRot'}; + $exifTool->SetNewValue("RenRotFileNameOriginal", + $tags{'RenRotFileNameOriginal'}{value}, + Group => $tags{'RenRotFileNameOriginal'}{group}); + dbgmsg (2, "renameFile(): set RenRotFileNameOriginal to $file.\n"); + } else { + dbgmsg (2, "renameFile(): RenRotFileNameOriginal: $fileNameOriginal.\n"); + } + my $ext = ($file =~ m/(\.[^\.]+)$/) ? $1 : ""; my $extLen = length($ext); $newFileName = template2name($exifToolObj, $infoObj, $configOptions{'name template'}, @@ -828,13 +842,13 @@ sub renameFile { # # getFileData() gets data from a given file in one-line string # sub getFileData { my $file = shift; my @result = getFileDataLines($file); - return join ('', @result) if (scalar(@result) > 0); + return join ("", @result) if (scalar(@result) > 0); return undef; } ######################################################################################## # # getFileDataLines() gets data from a given file in array of lines @@ -918,13 +932,14 @@ sub aggregationProcess { return if ($configOptions{'aggregation mode'} eq "none"); my $file; my $info; my $NewDir; - procmsg ("AGGREGATION\n===========\n"); + procmsg ("AGGREGATION\n"); + procmsg ("===========\n"); if ($configOptions{'aggregation mode'} eq "template") { dbgmsg (1, "aggregationProcess(): Template: $configOptions{'aggregation template'}\n"); my $fileCounter = $countStart; foreach $file (sort (keys %filenameshash)) { @@ -1193,61 +1208,73 @@ sub rotateThumbnail { warnmsg ("No thumbnail found.\n"); } } ######################################################################################## # -# usage() - the instruction how to use the script +# usage() prints the instructions how to use the script # sub usage { infomsg ( "Usage: renrot <--extension EXTENSION> [--quiet] [--no-rotate] [--no-rename] [--name-template TPL] [--comment-file FILE] [--work-directory DIR] [[--] FILE1 FILE2 ...] Options: -c, --config-file <FILE> configuration file to use -d, --work-directory <DIR> working directory - --exclude <FILE> ... files to not process. No wildcards. + --exclude <FILE> ... files to not process. No wildcards. -e, --extension <EXTENSION> extension of files to process: JPG, jpeg, ... + +Renaming options: -n, --name-template <TPL> filename template (see manual for details) - --no-rename no rename needed, default is to rename - --counter-fixed-field (*) set fixed field for counter (used in templates) - --counter-start <NUMBER> start to count files to be renamed from - --counter-step <NUMBER> step for files to be renamed counter + --no-rename no rename needed, default is to rename + --counter-fixed-field (*) set fixed field for counter (used in templates) + --counter-start <NUMBER> start to count files to be renamed from + --counter-step <NUMBER> step for files to be renamed counter + +Rotating options: -r, --rotate-angle <ANGLE> angle to rotate file and thumbnail by 90, 180, 270 - --rotate-thumb <ANGLE> rotate only thumbnail by 90, 180, 270 - --only-orientation changing Orientation tag (no real rotation) - --trim (*) pass -trim to jpegtran - --no-rotate no rotation needed, default is to rotate - --mtime (*) set file mtime according to DateTimeOriginal tag - --keywordize (*) set Keywords tag - --keywords-replace (*) replace Keywords tag rather than add value to it - -k, --keywords-file file with keywords - --aggr-mode <MODE> run aggregation (MODE: none, delta, template) - --aggr-delta <INTERVAL> aggregation time delta - --aggr-directory <DIR> aggregation directory name + --rotate-thumb <ANGLE> rotate only thumbnail by 90, 180, 270 + --only-orientation changing Orientation tag (no real rotation) + --no-rotate no rotation needed, default is to rotate + --trim (*) pass -trim to jpegtran + --mtime (*) set file mtime according to DateTimeOriginal tag + +Keywordizing options: + --keywordize (*) set Keywords tag + --keywords-replace (*) replace Keywords tag rather than add value to it + -k, --keywords-file <FILE> file with keywords + +Aggregating options: + --aggr-mode <MODE> run aggregation (MODE: none, delta, template) + --aggr-delta <INTERVAL> aggregation time delta + --aggr-directory <DIR> aggregation directory name -a, --aggr-template <TPL> aggregation template (see manual for details) - --aggr-virtual (*) virtual aggregation (symlinks instead of files) - --aggr-virtual-directory <DIR> root directory for virtual aggregation - --comment-file <FILE> file with text to put into Commentary tag - --user-comment <COMMENTARY> file with text to put into UserComment tag + --aggr-virtual (*) virtual aggregation (symlinks instead of files) + --aggr-virtual-directory <DIR> root directory for virtual aggregation + +Tag writing options: + --comment-file <FILE> file with text to put into Commentary tag + --user-comment <COMMENT> file with text to put into UserComment tag -t, --tag <TAG> ... existent EXIF tag to set in renamed files - --no-tags no tags writting, default is to write tags - --dry-run show what would have been happened - -v [-v -v ...] number of these options defines debug level + --no-tags no tags writing, default is to write tags + +Misc options: + --dry-run show what would have been happened + -v number of these options defines debug level -?, --help display this help and exit - --version output version and exit + --version output version and exit (*) The option does not take an argument and may be negated, i.e. prefixed by 'no'. E.g. 'mtime' will allow '--mtime' (positive value will be assigned) and '--nomtime' or '--no-mtime' (negative value will be assigned). "); } ######################################################################################## # -# template2name() - file name builder, according the template +# template2name() builds file name according to the template # sub template2name { my $exifToolObj = shift; my $infoObj = shift; my $template = shift; # the template to be used my $fileNo = shift; # counter for %c @@ -1273,12 +1300,15 @@ sub template2name { my $ExposureTime = ""; my $FileNumber = 'NA'; my $FNumber = ""; my $ISO = ""; my $WhiteBalance = ""; + my $fileNameOriginal = ""; + my $fileNameOriginalCounter = ""; # we can't use 0 as default value + my $fileNameOriginalExtensionLess = ""; if (defined $infoObj->{"FileNumber"}) { $FileNumber = $infoObj->{"FileNumber"}; } if (defined $infoObj->{"ExposureTime"}) { @@ -1296,27 +1326,41 @@ sub template2name { if (defined $infoObj->{"WhiteBalance"}) { $WhiteBalance = "W" . $infoObj->{"WhiteBalance"}; $WhiteBalance =~ s/[\s()]//g; } + if (defined $infoObj->{"RenRotFileNameOriginal"}) { + $fileNameOriginal = $infoObj->{"RenRotFileNameOriginal"}; + # file name starts with letters and ends with digits + if ($fileNameOriginal =~ m/^[[:alpha:]-_]*(\d+)(\.[^\.]+)?$/) { + $fileNameOriginalCounter = $1; + } + if ($fileNameOriginal =~ m/^(.*)\.([^\.]+)$/) { + $fileNameOriginalExtensionLess = $1; + } + } + my @templatearea = split (//, $template); my %templatehash = ( '%' => "%", 'a' => $angleSuffix, + 'C' => $fileNameOriginalCounter, 'c' => sprintf($counterSize, $fileNo), 'd' => $tm[3], 'E' => $ExposureTime, 'e' => $ext, 'F' => $FNumber, 'H' => $tm[4], 'I' => $ISO, 'i' => $FileNumber, 'M' => $tm[5], 'm' => $tm[2], 'n' => $base, + 'O' => $fileNameOriginalExtensionLess, + 'o' => $fileNameOriginal, 'S' => $tm[6], 'W' => $WhiteBalance, 'Y' => $tm[0], 'y' => $tm[1], ); my $thename = ""; @@ -1414,12 +1458,17 @@ I<%Y%m%d%H%M%S>. For practical results see L</TEMPLATE EXAMPLES> section. Interpreted sequences are: =over B<%%> a literal % +B<%C> the numeric part of the original file name. Implemented for the sake +of the cameras, where no FileNumber EXIF tag is present (currently all except +Canon). Filename would started by letters and ended by digits. No other +symbols are not allowed, except C<->, C<.> and C<_>. + B<%c> file order number in the processed file set (also see B<--counter-fixed-field> option) B<%d> day of the month (01-31) B<%E> ExposureTime tag value if defined @@ -1436,13 +1485,20 @@ B<%i> FileNumber tag if exists (otherwise, it'll be replaced by string C<NA>) B<%M> minute (00-59) B<%m> month (01-12) -B<%n> old filename +B<%n> previous filename (the one before the current processing with renrot) + +B<%O> base part of the original filename (see B<%o>). In other words the +first part from the begin to the last dot symbol. + +B<%o> the name, file had before first processing with renrot. If the file +was processed with renrot if only once, the tag RenRotFileNameOriginal written +with the file name. B<%S> second (00-59) B<%W> WhiteBalance tag value if defined B<%Y> year (1900, 1901, and so on) |