Extracting part of a Windows JPG filename and copying into an Exif tag

Started by mpegleg, June 14, 2019, 01:48:36 AM

Previous topic - Next topic

mpegleg

Thank you. I can see... in the future... I'm going to have to learn Perl. ;)

It looks like it would certainly be helpful in getting the most out of ExifTool.
OS: Windows 11 Pro

mpegleg

This is no biggie at all, but when I use the "-if" option, I get the standard console notifications when the condition fails.

eg).

"138 files failed condition"


Now that's all fine and good, because everything is working as it should, but I'd prefer to not even see those messages at all, and just have these messages:

"138 image files updated"


Is it possible to suppress them somehow, or do I just need to suck it up, be a man, and ignore them? ;)
OS: Windows 11 Pro

Phil Harvey

You can use -q to suppress all the messages, but there is no option to suppress just some of them.

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

mpegleg

OS: Windows 11 Pro

mpegleg

After all the incredible help you good people at ExifTool Forum have provided me, I thought it's only fair that I showed you the end result. Two weeks ago, I'd never heard of ExifTool. (I know... shame on me :-[)

Nor did I really know much about metadata. In two weeks, even though I still can't understand much of the gobbledegook of the commands (esp. Regex!), I feel that I have achieved more than I could possibly have hoped for, with the automation of my file and tag renaming requirements.

Here's a short real-time demo video I just created (Using ExifMixer running ExifTool) of what I have achieved so far. Feel free to offer any further advice, code changes, etc.

Note that ExifMixer allows the use of multiple lines for the various options, which makes it far easier to read the command line syntax.


     https://www.youtube.com/watch?v=4UsanggFUBk


   

The specific tag output names are all created based on the contents of the Windows "Copyright" tag info. I know that's not ideal, but I needed a tag whose properties were very easily changeable and visible in Windows Explorer's columns. I personally don't normally make use of the Copyright tag, because obviously my photos are just personal family snaps, and I have no other need for it. Even if it gets clobbered by other editing programs, it would be no big deal, and I could always recover and copy it back from another duplicated tag, that might be a bit more robust and unused.

The H represents files that are "Hidden". Unfortunately as you'll see (and has been discussed here) any writing operation performed by ExifTool will "Unhide" the file status. I hide all my original images (that have a corresponding unhidden edited file) in the same folder. This works for me. I found a workaround whereby using the Copyright tag to hold the letter "H" would represent which files needed to be re-hidden after using ExifTool. After any ExifTool writing operation, I thus would search for my *.jpg files in Explorer, re-order them in Alphabetical order based on the Copyright column, select all those, and then do a bulk Hidden-file attribute properties change, based on the info contained in the Copyright tag for those applicable files.

Too easy.


Regards,
and many thanks,

Paul  :)
OS: Windows 11 Pro

StarGeek

Quote from: mpegleg on June 22, 2019, 02:15:56 AM(esp. Regex!)

When you decide to try and figure regex out more, try copying the expression into a website like Regex101.  It will give you a step by step break down of the expression in the upper right corner and it will highlight sections of the regex and tell you what each part does as you hover over it.


QuoteThe specific tag output names are all created based on the contents of the Windows "Copyright" tag info. I know that's not ideal, but I needed a tag whose properties were very easily changeable and visible in Windows Explorer's columns.
...
Even if it gets clobbered by other editing programs,

Copyright is pretty safe.  Almost any tag in the XMP, IPTC, or EXIF group is unlikely to get destroyed or overwritten by most programs, unless you specifically tell to.  The jpeg Comment tag and a few other very obscure/rare tags are not necessarily safe.

Happy it all worked out for you.
* 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).

mpegleg

Thank you StarGeek.

Yes I discovered Regex101 the other day, along with RegExr. They will be very useful.

The only reason I need to use the jpeg comment tag is because the program I use to do the photo resizing and captioning FastStone Photo Resizer (which is perfect for doing the resizing), "only" allows a few very specific tags to contain the captions, as you can see in my attached image. Most are for the camera metadata, like Exposure settings etc, which although useful, doesn't really allow me to display my textual descriptive data like Title, Subject, and other comments.



I've tried to get in touch with the author, to suggest he expand the amount of tags one can use, but have so far been unsuccessful in getting any response back. :-\

