Removing IPTC Keyword duplicates

Started by blenhard, November 07, 2012, 07:54:29 PM

Previous topic - Next topic

blenhard

Is there a way to use EXIFTool to remove IPTC keyword duplicates?  I am not sure how they got into my metadata, but now I believe the duplicates are causing me problems because certain programs won't let me delete keywords that are duplicates.

My followup question is can EXIFTool be configured to remove leading spaces from keywords?  Again, I am not sure how it happened but it appears that sometimes I now have what certain programs consider to be duplicates even though they are not...i.e.  " Germany" is not the same as "Germany" but programs treat them as the same.   I did not notice this issue when it happened, but (as above) now certain programs are not letting me delete or change keywords if I have (1) "Keyword" as well as (2) "LeadingSpace+Keyword"

Thanks in advance - your software is a great tool and probably my only chance to fix these issues in batch without lots of manual effort.

Phil Harvey

Here is a config file that will do it with this command:

exiftool "-keywords<mykeywords" DIR

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyKeywords => {
            Require => 'Keywords',
            ValueConv => q{
                my @list = ref $val eq 'ARRAY' ? @$val : $val;
                my ($item, %found, @rtn);
                foreach $item (@list) {
                    $item =~ s/^\s+//;   # remove leading white space
                    push @rtn, $item unless $found{$item};
                    $found{$item} = 1;
                }
                return \@rtn;
            },
        },
    },
);
1; # end


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

blenhard

Wow - that is truly amazing.  Your software is, again, great.  Thanks for saving me so much time.

sempervirentz

Thanks. This works and saved me a lot of time.