Author Topic: Question: replacing tag-content using the -= mechanism  (Read 7368 times)

herb

  • ExifTool Freak
  • *****
  • Posts: 346
Question: replacing tag-content using the -= mechanism
« on: May 13, 2010, 06:26:29 AM »
Hello Phil,

I have a *.jpg file which contains e.g the following tags:
- exif:make=contmake
- xmp-dc:title=conttitle

With the windows executable of exiftool version 8.19 (on Win 2000 system) I tried to replace/delete the content of the above mentioned (example-)tags only in case of the existing tag-content and the string given in commandline are identical.
I tried to use the -= mechanism.

The following commands
    exiftool -exif:make-=contmake -exif:make=contmakenew
    exiftool -xmp-dc:title-=conttitle -xmp-dc:title=conttitle-new
work fine except in the following cases:

a) For contmakenew="" and conttitle-new="" (they have 0 characters) the tag is also deleted when contmake / conttitle
   (given in  commandline) is not identical with the content of the tag inside the file.
b) Using the tag title-de (a valid language sign attached) instead of title:
   For conttitle-de="" the tag is not created also in case of the tag does not exist inside the file.
   This happens only in case of the tag title exists.

What did I wrong or what do I misunderstand?
Or is it a fault?

Thanks for your explanations in advance.
Herb

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16702
    • ExifTool Home Page
Re: Question: replacing tag-content using the -= mechanism
« Reply #1 on: May 13, 2010, 07:40:32 AM »
Hi Herb,

The following commands
    exiftool -exif:make-=contmake -exif:make=contmakenew
    exiftool -xmp-dc:title-=conttitle -xmp-dc:title=conttitle-new
work fine except in the following cases:

a) For contmakenew="" and conttitle-new="" (they have 0 characters) the tag is also deleted when contmake / conttitle
   (given in  commandline) is not identical with the content of the tag inside the file.

If to conditionally delete a tag, you just need to say -TAG-=VALUE.  If you add -TAG= later on the command line, it overrides the condition and simply deletes the tag.

Quote
b) Using the tag title-de (a valid language sign attached) instead of title:
   For conttitle-de="" the tag is not created also in case of the tag does not exist inside the file.
   This happens only in case of the tag title exists.

I'm not clear on what you mean here.  Can you give the command lines?

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

herb

  • ExifTool Freak
  • *****
  • Posts: 346
Re: Question: replacing tag-content using the -= mechanism
« Reply #2 on: May 13, 2010, 03:29:04 PM »
Hello Phil,

thanks for yor quick reply.

Starting point of my suggestions were the following 2 examples in exiftool help:
- exiftool -whitebalance-=auto -WhiteBalance=tung dst.jpg
  Set WhiteBalance to Tungsten only if it was previously Auto.
- exiftool -comment-= -comment='new comment' a.jpg
  Write a new comment only if the image doesn't have one already.

So I thought, in order to delete a tag, I always need the tag twice inside the commandline (as given in a) of my questions:
   exiftool -exif:make-=contmake -exif:make="".
Now it is clear to me that the following command will delete the tag:
   exiftool -exif:make-=contmake

In the meanwhile I think I confused myself. Thanks for your explanation.

Coming to b) of my questions: (I agree it was not clearly described. Sorry.)
Lets assume, the tag -xmp-dc:title=value exists, but the tag -xmp-dc:title-de does not exist.
The command
   exiftool -xmp-dc:title-de-="" -xmp-dc:title-de="valnew" pic.jpg
does not create the non-existing tag.

Thanks in advance again.
   

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16702
    • ExifTool Home Page
Re: Question: replacing tag-content using the -= mechanism
« Reply #3 on: May 14, 2010, 08:19:36 AM »
Starting point of my suggestions were the following 2 examples in exiftool help:
- exiftool -whitebalance-=auto -WhiteBalance=tung dst.jpg
  Set WhiteBalance to Tungsten only if it was previously Auto.
- exiftool -comment-= -comment='new comment' a.jpg
  Write a new comment only if the image doesn't have one already.

So I thought, in order to delete a tag, I always need the tag twice inside the commandline (as given in a) of my questions:
   exiftool -exif:make-=contmake -exif:make="".
Now it is clear to me that the following command will delete the tag:
   exiftool -exif:make-=contmake

In the meanwhile I think I confused myself. Thanks for your explanation.

No problem.  There is also the following example which may have helped if you had found it:

exiftool -credit-=xxx dir

Quote
Lets assume, the tag -xmp-dc:title=value exists, but the tag -xmp-dc:title-de does not exist.
The command
   exiftool -xmp-dc:title-de-="" -xmp-dc:title-de="valnew" pic.jpg
does not create the non-existing tag.