If he was to use ExifTool in his program, (which I don't "think" he does), of course one would then have access to almost unlimited metadata tags.
OS: Windows 11 Pro

mpegleg

Phil, (totally off-topic here, but...)

I notice a little bit further down the page [here] you say:

[Unfortunately the Windows cmd shell provides no method to get a newline (CR/LF in Windows) into the command line. A linefeed (LF) may be inserted with CTRL-T, but I have found no way to insert a carriage return (CR).]

Excuse my ignorance as I'm not 100% sure that this is what you were trying to achieve here, but I thought I'd mention it just in case you weren't aware of it, as it might be important...

If you place a " ^" after the options on each line it allows you to place them on separate lines in the Windows command console.

Eg:


exiftool ^
-m ^
-overwrite_original ^
-comment="123" ^
image.jpg




executes the complete command as though it was entered on one line.

For example, the above code (and importantly including the "blank line" after image.jpg) can all be copied and pasted, and it will immediately execute upon pasting into the Console.

With the mouse, you must "click & drag upwards" from below image.jpg to allow the capture of the hidden CR/LF characters, when copying the text. (You can also mouse downwards, as long as you mouse drag below image.jpg).

Note: The space is very important before each ^ character.

So, the  ^ with a blank line included after, should be the equivalent of a CR/LF.

Possibly this is only the LF that you were talking about, rather than the CR, but it doesn't do any harm to mention it just in case.
OS: Windows 11 Pro

Hayo Baan

Unless I am mistaken, this still doesn't insert a CR (or LF) into the arguments. It only allows you to spread your command over multiple lines. When ultimately the command receives the arguments, these multiple lines are replaced by a single line (the line endings are basically just a space). On Linux/Mac this is done by ending the line with a \.
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Yeah. I think you are right. I just thought I'd mention it, "just in case", because I came across it, and had never personally seen it mentioned before. :)
OS: Windows 11 Pro

mpegleg

Hi. I hope someone can please help with the Regex code on this one.

Using the following code:

"-XPComment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +/ /g;s/ +$//}    (${DateTimeOriginal;DateFmt('%a. %b %d, %Y');s/\b0+\B//g})    [${directory; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]"

and this Windows file:

W:\Photos\2010\2010-08-08 Jewels of Europe River Cruise\2010-08-08 Amsterdam, Netherlands\
2010-08-08 21-12-43 P1030160 [PIX506764] In transit at Singapore Changi Airport.jpg

I'm getting the result with the XPComment tag as:

Waiting for flight from Singapore Changi Airport    (Sun. Aug 8, 2010)    [W:/Photos/2010/2010-08-08 Jewels of Europe River Cruise/2010-08-08 Amsterdam, Netherlands]



yet, what I'd like is:

Waiting for flight from Singapore Changi Airport    (Sun. Aug 8, 2010)    [Jewels of Europe River Cruise]


I'm still not quite sure what small modification I need to make in the last bit of the code, to achieve this.

ie. I'd like the Parent Directory name included (without the date), but I don't want the Current Directory name included, which is what I "was" requesting previously.

Note: the Parent Directory could appear anywhere eg: W:/Test/1/Photos/123/2010-08-08 Jewels of Europe River Cruise/2010-08-08 Amsterdam, Netherlands

but you can always assume that both the Parent and Current Directory Names will always be: "yyyy-mm-dd xxxxxx"


Many thanks,
-Paul

Ps. The biggest problem I'm having with trying to decipher the Regex code, is that it is, of course, a variant of the Perl Programming language, thus I can't just enter it into regex101.com and expect it to work. Very tricky, but I am trying to learn it.  :-\

EDIT: OK. I got this far using regex101

... so much to learn! :-\

Ideally I guess I want to search backwards from the last "/" until I hit the "-dd" or "-mm-dd".

So searching backwards for "-??-??" is probably more feasible. I don't know. ie. (?<=[-]......)([^\/]+)

This is getting close... (testing with digits before the "Jewels...").

OS: Windows 11 Pro

Hayo Baan

Hi Paul,

I don't understand the result you are getting at all; the last regexp $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#; should already deliver the result you're after:

perl -E '$x ="W:/Photos/2010/2010-08-08 Jewels of Europe River Cruise/2010-08-08 Amsterdam, Netherlands"; say qq{Before=$x}; $x =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#; say qq{After=$x}'
Before=W:/Photos/2010/2010-08-08 Jewels of Europe River Cruise/2010-08-08 Amsterdam, Netherlands
After=Jewels of Europe River Cruise


(to test this on windows, swap the single and double quotes).
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Thanks Hayo.

Indeed, I believe also that it should have worked, as the more complex command does, but...

I also tried it on my D: drive, which is not a network drive. Using the Windows command console, I got the exact same result:

exiftool "-XPcomment<[${directory; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]" "2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg"

D:\Photos\2010\2010-08-08 Jewels of Europe River Cruise\2010-08-08 Amsterdam, Netherlands>exiftool "-XPcomment<[${directory; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]" "2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg"

Warning: Undefined subroutine Image::ExifTool::abs_path called for 'directory' - 2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg
    1 image files updated


Note the: "Warning: Undefined subroutine..."


This ends up with:

XPComment=[.]



Note that I "should" have tested it on the command line previously, but I was actually using ExifMixer. ExifMixer gives the result (with no errors) of the whole of the path:

XPComment=[D:/Photos/2010/2010-08-08 Jewels of Europe River Cruise/2010-08-08 Amsterdam, Netherlands]




Strange thing is, the previous full (more complex) command (using either the command console, or within ExifMixer) works perfectly:

exiftool "-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +/ /g;s/ +$//;s/^(.+)$/$1 - /}${directory; use Cwd 'abs_path'; $_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}    (${DateTimeOriginal;DateFmt('%a. %b %d, %Y');s/\b0+\B//g})    [${directory; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]" "2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg"

D:\Photos\2010\2010-08-08 Jewels of Europe River Cruise\2010-08-08 Amsterdam, Netherlands>exiftool "-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +/ /g;s/ +$//;s/^(.+)$/$1 - /}${directory; use Cwd 'abs_path'; $_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}    (${DateTimeOriginal;DateFmt('%a. %b %d, %Y');s/\b0+\B//g})    [${directory; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]" "2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg"
    1 image files updated



I end up with:

XPComment=Waiting for flight from Singapore Changi Airport - Amsterdam, Netherlands    (Sun. Aug 8, 2010)    [Jewels of Europe River Cruise]
OS: Windows 11 Pro

Hayo Baan

Change the first command into exiftool "-XPcomment<[${directory; use Cwd 'abs_path'; $_ = abs_path($_); $_ =~ s#.*/[0-9-]+\s*([^/]+)/[^/]+$#$1#;}]" "2010-08-08 23-11-28 IMG_5479 [PIX610424] Waiting for flight from Singapore Changi Airport.jpg" (i.e. add use Cwd 'abs_path';).
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

OS: Windows 11 Pro