Author Topic: Writing substring into IPTC:Headline, half way there?!  (Read 1580 times)

odolphie

  • Newbie
  • *
  • Posts: 3
Writing substring into IPTC:Headline, half way there?!
« 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
Code: [Select]
/.{1,}_(.{1,})_.{1,}(\.jpg)/i
Code: [Select]
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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16727
    • ExifTool Home Page
Re: Writing substring into IPTC:Headline, half way there?!
« Reply #1 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
...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 ($).

odolphie

  • Newbie
  • *
  • Posts: 3
Re: Writing substring into IPTC:Headline, half way there?!
« Reply #2 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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16727
    • ExifTool Home Page
Re: Writing substring into IPTC:Headline, half way there?!
« Reply #3 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
...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 ($).

odolphie

  • Newbie
  • *
  • Posts: 3
Re: Writing substring into IPTC:Headline, half way there?!
« Reply #4 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:

Code: [Select]
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)