ExifTool Forum

ExifTool => Newbies => Topic started by: odolphie on August 08, 2016, 06:27:37 AM

Title: Writing substring into IPTC:Headline, half way there?!
Post by: odolphie on August 08, 2016, 06:27:37 AM
Hey,

I'm looking for some help please for a few things I need to accomplish, after trying for hours I'm close but I just can't get the first thing to work.

List of files in the format
===================
01_Pretty Feet_16A.jpg
01_A Good Shake_77B.jpg
01_A Good Shake_77A.jpg
01_Backflip_39P.jpg
01_Beethoven 5 first movement_ 70A.jpg
01_Black Star Lead Jammer_76a.jpg

I need to do a few things.
==========================
A) Write everything inside the underscores to that images headline, for example 01_Pretty Feet_16A.jpg is given the IPTC:Headline "Pretty Feet".
B) Remove number rating
C) Move the files into a folder based on the last letter of the filename, e.g. all those ending in A end in up and A folder, B in a B folder etc.

Where I've got to
==================
For A I've got the regex which works in a regex tester for capturing the headline /.{1,}_(.{1,})_.{1,}(\.jpg)/i

exiftool "-IPTC:Headline<${filename;s/.{1,}_(.{1,})_.{1,}" "01_Jemima_23A.jpg"

However when applying this using exiftool the whole file name is written, not the substring.


I'll start on B and C ones I've got A working.  C I expect I'll accomplish through a batch file although although I know exiftool can do folder moves !

Any help appreciated.
Title: Re: Writing substring into IPTC:Headline, half way there?!
Post by: Phil Harvey on August 08, 2016, 07:55:02 AM
OK, try this (I've replaced your "{1,}" expression with "+" because I think they do the same thing):

exiftool "-iptc:headline<${filename;s/.+_(.+)_.+/$1/}" "-directory<${filename;s/.+_.+_\d+([A-Z]).+/\u$1/i}" "-filename<${filename;s/_\d+[A-Z]\././i}" DIR

Note that the number rating from the file name will be lost.  Did you want this?

Be sure to run this on some test files first to make sure it does what you want.

I have used "\u" to make the folder names upper case (since one of your examples was "a" and I imagined you wanted the folder "A").

- Phil
Title: Re: Writing substring into IPTC:Headline, half way there?!
Post by: odolphie on August 08, 2016, 09:15:37 AM
That's amazing, works nearly as needed, I'd like to keep the files with the same name when moved though if possible?

The number rating I was hoping to strip was the one applied in the iptc/xmp however its trivial for this to be removed through other software.

I expect you've seen it all, but I hope this was at least an interesting one for you to write :)  I'm heading over to donate page too, amazing tool and the level of help you provide is exemplary.
Title: Re: Writing substring into IPTC:Headline, half way there?!
Post by: Phil Harvey on August 08, 2016, 05:33:39 PM
OK, just drop the argument that sets the FileName if you don't want to change the name.  I misunderstood when you said you want to remove the number rating.  I thought you meant from the file name.  You can easily remove this from the metadata if you know the tag name (ie. with -rating=).

- Phil
Title: Re: Writing substring into IPTC:Headline, half way there?!
Post by: odolphie on August 10, 2016, 04:19:16 AM
Excellent, thank you.  It works amazingly well and will save hours.  Huge thanks.

For those following along at home I ended up with:

exiftool "-iptc:headline<${filename;s/.+_(.+)_.+/$1/}" "-directory<${filename;s/.+_.+_\d+([A-Z]).+/\u$1/i}" "-rating=" DIR

(where DIR the folder with the images in)