aboutsummaryrefslogtreecommitdiff
path: root/renrot
diff options
context:
space:
mode:
Diffstat (limited to 'renrot')
-rwxr-xr-xrenrot118
1 files changed, 87 insertions, 31 deletions
diff --git a/renrot b/renrot
index 0a2c428..ece96e6 100755
--- a/renrot
+++ b/renrot
@@ -5,6 +5,7 @@
#
use strict;
+use warnings;
require 5.006;
use Time::localtime;
use Time::Local;
@@ -28,6 +29,7 @@ if (defined %Image::ExifTool::UserDefined::RenRot) {
GROUPS => { 0 => 'XMP', 1 => 'RenRot', 2 => 'Image' },
NAMESPACE => [ 'RenRot' => 'http://freshmeat.net/projects/renrot/' ],
WRITABLE => 'string',
+ RenRotFileNameOriginal => { },
RenRotProcessingTimestamp => { },
RenRotVersion => { },
RenRotURL => { },
@@ -91,7 +93,7 @@ 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
@@ -701,7 +703,8 @@ sub renRotProcess {
$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");
@@ -794,6 +797,17 @@ sub renameFile {
$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);
@@ -831,7 +845,7 @@ sub renameFile {
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;
}
@@ -921,7 +935,8 @@ sub aggregationProcess {
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");
@@ -1196,7 +1211,7 @@ sub rotateThumbnail {
########################################################################################
#
-# usage() - the instruction how to use the script
+# usage() prints the instructions how to use the script
#
sub usage {
infomsg (
@@ -1207,36 +1222,48 @@ infomsg (
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).
");
@@ -1244,7 +1271,7 @@ Options:
########################################################################################
#
-# template2name() - file name builder, according the template
+# template2name() builds file name according to the template
#
sub template2name {
my $exifToolObj = shift;
@@ -1276,6 +1303,9 @@ sub template2name {
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"};
@@ -1299,10 +1329,22 @@ sub template2name {
$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,
@@ -1314,6 +1356,8 @@ sub template2name {
'M' => $tm[5],
'm' => $tm[2],
'n' => $base,
+ 'O' => $fileNameOriginalExtensionLess,
+ 'o' => $fileNameOriginal,
'S' => $tm[6],
'W' => $WhiteBalance,
'Y' => $tm[0],
@@ -1417,6 +1461,11 @@ Interpreted sequences are:
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)
@@ -1439,7 +1488,14 @@ 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)

Return to:

Send suggestions and report system problems to the System administrator.