Adding and removing keywords via json

Started by karlgustavv, February 01, 2015, 03:40:14 AM

Previous topic - Next topic

karlgustavv

Hi Phil,

is there a way to add keywords to files via json (without overwriting existing keywords) or to remove some keywords?

A json file like:

[{
  "SourceFile": "file1.jpg",
  "Keywords": ["file1_key1","file1_key2","file1_key3"]
},
{
  "SourceFile": "file2.jpg",
  "Keywords": ["file2_key1","file2_key2","file2_key3"]
} ...


will set keywords to file1, file2 ... fileN. But it will replace all existing keywords in those files.

Something like exiftool -json-=file.json *.jpg to delete keywords:

[{
  "SourceFile": "file1.jpg",
  "Keywords": ["unwanted_key1","unwanted_key2","unwanted_key3"]
},
{
  "SourceFile": "file2.jpg",
  "Keywords": ["unwanted_key4","unwanted_key5","unwanted_key6"]
} ...


and exiftool -json+=file.json *.jpg to add keywords would really be great.

Regards Karl

Phil Harvey

#1
Hi Karl,

It is easy to see how you missed this in the -csv documentation:

            Special feature:  −csv+=CSVFILE may be used to add items to
            existing lists. This affects only list‐type tags.  Also applies to
            the −j option.


- Phil

Edit:  I have added this to the -json section of the documentation.
...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 ($).

karlgustavv

Hi Phil,

Thanks for your fast answer. That's great news.

Will -csv-=CSVFILE or -json-=JSONFILE work, too? This way you could remove and add keywords in one step:

exiftool -json+=keywords_to_add.json -json-=keywords_to_remove.json *.jpg


Regards Karl

Phil Harvey

...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 ($).

Phil Harvey

Well, I looked into it.  Unfortunately, implementation is non trivial, so I'm not sure it is worthwhile adding this feature.

- 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 ($).

karlgustavv

Thank you a lot for looking into it.

Btw, is it possible to remove keywords using wildcards?

exiftool -keywords-="POI/*" DIR

instead of

exiftool -keywords-="POI/castle" -keywords-="POI/church" -keywords-="POI/museum" -keywords-="POI/zoo" DIR

Regards Karl

Phil Harvey

Hi Karl,

No.  To do what you want requires either an advanced formatting expression or a user-defined Composite tag.  The user-defined tag solution is preferred.

- 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 ($).

karlgustavv

Thank you.

"*" stands for 56 different (sub-)POIs. As this (hopefully) is a one-time-task I will simply specify all 56 POIs that needs to be removed.