Miscellaneous ExifTool related questions (and information)

Started by mpegleg, June 26, 2019, 07:38:14 AM

Previous topic - Next topic

mpegleg

EDIT: This post content was moved to a new topic in Bug Reports [here], as suggested.

Phil, if it's useful to you, let me know, and I'll pass on any other minor typos that I may find, but overall, your documentation is already extremely well proofread... (So much so, that I think I deserve a prize for spotting that one). ;)

Regards,
-Paul
OS: Windows 11 Pro

Phil Harvey

Hi Paul,

Great!  I love it when people read the documentation!

Yes, please let me know of any other typos that you find.  Maybe start a new thread in the bug report section for these.

And you get a gold star for every typo you find.  One star for you so far... :)

- 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

EDIT: Ok, I'm going to scrap this previously TLDR question, because I now understand what Hayo is getting at in reply#8
OS: Windows 11 Pro

Hayo Baan

Have you looked at the -p and -testname options? These allow you to show results without altering the file.
Or, isn't your problem completely solved with -if? Looks like you simply want a conditional execution, or do I misunderstand your question?
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Hi Hayo. Yes I looked at the -testname option. It's getting close to what I want, but I think it's possibly a bit limited. I can't see how I can use it to pipe the Regex expression into it and temporarily store it. I think all it does, is display output??

As explained in my last edited paragraph above, this may well be the best option for me, as the SSD will make any temp "throwaway" write operations extremely fast. I'm working on it now. So far so good.
OS: Windows 11 Pro

Hayo Baan

Re-reading the question, I'm puzzled as to why -if doesn't work; it can have a complete Perl expression as condition, so this should allow you to fully do what you want.
Can you elaborate on the condition you want to express?
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Quote from: Hayo Baan on July 06, 2019, 02:07:57 AM
Or, isn't your problem completely solved with -if? Looks like you simply want a conditional execution, or do I misunderstand your question?

No, I'm already using many combined -if operations with -execute ops.

I think the solution may well be in the temp SSD file using the -srcfile option.

Hayo. It's tricky to explain, without seeing the full code, which I will show you soon if this fails to work, otherwise, everything's ok. The problem is that the -if conditions are all requiring a tag write operation, which I'm trying to avoid, but I might be missing something here, in my not understanding Perl very well.

Stay tuned. I'll test what I'm working on now, and get back to you, and perhaps then, you will be able to give me a better option. Thanks :)
OS: Windows 11 Pro

mpegleg

Hayo. The -if operations all work, and work very well, however I can't see a way to make them work without using the "<" operator which will always write to the file.

The majority of my images don't need any tags written to, (and I want them to remain untouched if possible) but in order to manipulate and check the filename using an -if op, I seem to have to write the data to a tag first. Is that not always the case?

eg. -comment < ${filename; $_ =~......


Anyway, I'll keep persevering for the time being and show you the reason soon.
OS: Windows 11 Pro

Hayo Baan

I don't understand; the if (when the condition fails) will prevent the command from being executed, so there won't be a write (or whatever you do). It furthermore doesn't need to be a write command, anything will work. -filename -if xxx will only display the filename if condition xxx has been met.
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Ah. I see what you're saying. Let me ponder this some more. :)

With some more movement of the ol' grey matter... I think that two subsequent -if option statements should do what I want. I'll look into that later. Right now I'm very intrigued by some weird undocumented behaviour of the -srcfile option. Interesting... but also very bewildering. I'll explain later, after much experimentation. ;)
OS: Windows 11 Pro

mpegleg

Ok. Let's scrap all that previous stuff. lol

Here's the problem code:

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

For these following examples, assume the filename has a DateTimeOriginal Year=2018.

These three examples work correctly as expected:

image.jpg  ---> image. 2018
2019-04-22 15-33-14 test1 [PIX123456] abc modx edit1.jpg   ---> abc. 2018
test 123 modx.jpg ---> test 123. 2018


However, if the filename is:

image [PIX123456].jpg ---> .2018   <--- Don't want this file updated. The tag should be left as it is.
2019-04-22 15-33-14 test1 [PIX123456] modx edit1.jpg ---> .2018   <--- and this too.

These should actually be empty because there is no data after [PIX123456], (or before modx) so there is no need to update the tag, and the file should not be touched.


So, I think I will also need an -if statement so that the file won't be updated if the result will be blank (or should be blank) when the filename has nothing after the PIX code. So the complication arises in that normally the tag will be updated, unless like in this case, the filename has nothing after the PIX code, in which case do nothing for this particular file.

ie. If the filename does not end with [PIX......] (including the modx exceptions  ;) ) then do the tag operation.

I'm trying to avoid unnecessary file write operations if possible, as there are thousands of images on my NAS, and the majority won't require tag updating, as they won't be captioned yet. Thus they will still be be of the "image [PIX123456].jpg" or "2019-05-01 12-05-32 [PIX123456].jpg" filename variety.


Note: It doesn't matter how long or complicated the syntax is, because I'm using various arg files to hide store all this code.
OS: Windows 11 Pro

Hayo Baan

That shouldn't be to hard: I think this -if will do what you need:
-if "$filename =~ /(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/ && $1 !~ /^\s*$/"
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

Oh, I see, if it didn't contain PIX then you also want it to succeed:
-if "$filename !~ /\[PIX\d+\]/ || ($filename =~ /(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/ && $1 !~ /^\s*$/)"
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Quote from: Hayo Baan on July 06, 2019, 07:22:40 AM
Oh, I see, if it didn't contain PIX then you also want it to succeed:
-if "$filename !~ /\[PIX\d+\]/ || ($filename =~ /(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/ && $1 !~ /^\s*$/)"

Yes, sorry! I have lots of different scenarios now, with many options depending on various flags that I've set up in another tag.

This will be the major most common one though, as there are no directories required in the output data.

Although it's rare, I still have a few filenames without the PIX code. Mainly very old historical scanned photos, with dates only approximated.




Unfortunately with your code from Reply#12, all filenames seem to be failing the condition??

Try it first with "image.jpg" because that should pass the condition.

I really appreciate your help with this Hayo. It's had me struggling for days.

The old code I was using worked whereby it would come back and clear the tag if it finally resembled ". 2018", but I wasn't happy with this because it meant two updates, and I really want to avoid any writes or updates of the file if the tag is going to end up (or "should" end up) empty.

Also, any updated files always lose their hidden status. *sob* :'(
OS: Windows 11 Pro

Hayo Baan

Don't know what is going wrong (I guess its the $1 that is not working inside the exiftool -if as in normal Perl it worked), but with a little bit of tinkering I've been able to come up with a slightly simpler one that should work:
-if "($filename !~ /\[PIX\d+\]/ || $filename =~ /(?:.*\[PIX\d+\]\s*)?\s*(?:(?!modx)[\S*]+)/)"
Hayo Baan – Photography
Web: www.hayobaan.nl