How to do a compound IF statement

Started by Archive, May 12, 2010, 08:54:13 AM

Previous topic - Next topic

Archive

[Originally posted by bv on 2007-12-19 20:06:40-08]


Hi Phil, I am trying to figure out how to do a compound IF statement such as if the DateTimeOriginal and ModifyDate and CreateDate are empty / no value then set DateTimeOriginal to FileModifyDate. I tried all three methods (command line, @Argfile, and .Exiftool_config).

I perfer to use @argfile syntax. I made a Composite TAG in .Exiftool_config which works great when outputting results but fails to work in a IF statement.

In anycase, I do not understand Pearl enough to get things right. Pearl is so cryptic to me and add the complexity of you having a internal pasrer in the exiftool, makes things just a bit more impossible. I do hate having to rely on your expertise. You have no idea how much I appriciate your product and your feedback and assistance.

Code:
# ==== ArgFile example #1 =================
-P
-DateTimeOriginal<FileModifyDate
-CreateDate<FileModifyDate
-ModifyDate<FileModifyDate
-if
  ( (not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/) and (not $ModifyDate or $ModifyDate !~ /^[12]/) and (not $CreateDate of $CreateDate !~ /^[12]/) )

Here is a .exiftools_config version. It works but I cannot use it in a -if statement in the argfile. So I need to get Argfile example #1 above working.

Code:
# ==== ArgFile example #2 =================
-P
-DateTimeOriginal<FileModifyDate
-CreateDate<FileModifyDate
-ModifyDate<FileModifyDate
-if
  isAllDates == 0

# ==Results ===================
exiftool -v -@ bv_UseModDate.arg img_0018.JPG
Condition: Bareword "isAllDates" not allowed while "strict subs" in use - img_00
18.JPG
-------- img_0018.JPG (failed condition)
    1 files failed condition

# =====================
# === code in .exiftool_config file ==================
   isDate => {
       Require => 'DateTimeOriginal',
       ValueConv => 'not $val or $val !~ /^[12]/ ? 0 : 1;',
        },
   isAllDates => {
       Require => 'DateTimeOriginal','CreateDate','ModifyDate',
       ValueConv => 'not $val or $val !~ /^[12]/ ? 0 : 1;',
        },
# == Test results ===================
exiftool -S -alldates -year -isdate -isAllDates *.jpg
======== IMG_0117.JPG
DateTimeOriginal: 2005:05:20 00:43:58
CreateDate:     :  :     :  :
ModifyDate:     :  :     :  :
Year: 2005
IsDate: 1
IsAllDates: 1
======== IMG_0118.JPG
DateTimeOriginal:     :  :     :  :
CreateDate:     :  :     :  :
ModifyDate:     :  :     :  :
Year:
IsDate: 0
IsAllDates: 0
# =====================

Archive

[Originally posted by bv on 2007-12-20 04:13:48-08]


I finally got a working ArgFile. I inserted the -P and -overwrite_original repeatedly because I was calling this from another @ Argfile and the -common_args option does not work inside of the Argfile (accouding to documentation). So they would never make it to the other -execute sections.

Any cleanup suggestions are welcome.

Code:
# FixAllDates-Canon.arg - Exiftool v.7.06 @argfile
# Usage:
#   exiftool -@ FixAllDates-Canon.arg -common_args *.JPG
#   exiftool -overwrite_original_in_place -@ FixAllDates-Canon.arg -common_args *.JPG
#   exiftool -P -overwrite_original_in_place -DateTimeOriginal="2005:05:22 00:00:00" *.jpg
#   exiftool -P -overwrite_original_in_place -DateTimeOriginal="2005:04:23 00:00:00" *.jpg
# Verify: exiftool -Make -alldates -r ./ *
#   exiftool -AllDates -if "not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/" -r ./ *.jpg
#
# if all dates are missing, set DateTimeOriginal to FileModifyDate
#
-P
-overwrite_original
-DateTimeOriginal<FileModifyDate
-CreateDate<FileModifyDate
-ModifyDate<FileModifyDate
-if
   ($Make eq "Canon") and (not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/) and (not $ModifyDate or $ModifyDate !~ /^[12]/) and (not $CreateDate or $CreateDate !~ /^[12]/)
-execute
#
# if DateTimeOriginal and CreateDate dates are missing, set to ModifyDate
-P
-overwrite_original
-DateTimeOriginal<ModifyDate
-CreateDate<ModifyDate
-if
   ($Make eq "Canon") and (not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/) and (not $ModifyDate or $ModifyDate !~ /^[12]/)
-execute
#
# if DateTimeOriginal and ModifyDate dates are missing, set to creatDate
#
-P
-overwrite_original
-DateTimeOriginal<CreateDate
-ModifyDate<CreateDate
-if
   ($Make eq "Canon") and (not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/) and (not $CreateDate or $CreateDate !~ /^[12]/)
-execute
#
# if DateTimeOriginal is missing, set to creatDate
#
-P
-overwrite_original
-DateTimeOriginal<CreateDate
-if
   ($Make eq "Canon") and (not $dateTimeOriginal or $dateTimeOriginal !~ /^[12]/)
-execute
#
# if CreateDate date is missing, set to dateTimeOriginal
#
-P
-overwrite_original
-CreateDate<DateTimeOriginal
-if
   ($Make eq "Canon") and (not $CreateDate or $CreateDate !~ /^[12]/)
-execute
#
# if CreateDate date is missing, set to dateTimeOriginal
#
-P
-overwrite_original
-ModifyDate<DateTimeOriginal
-if
   ($Make eq "Canon") and (not $ModifyDate or $ModifyDate !~ /^[12]/)
# end of FixAllDates-canon.arg

Archive

[Originally posted by exiftool on 2007-12-20 12:20:18-08]

The way to do this is with user-defined tags.  Doing this with an
argfile is clumsy and inefficent.  Here is the Composite tag definition:

Code:
   GoodDateTimeOriginal => {
        Require => {
            0 => 'DateTimeOriginal',
            1 => 'CreateDate',
            2 => 'ModifyDate',
            3 => 'FileModifyDate',
        },
        ValueConv => q{
            return undef if $val[0] and $val[0] =~ /^[12]/;
            return $val[1] if $val[1] and $val[1] =~ /^[12]/;
            return $val[2] if $val[2] and $val[2] =~ /^[12]/;
            return $val[3];
        },
    },

You would define a similar tag for each of the other date
tags you want to set, then use arguments like this to do
the work:

Code:
"-datetimeoriginal<gooddatetimeoriginal"

This will not change datetimeoriginal if the value is OK, and
will set it to createdate or modifydate if they are OK, otherwise
it will set it to filemodifydate.

- Phil