Add or replace items in list at once

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

Previous topic - Next topic

Archive

[Originally posted by ce on 2008-06-26 06:29:19-07]

I would like to add some information to the tag list IPTC:Keywords. If there is already an item with the same text, I do not want to add it again.

This works, but is very slow:
Code:
exiftool "-COMPOSITE:LensID->IPTC:Keywords" *.JPG
exiftool "-COMPOSITE:LensID+>IPTC:Keywords" *.JPG
exiftool "-EXIF:Model->IPTC:Keywords" *.JPG
exiftool "-EXIF:Model+>IPTC:Keywords" *.JPG

If I try to edit the same tag more than once, only one of the instructions will be executed. E.g.

Code:
exiftool "-COMPOSITE:LensID->IPTC:Keywords" "-COMPOSITE:LensID+>IPTC:Keywords" "-EXIF:Model->IPTC:Keywords" "-EXIF:Model+>IPTC:Keywords" *.JPG

The above statement will only add EXIF:Model to the list. It will not add or remove LensID or remove an existing EXIF:Model item as one could expect.

Is there a faster way of doing all the above in one statement?

Thanks a lot.
Chris

Archive

[Originally posted by exiftool on 2008-06-26 10:33:59-07]

Hi Chris,

ExifTool 7.32 fixed this so you should be able to add and delete
items from the same list in a single command.  What version
are you using?

- Phil

Archive

[Originally posted by exiftool on 2008-06-26 11:17:38-07]

Hi again,

I just tried your exact command line, and the behaviour when using "+>"
is different than "+=", so you command still won't do what you want.
Unfortunately, "+>" replaces the existing new keywords
list, while "+=" doesn't.   This was done to prevent creating duplicate
entries in a list when copying from a tag which may have multiple copies
in the same file.  So for now, you are stuck using two command lines unless
you want to write a Perl script of your own.  I will look into this to see if
there is any way around this.

- Phil

Archive

[Originally posted by exiftool on 2008-06-26 12:34:55-07]

Make that 4 commands, not 2.  You were right.  It's a tricky issue and
there may not be a simple solution, but I will look into it.
If you have Perl installed, a script of your own may be the way to go
for now since this problem may take a while for me to solve (if
possible at all).  The script would actually be quite simple:

Code:
#!/usr/bin/perl -w
use strict;
use Image::ExifTool qw(:Public);

my $file;
foreach $file (@ARGV) {
    my $exifTool = new Image::ExifTool;
    my @tags = ( 'Composite:LensID', 'EXIF:Model' );
    my $info = $exifTool->ImageInfo($file, \@tags);
    my ($tag, $found);
    foreach $tag (@tags) {
        next unless defined $$info{$tag};
        $found = 1;
        $exifTool->SetNewValue('IPTC:Keywords', $$info{$tag}, DelValue => 1);
        $exifTool->SetNewValue('IPTC:Keywords', $$info{$tag}, AddValue => 1);
    }
    if ($found) {
        my $rtn = $exifTool->WriteInfo($file);
        if ($rtn == 0) {
            print "Write error for $file\n";
        } elsif ($rtn == 1) {
            print "Updated $file\n";
        } elsif ($rtn == 2) {
            print "Nothing changed in $file\n";
        }
    } else {
        print "No tags found for $file\n";
    }
}
#end

(note that this script will overwrite the original image)

- Phil

Archive

[Originally posted by ce on 2008-06-26 14:09:59-07]

Thanks a lot for your help and the workaround. Hope there will be a fix in one of the upcoming versions. I am currently using 7.33.

Chris