ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Versil on September 24, 2012, 07:36:31 PM

Title: add tag if it does not already exist/have value
Post by: Versil on September 24, 2012, 07:36:31 PM
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
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on September 24, 2012, 07:49:34 PM
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
Title: Re: add tag if it does not already exist/have value
Post by: Versil on September 24, 2012, 08:36:37 PM
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
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on September 25, 2012, 08:19:50 AM
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
Title: Re: add tag if it does not already exist/have value
Post by: Versil on September 26, 2012, 12:48:34 PM
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
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on September 26, 2012, 12:55:08 PM
Hi Versil,

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

- Phil
Title: Re: add tag if it does not already exist/have value
Post by: Versil on September 26, 2012, 01:01:08 PM
Sorry.  Meant -if statements
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on September 26, 2012, 01:06:27 PM
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
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on September 30, 2012, 06:57:58 AM
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
Title: Re: add tag if it does not already exist/have value
Post by: herb on October 01, 2012, 05:25:38 AM
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
Title: Re: add tag if it does not already exist/have value
Post by: Phil Harvey on October 01, 2012, 07:12:30 AM
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
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on October 28, 2018, 12:30:56 AM
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
Title: Re: add tag if it does not already exist/have value
Post by: StarGeek on October 28, 2018, 01:27:10 AM
Take a look at the -wm (writemode) option (https://exiftool.org/exiftool_pod.html#wm-MODE--writeMode).  I regularly use -wm cg to write only new tags and not to overwrite existing tags.
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on October 28, 2018, 02:02:57 AM
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


Title: Re: add tag if it does not already exist/have value
Post by: StarGeek on October 28, 2018, 02:20:33 AM
From the docs on the -@ (Argfile) option (https://exiftool.org/exiftool_pod.html#ARGFILE):
        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
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on October 28, 2018, 01:58:47 PM
Thans again StarGeek, that works great!


-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

-stay_open
false
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on November 21, 2018, 10:51:17 PM
-wm cg does not seem to work for .mp4 files (the file remains unchanged).  If I remove the write mode (-wm cg) it does write the EXIF tags to the target .mp4 file properly. 

Is this expected/known behavior?  I've tried version 11.20.

Thanks!
Title: Re: add tag if it does not already exist/have value
Post by: StarGeek on November 22, 2018, 04:33:58 PM
What tag are you trying to write, because it's very rare for a mp4 to have an EXIF tag.
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on November 22, 2018, 07:21:52 PM
Hi StarGeek,

Maybe I shouldn't have used the term "EXIF" then (I thought that was just the general group for all tags)?  I'm just trying to copy all the missing tags from "file1.mp4" to "file1_edited.mp4".  When I use my video editor it drops some of the tags, so I just want to add them back after editing. 

Thank you.
Title: Re: add tag if it does not already exist/have value
Post by: StarGeek on November 22, 2018, 08:15:45 PM
All Exif is metadata, but not all metadata is Exif.  See the Tag Names page (https://exiftool.org/TagNames/).

Overall, exiftool has limited ability to write to video files.  Mostly just XMP metadata and a few Quicktime tags.  From what Phil has said, video metadata is poorly documented.

What tags are you trying to copy over?
Title: Re: add tag if it does not already exist/have value
Post by: shiregator on November 22, 2018, 08:24:39 PM
Every tag that exists in "file1.mp4" that does not exist in "file1_edit.mp4".


-echo
**START** 883db520-a093-4e23-b834-fed5dcbf6f1d
-overwrite_original
-ver
-wm
cg
-tagsFromFile
file1.mp4
file1_edit.mp4
-execute
-echo
**STOP** 883db520-a093-4e23-b834-fed5dcbf6f1d
-execute
-echo
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------