Remove duplicate Keyword

Started by bennyys, July 10, 2017, 01:05:35 PM

Previous topic - Next topic

bennyys

Hi All,
At the moment I am dealing with more than 50 image, and some of those with duplicate keyword.
I try to remove duplicate keyword using the following command or procedure but have no luck yet. Please let me know if I missing something in the next 2 command!

1. Remove duplication for version below 10.51


exiftool -sep "##" "-keywords<${keywords;my %seen; my $new=join('##',grep { ! $seen{ $_ }++ } split /##/);$_ = $_ ne $new ? $new : undef}" DirOrFile


2. using command


exiftool "-keywords<mykeywords" *


keywords is set up in exiftool config as


%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




Regards,
Benny




StarGeek

Since you mention the version, I assume you're using NoDups for later versions.

Option 1 looks correct and is the same as I posted here.  In what way is it not working for you?  As I said in the linked post, it will throw a minor warning if there aren't any duplicate keywords, but that can be ignored.

What is exiftool's response in the case of option 2?  Is that your entire .exiftool_config file?  Because if there's another %Image::ExifTool::UserDefined section, it may not work.

Here's my UniqueKeywords tag code that made some time back, though I don't think I ever posted it.  It can be added under the 'Image::ExifTool::Composite' => { line in the example .exiftool_config.
UniqueKeywords => {
Require => 'Keywords',
ValueConv => q{
my @list = ref $val ? @$val : ($val);
my %seen;
my @new = grep{ ! $seen{ $_ }++ } @list;
return( join('',@list) ne join('',@new)  ? \@new : undef);
},         
},


I notice that your code trims leading spaces.  Are you sure you have keywords with leading spaces? 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bennyys

Hi StarGeek,

Since you mention the version, I assume you're using NoDups for later versions.
( I knew it from Phill post's but I haven't try as I have 10.47 at the moment)

Option 1 looks correct and is the same as I posted here.  In what way is it not working for you?
(I try it this morning after restart my laptop and now it is working fine for me)

What is exiftool's response in the case of option 2?  (see attachment)
(It supposed to be 2 image files updated ( as I did it in purpose to duplicate it just to see how it works for me)


Is that your entire .exiftool_config file?  Because if there's another %Image::ExifTool::UserDefined section, it may not work.
(Yes it is, that is the only .exiftool_config content file I have at the moment)


StarGeek

I tested out your config file and it worked for me.  So I'm guessing that exiftool can't find your .exiftool_config file.  Try running
exiftool -config /path/to/.exiftool_config -mykeywords DuplicateKeywords.jpg
and see if that works properly first.  Replace "/path/to/.exiftool_config" with the full path to your config file and "DuplicateKeywords.jpg" with a file you know has duplicate keywords.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bennyys

Hi StarGeek,
I run command


exiftool -config /path/to/.exiftool_config -mykeywords DuplicateKeywords.jpg

and here is the outcome

Can't locate C:\exiftoolgui in @INC (@INC contains: . C:\Windows/lib C:\Users\US
ER\AppData\Local\Temp\par-55534552\cache-exiftool-10.47\inc\lib C:\Users\USER\Ap
pData\Local\Temp\par-55534552\cache-exiftool-10.47\inc CODE(0x2e581b4) CODE(0x2e
583ac)) at Image/ExifTool.pm line 7746.

Regards,
Benny

StarGeek

Are you running these in CMD or through ExiftoolGUI?

I'm trying to figure out how the error comes back with a reference to an exiftoolgui directory.

Try removing the exiftool temp directories as that type of error often comes up when something goes wrong when exiftool tries to run.  To do so, click on the Windows Start button and type %Temp% in the search bar.  Look for any directory that starts with par-.  It may be par- and the name of your account or it might be par- and a string of numbers and letters.  Go ahead and delete them and then try to run exiftool again.

Also, make sure and replace "/path/to/.exiftool_config" with the full path to your config file and "DuplicateKeywords.jpg" with a file you know has duplicate keywords.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bennyys

Hi starGeek,
Following is my answer

Are you running these in CMD or through ExiftoolGUI?
(I run the command from CMD, running as administrator)

I'm trying to figure out how the error comes back with a reference to an exiftoolgui directory.
(Just for information: I put all my exiftool stuff under folder ExiftoolGUI(see the picture for detail contents))

bennyys

Hi StarGeek,

I follow your suggestion:

1. Try removing the exiftool temp directories as that type of error often comes up when something goes wrong when exiftool tries to run.  To do so, click on the Windows Start button and type %Temp% in the search bar.  Look for any directory that starts with par-.  It may be par- and the name of your account or it might be par- and a string of numbers and letters.  Go ahead and delete them and then try to run exiftool again.

(I removed 2 folders of par-, restart my laptop and rerun exiftool again)

Also, make sure and replace "/path/to/.exiftool_config" with the full path to your config file and "DuplicateKeywords.jpg" with a file you know has duplicate keywords.

(here is my command


exiftool -config C:\exiftoolgui -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg


still come up with

"Can't locate C:\exiftoolgui in @INC (@INC contains: . C:\Windows/lib C:\Users\US
ER\AppData\Local\Temp\par-55534552\cache-exiftool-10.47\inc\lib C:\Users\USER\Ap
pData\Local\Temp\par-55534552\cache-exiftool-10.47\inc CODE(0x2ff018c) CODE(0x2f
f0384)) at Image/ExifTool.pm line 7746."

Regards,
Benny

StarGeek

Try:
exiftool -config C:\exiftoolgui\.exiftool_config -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bennyys

I try


exiftool -config C:\exiftoolgui\.exiftool_config -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg


it come up with list of keywords, see attachment

Regards,
Benny

bennyys

It seems that "mykeywords" list all unique keyword in cmd


2015:03:23 21:01:55; ScreenShot; Sendiri; 2015:01:26 21:14:22; LebihDariSeorang; DariFB;


where the original keywords are:

2015:03:23 21:01:55
ScreenShot
Sendiri
2015:01:26 21:14:22
LebihDariSeorang
DariFB
2015:03:23 21:01:55
ScreenShot
Sendiri
2015:01:26 21:14:22
LebihDariSeorang
DariFB
2015:03:23 21:01:55
ScreenShot
Sendiri
2015:01:26 21:14:22
LebihDariSeorang
DariFB


The only part here that still missing or not working properly is to write the unique Keywords(which is list on CMD screen using exiftool -config C:\exiftoolgui\.exiftool_config -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg ) to the IPTC.

Regards,
Benny

StarGeek

Now try running the command without the config part
exiftool -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg

If this doesn't work, then exiftool isn't finding the config file on it's own.  If that's true, then I'm guessing that you have exiftool someplace else as well as in C:\exiftoolgui.

Type where exiftool into the command line.  If it shows more than one result, then you have exiftool in multiple places.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bennyys

Hi StarGeek

QuoteNow try running the command without the config part
exiftool -mykeywords Screenshot_2015-03-23-21-01-55-001.jpg
(I try it and still doesn't work)

QuoteIf this doesn't work, then exiftool isn't finding the config file on it's own.  If that's true, then I'm guessing that you have exiftool someplace else as well as in C:\exiftoolgui.

Type where exiftool into the command line.  If it shows more than one result, then you have exiftool in multiple places.
(I did this step and it only report as one exiftool in C:\exiftoolgui.)

I manage to get it work by doing the following step:
1. copy exiftool.exe file and  .exiftool_config file to c:/windows
2. delete exiftool.exe and .exiftool_config file from exiftoolgui folder.
3. running command exiftool "-keywords<mykeywords" *