News:

If this site goes down it is because of the crappy DreamHost web hosting: They will disable your "unlimited traffic" web server if a single bot hammers the site with a moderate load.  If necessary, an alternate ExifTool forum page is available at https://sourceforge.net/p/exiftool/discussion/

Main Menu

truncate exceeding keywords

Started by audiogalaxy, October 30, 2017, 05:08:03 PM

Previous topic - Next topic

audiogalaxy

Hallo,

and sorry for my halting English :-/

I'm not very skilled in programming with exiftool, and I have a couple of great problems, each of them is about the "KEYWORDS" field (even in EXIF or in IPTC "zone").

Facts:
- Given that the "keywords" field contains potentially lots of keywords
- they are not necessarily in the form of a single word
- So I consider each "token" separated by a ";" (semicolon) separator and (maybe: I really don't know how to verify: I put my keywords into the files using Adobe Bridge) each of the actual keyword "wrapped" in an opening and closing double quotes.

Examples:

keyword:bottle
keyword:"red bottle"
keyword:"broken red bottle"
keywords:"red bottle" ; "broken red bottle" ; "glass" ; "waste"

To solve:

1) Cut out the exceeding number of keywords (example: 50).

2) Shuffle randomly the keywords starting from a given keyword, for example AFTER the 8th keyword.

I can't know if the number of the keywords is greather than (50) but I have to perform that action (cut the exceeding keywords) in THAT case.
I can't know it the number of keywords is lower than 8, but I have to perform the shuffle operation between  the "exceeding" keywords in the case they are greather than (8)

8 and 50 are sample numbers.

Is there someone here that could write one code for the problems "1" and "2" ?

Thank you even only if you read this! :-)

--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

Phil Harvey

First, we need to know where your keywords are stored and if they are stored correctly.

Please run this command on a file and post the output:

exiftool -keywords -subject -sep xxx FILE

Assuming the keywords are stored properly in "Keywords", there should be an "xxx" between them in the output from the command above.  In this case, you could use the following command to rewrite the keywords, truncating the list to a maximum of 50 keywords and keeping the first 8 in the same order:

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}" FILE

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

audiogalaxy

Quote from: Phil Harvey on October 31, 2017, 07:54:49 AM
First, we need to know where your keywords are stored and if they are stored correctly.

Please run this command on a file and post the output:

exiftool -keywords -subject -sep xxx FILE

Assuming the keywords are stored properly in "Keywords", there should be an "xxx" between them in the output from the command above.  In this case, you could use the following command to rewrite the keywords, truncating the list to a maximum of 50 keywords and keeping the first 8 in the same order:

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}" FILE

- Phil

this is the output using the word live for xxx :

Keywords                        : microphonelivesinglivesongliveliveliveAudio Equipmentliveband rehearsallivecolorfulliveClose-upliveEntertainmentliveEntertainment EventliveFunlivegarage bandliveHeavy MetalliveloudlivemonochromeliveMusicliveMusic FestivalliveNightlifeliveperformancelivePunkliveRockliveRock and RollliveRock BandlivescreamingliveShallow depth of fieldliveshoutinglivesinging

what shoud I use to search for a composite keyword, like "live band" (in this case).
--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

Phil Harvey

The -sep option sets the separator between the keywords if they are stored properly.  I wanted you to use "xxx" literally.  The second command I gave uses "xxx" as a separator as well to manipulate the keywords string.  So my exact command should work for you, just replacing FILE with the name of your file.

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

audiogalaxy

Quote from: Phil Harvey on October 31, 2017, 07:54:49 AM
First, we need to know where your keywords are stored and if they are stored correctly.

Please run this command on a file and post the output:

exiftool -keywords -subject -sep xxx FILE

Assuming the keywords are stored properly in "Keywords", there should be an "xxx" between them in the output from the command above.  In this case, you could use the following command to rewrite the keywords, truncating the list to a maximum of 50 keywords and keeping the first 8 in the same order:

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}" FILE

- Phil

Sorry Phill, I answered only to the FIRST part, to let you see the output. But I can't use the second part because my "script" (am I right?) have to work even If there are empty JPGS and even if I don't know the words contained in "keywords" (or whatever that file could be). Did I make myself understood? I hope so :-) It's a little bit complicated for me to explain this problem ...

This "command" have to work like a magic on any set of JPG (or TIFF, or RAW files) with an unspecified number of keywords that could be zero up to 100 ... This is very useful for me :-) So if I can't explain this very well, let me know! :-) I'm not a natural English speaker :)

thanks!
--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

audiogalaxy

Quote from: Phil Harvey on October 31, 2017, 02:36:48 PM
The -sep option sets the separator between the keywords if they are stored properly.  I wanted you to use "xxx" literally.  The second command I gave uses "xxx" as a separator as well to manipulate the keywords string.  So my exact command should work for you, just replacing FILE with the name of your file.

- Phil

here I am:

Keywords                        : microphonexxxsingxxxsongxxxlivexxxAudio Equipmentxxxband rehearsalxxxcolorfulxxxClose-upxxxEntertainmentxxxEntertainment EventxxxFunxxxgarage bandxxxHeavy MetalxxxloudxxxmonochromexxxMusicxxxMusic FestivalxxxNightlifexxxperformancexxxPunkxxxRockxxxRock and RollxxxRock BandxxxscreamingxxxShallow depth of fieldxxxshoutingxxxsinging

Is this what I should have done? :-) (sorry)
--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

audiogalaxy

Quote from: Phil Harvey on October 31, 2017, 02:36:48 PM
The -sep option sets the separator between the keywords if they are stored properly.  I wanted you to use "xxx" literally.  The second command I gave uses "xxx" as a separator as well to manipulate the keywords string.  So my exact command should work for you, just replacing FILE with the name of your file.

- Phil

I've tried: this is the error (and nothing changed):

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}" aaaa.jpg

Warning: Bareword "xxx" not allowed while "strict subs" in use for 'keywords' - aaaa.jpg

--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

Phil Harvey

Ooops.  That's my fault.  When I changed the outter quotes to double, I forgot to change the inner quotes to single.   (I'm on a Mac, so my quoting is different.  I'm assuming you're on a PC.)  Try this:

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join 'xxx',@b}" FILE

This should work on any file to re-arrange the keywords as you wanted.

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

audiogalaxy

Quote from: Phil Harvey on October 31, 2017, 03:55:03 PM
Ooops.  That's my fault.  When I changed the outter quotes to double, I forgot to change the inner quotes to single.   (I'm on a Mac, so my quoting is different.  I'm assuming you're on a PC.)  Try this:

exiftool -sep xxx "-keywords<${keywords;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join 'xxx',@b}" FILE

This should work on any file to re-arrange the keywords as you wanted.

- Phil

Phil: I love you.
I'm going to donate immediately some money.

You're simply great.

I solved LOTS of problems using your software: for me and for lots of other people.
But NOW I really solved a problem of mine, a GREAT problem and eliminated a _critical_ time-consuming work. Thanks!

I really want to learn how to do this by myself but ... one step at a time.

THANKS
--
Sorry for my halting English: I'm not a natural English speaker.
On a PC / windows commandline

Phil Harvey

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