Author Topic: Writing Keywords  (Read 1586 times)

irinaonline

  • Full Member
  • ***
  • Posts: 30
Writing Keywords
« on: June 20, 2017, 06:28:32 AM »
It seems, I have a bit of a problem with understanding, when I have to set correctly a ' or a " or a $ to point to a tag. Also it is a little bit unclear, when to use < and when =.

May you please help me to correct this command line, so that it works?

I am trying to write keywords and spaces or words without $ should be a text and all with leading $ should refer to a field.

-sep ", " -m "-Keywords=All,All Sync %ETV%,$CountryCode,$Country,$State,$City,$Location,$SupplementalCategories,$ISO,$Make $Model $BodySerialNumber,$Lens $MakeLensModel $LensSerialNumber,$ImageWidthx$ImageHeight,$FileType,f/$FNumber,$GPS:GPSAltitude $GPS:GPSAltitudeRef,$GPS:GPSLatitudeRef latitude,$GPS:GPSLongitudeRef longitude,Orientation $Orientation,Flash $Flash,Focal Length $FocalLength,$ShutterSpeed s,GPS Speed $GPS:GPSSpeed $GPS:GPSSpeedRef,Orientation $Orientation,Software $Software,Exif Version $ExifVersion,$Regionname"

As a plus it should check, if this tags are already written and only add them, if they are not there. I had no luck with NoDupe so far.

Thank you for your effort!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14162
    • ExifTool Home Page
Re: Writing Keywords
« Reply #1 on: June 20, 2017, 07:26:43 AM »
The "=" writes a literal string value to a tag.

The "<" copies (redirects) the values of other tags (which may be embedded in a string with leading "$" symbols).

On Windows, you need double quotes around the "<".  On Mac/Linux you must use single quotes around any "$" symbol.

And see FAQ 17 for how to prevent duplicate entries.

So your command would look something like this (on Windows):

-sep ", " -m -addtagsfromfile @ "-Keywords-<All,All Sync %ETV%,$CountryCode,$Country,$State,$City,$Location,$SupplementalCategories,$ISO,$Make $Model $BodySerialNumber,$Lens $MakeLensModel $LensSerialNumber,$ImageWidthx$ImageHeight,$FileType,f/$FNumber,$GPS:GPSAltitude $GPS:GPSAltitudeRef,$GPS:GPSLatitudeRef latitude,$GPS:GPSLongitudeRef longitude,Orientation $Orientation,Flash $Flash,Focal Length $FocalLength,$ShutterSpeed s,GPS Speed $GPS:GPSSpeed $GPS:GPSSpeedRef,Orientation $Orientation,Software $Software,Exif Version $ExifVersion,$Regionname" "-Keywords+<All,All Sync %ETV%,$CountryCode,$Country,$State,$City,$Location,$SupplementalCategories,$ISO,$Make $Model $BodySerialNumber,$Lens $MakeLensModel $LensSerialNumber,$ImageWidthx$ImageHeight,$FileType,f/$FNumber,$GPS:GPSAltitude $GPS:GPSAltitudeRef,$GPS:GPSLatitudeRef latitude,$GPS:GPSLongitudeRef longitude,Orientation $Orientation,Flash $Flash,Focal Length $FocalLength,$ShutterSpeed s,GPS Speed $GPS:GPSSpeed $GPS:GPSSpeedRef,Orientation $Orientation,Software $Software,Exif Version $ExifVersion,$Regionname"

Here I have had to specify -addTagsFromFile to be able to combine two copy operations on the same list-type tag.

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

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #2 on: June 20, 2017, 07:48:41 AM »
perfect. thank you so much! it works :-)

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #3 on: June 20, 2017, 08:09:07 AM »
and how can i write the year from datetimeoriginal in the format YYYY as a keyword?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14162
    • ExifTool Home Page
Re: Writing Keywords
« Reply #4 on: June 20, 2017, 08:16:14 AM »
add -d %Y to your command and use "$datetimeoriginal" in your string.

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

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #5 on: June 20, 2017, 08:29:38 AM »
-d "%%Y%%m%%d %%H%%M%%S" is used in the same command to rename the file.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14162
    • ExifTool Home Page
Re: Writing Keywords
« Reply #6 on: June 20, 2017, 09:02:31 AM »
Then use ${datetimeoriginal#;s/:.*//} in your string.

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

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #7 on: June 20, 2017, 10:14:44 AM »
Thank you! Is there a function like PROPER() which capitalizes the first character in each word of a string?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14162
    • ExifTool Home Page
Re: Writing Keywords
« Reply #8 on: June 20, 2017, 10:29:49 AM »
For an individual tag, you could do this in the string: ${TAG;s/\b([a-z])/\u$1/g}

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

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #9 on: June 20, 2017, 02:27:09 PM »
that is a very easy to remember syntax.

may i ask you, how i could combine and's and or's?

how can i optimize this syntax (or that it works at all)?

-if "$Filename =~ /1S/i and ($SupplementalCategories =~ /R1102/i OR $SupplementalCategories =~ /R1170/i OR $SupplementalCategories =~ /R1103/i OR $SupplementalCategories =~ /R89052/i OR $SupplementalCategories =~ /R89110/i OR $SupplementalCategories =~ /R89129/i OR $SupplementalCategories =~ /R89130/i OR $SupplementalCategories =~ /R89145/i)"

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2257
Re: Writing Keywords
« Reply #10 on: June 20, 2017, 05:06:59 PM »
I played around with your data and Regexp::Assemble and it comes up with
(?:R(?:89(?:1(?:[13]0|29|45)|052)|11(?:0[23]|70)))

So you could use
-if "$Filename =~ /1S/i and $SupplementalCategories =~ /(?:R(?:89(?:1(?:[13]0|29|45)|052)|11(?:0[23]|70)))/i"

Regex101 example
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #11 on: June 20, 2017, 06:03:22 PM »
i would love to understand this at some point, but this seems to pretty difficult or add new codes, as these were just examples and i need to add around 15 more job codes.

with the link you provided, a new regex will be created?

i added some codes, but the regex code did not update.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2257
Re: Writing Keywords
« Reply #12 on: June 20, 2017, 06:57:21 PM »
i would love to understand this at some point, but this seems to pretty difficult or add new codes, as these were just examples and i need to add around 15 more job codes.

Yeah, it's would be very difficult to add new stuff to that.  That answer was compiled specifically for the data you gave.  As for understanding, if you follow the link, in the upper right it gives a step by step breakdown, but it requires you know something about RegEx first.

Quote
with the link you provided, a new regex will be created?

No, it just shows an example of what it matches.

If you want something that you can extend, try this:
-if "$Filename =~ /1S/i and $SupplementalCategories =~ /R1102|R1103|R1170|R89052|R89110|R89129|R89130|R89145/i"

To add more codes, add a pipe charcter | and then the new code.  For example, if your new code was R89177 then you would end up with
-if "$Filename =~ /1S/i and $SupplementalCategories =~ /R1102|R1103|R1170|R89052|R89110|R89129|R89130|R89145|R89177/i"
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

irinaonline

  • Full Member
  • ***
  • Posts: 30
Re: Writing Keywords
« Reply #13 on: June 20, 2017, 07:12:06 PM »
this looks far better and easier to read and maintain. thank you very much for your time!