add tag if it does not already exist/have value

Started by Versil, September 24, 2012, 07:36:31 PM

Previous topic - Next topic

Versil

I am trying to generate xmp data for files of any type (with or without metadata) without modifying the original.  I am able to insert new data such as dc:subject and dc:source.  However, I would like to provide values for some tags if and only if they do not already have a value.  CreateDate is a good example, though not the only.  Any Help would be greatly appreciated!

The basic command line I am using is this:
exiftool -tagsFromFile @ -title='Working Set 1' -subject='Anna'  -o %d%f_%e.xmp .

After reading this thread:  https://exiftool.org/forum/index.php?topic=3290.0 , I tried this:
exiftool -tagsFromFile @ -title='Qorking Set 1' -subject='Anna' -createdate=2012:12:12 -createdate-=  -o %d%f_%e.xmp .

While this inserts the date properly in files which do not have a date; it also overwrites the date in those that do.

Did I miss something?

Thanks.

-Versil

Phil Harvey

Hi Versil,

The problem is that the -TAG-=VALUE syntax has a different meaning for date/time tags.  For these, -= is used to shift the time backwards.  However, if no value is given then it doesn't make sense to shift the time.  In that case, maybe I could make exiftool write the value only if it doesn't exist (as with non-date/time tags).  I'll look into this.

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

Versil

#2
Thanks for the quick response.  That explains it.  It does work properly for non datetime  tags.  What if there was simply a command line option for shift/noshift behavior?  Or all tag values are treated as text (no shifting available) unless wrapped in parens?

Realizing these examples don't make sense on their own...
-createdate+=(2012:12:12)    would treat the date as a date, not as a text field.
-createdate+=2012:12:12    would treat the date as textual value for the field.

-Versil

Phil Harvey

I'll have to think about this.  I like your idea brackets if I can make it backward compatible.

The complication is that the += and -= operators have been overloaded to have more meanings than just this:

1) List-type tags: += adds list item, -= deletes list item

2) Numerical-valued tags: += increments value

3) Date/time tags: += shifts date/time forward, -= shifts date/time backward

4) Non-date/time and non-list tags: -= used for conditional deletion/replacement

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

Versil

To help maintain backwards compatibility, how about using something like double quotes or double-single quotes to force textual evaluation; otherwise, treat the value as whatever its special datatype may be.

Regarding the current implementation; is there a way to achieve what I want using ifs?

-Versil

Phil Harvey

Hi Versil,

What is ifs?  If you're talking about using the API, then yes, this should be possible.

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

Versil


Phil Harvey

Ah.  Yes, you could process the file only if the tag doesn't exist.  But this is all or nothing, so you could only do one tag at a time like this.

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

Phil Harvey

Hi Versil,

I finally got around to working on this.  I was a bit surprised to discover that it already works for me!:

> exiftool a.jpg -createdate
Create Date                     : 2012:08:10 18:59:27

> exiftool a.jpg -createdate-= -createdate=2012:12:12
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:CreateDate (PrintConvInv)
    0 image files updated
    1 image files unchanged

> exiftool a.jpg -createdate-= -createdate="2012:12:12 12:00:00"
    0 image files updated
    1 image files unchanged

> exiftool a.jpg -createdate=    1 image files updated

> exiftool a.jpg -createdate-= -createdate="2012:12:12 12:00:00"
    1 image files updated

> exiftool a.jpg -createdateCreate Date                     : 2012:12:12 12:00:00


The only difference from what you were doing is that I had to use a full date/time value.  If you didn't get a warning with your command, perhaps it is because you were using a very old version of ExifTool.  In this case, maybe simply updating to the current version will get you going with this.

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

herb

Hello Versil and hello Phil,

I followed your discussion and have an additional question.
Is it possible that the "problem" depends on the sequence:
- Versil used: -createdate=value -createdate-=
- Phil used:    -createdate-= -createdate=value

Best Regards
Herb

Phil Harvey

Hi Herb,

Good idea, but this order should not matter.  I tried it just to be sure and it works both ways for me.

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

shiregator

Hi Phil,

Is there anyway to add all tags except for ones that already exist/have value?  The following overwrites all tags in the destination.

exiftool -tagsFromFile src.cr2 dst.jpg

Thanks so much for this exceptional tool.

Regards,
Jamie

StarGeek

Take a look at the -wm (writemode) option.  I regularly use -wm cg to write only new tags and not to overwrite existing tags.
* 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).

shiregator

Thanks StarGeek!  That's working via command line:

exiftool -wm cg -tagsFromFile src.jpg dst.jpg

But if I run it from are args file I get "Invalid TAG name: wm cg".  How can I run that from within an args file?

exiftool -stay_open true -@ "..\args"


Here is my args file:

-echo
**START** 883db520-a093-4e23-b834-fed5dcbf6f1d
-overwrite_original
-ver
-wm cg
-tagsFromFile
src.jpg
dst.jpg
-execute
-echo
**STOP** 883db520-a093-4e23-b834-fed5dcbf6f1d
-execute
-echo
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-execute

-execute
-stay_open
false



StarGeek

From the docs on the -@ (Argfile) option:
        The file contains one argument per line (NOT one option per line -- some options require additional arguments, and all arguments must be placed on separate lines).

In an arg file it would be
-wm
cg
* 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).