Thanks for the example.  You're right, the behaviour here is not correct.  I will fix this in the next release.

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

herb

  • ExifTool Freak
  • *****
  • Posts: 346
Re: Question: replacing tag-content using the -= mechanism
« Reply #4 on: May 14, 2010, 02:17:24 PM »
Hello Phil,

thanks for your answers. This are really good news.

Please do not misunderstand, but I have an additional question:
I have files that contain the exif:copyright tag and the length of its content is 0 byte.

exiftool -exif:copyright -- displays the content, because the tag exists.
exiftool -exif:copyright-="" -exif:copyright="cop" -- does not change the file, because the tag exists.
exiftool -exif:copyright-="" -- does not delete the tag.

Is this correct?
Thanks for yor comments in advance.
Herb

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16702
    • ExifTool Home Page
Re: Question: replacing tag-content using the -= mechanism
« Reply #5 on: May 14, 2010, 08:26:15 PM »
Wow, you are good at finding bugs.

As far as I can tell, this is the only EXIF tag which has this problem.  The reason is that this tag is handled specially because the EXIF specification allows two strings to be written to this tag, one for the photographer and one for the editor.  It seems that somehow this special case is causing problems here.  I will sort this out and fix this too for the next release.

As well, the EXIF specification states that many strings may be filled with spaces and that this should be treated the same as a missing tag.  I'm currently not handling this either in the conditional replacement but I'll see what I can do for this too.

Thanks for pointing this out.  It's good to fix details like this.

- Phil
« Last Edit: May 15, 2010, 06:45:15 AM by 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 ($).

herb

  • ExifTool Freak
  • *****
  • Posts: 346
Re: Question: replacing tag-content using the -= mechanism
« Reply #6 on: May 16, 2010, 08:03:29 AM »
Hello Phil,

don't worry, just an additional question.
Lets assume a file contains 1 language-tag and 1 language-sub-tag
- xmp-dc:title=t
- xmp-dc:title-de=tde

The command
   exiftool -xmp-dc:title-="t" -xmp-dc:title="tnew"
works fine for tag xmp-dc:title and in case of the old value was "t" also all language-sub-tags e.g. title-de are removed.
In order to keep the values of the sub-tags I have to send the following command
   exiftool -xmp-dc:title-="t" -xmp-dc:title="tnew" "-xmp-dc:title-de<$xmp-dc:title-de"

Is the described behaviour the expected one?
I ask, because I had expected the language-sub-tasks are not deleted in case of the tag itself is not deleted.
Does a mechanism exists that keeps all values of existing language-sub-tags automatically?

Question to your announced corrections:
Can I exchange the values "t" -> "tnew" and "tde" -> "tdenew" (subject to the old value) within one command only using
   exiftool -xmp-dc:title-="t" -xmp-dc:title="tnew" "-xmp-dc:title-de<$xmp-dc:title-de"
            -xmp-dc:title-de-="tde" -xmp-dc:title-de="tdenew"

Thanks in advance.
Herb

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16702
    • ExifTool Home Page
Re: Question: replacing tag-content using the -= mechanism
« Reply #7 on: May 17, 2010, 07:28:57 AM »
The command
   exiftool -xmp-dc:title-="t" -xmp-dc:title="tnew"
works fine for tag xmp-dc:title and in case of the old value was "t" also all language-sub-tags e.g. title-de are removed.

Interesting.  This is the way it is supposed to work, but I discovered a bug in 8.19 where other languages aren't removed as they should be when conditionally writing a tag with no lang code like this.  I was going to fix this in the next release.  From the XMP tag name documentation:

" A lang-alt tag with no language code accesses the "x-default" language, but causes other languages for this tag to be deleted when writing. The "x-default" language code may be specified when writing to preserve other existing languages (ie. "XMP-dc:Description-x-default"), but note that other languages are still deleted if the "x-default" language is deleted."

So write XMP-dc:Title-x-default if you want to keep the other languages.

Quote
Question to your announced corrections:
Can I exchange the values "t" -> "tnew" and "tde" -> "tdenew" (subject to the old value) within one command only using
   exiftool -xmp-dc:title-="t" -xmp-dc:title="tnew" "-xmp-dc:title-de<$xmp-dc:title-de"
            -xmp-dc:title-de-="tde" -xmp-dc:title-de="tdenew"

This is the way:

exiftool -xmp-dc:title-x-default-=t -xmp-dc:title-x-default=tnew -xmp-dc:title-de-=tde -xmp-dc:title-de=tdenew ...

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

herb

  • ExifTool Freak
  • *****
  • Posts: 346
Re: Question: replacing tag-content using the -= mechanism
« Reply #8 on: May 18, 2010, 12:20:12 PM »
Hello Phil,

thank you very much for the detailed answers based on facts.
Herb