Miscellaneous ExifTool related questions (and information)

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

Previous topic - Next topic

mpegleg

Seems to be the exact opposite now.

ie. All filenames are passing the condition.

These should fail, but they are currently passing:

2018-08-11 11-43-21 [PIX761807].jpg

2019-04-22 15-33-14 test1 [PIX123456] modx edit1.jpg

image [PIX123456].jpg
OS: Windows 11 Pro

Hayo Baan

Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Unfortunately that didn't work Hayo... but I'm super excited because I worked it out. This works! :)

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

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




Thanks for your help Hayo. Sorry, it was a hard one to fully explain what I was after,... but all's well that ends well.  :)

It's using most of your previous code anyway! ;)

My main initial problem was that I couldn't get any Regex code to work with the -if option, so I assumed (wrongly) that it "had" to be done via the "<" operator with tags. Now that it finally works, I feel I've jumped a major hurdle in my understanding. I'm tired, but also very happy. It's true... persistence pays off.
OS: Windows 11 Pro

mpegleg

Now, to finally finish this all off, I just need a couple of "hopefully" easy Regex fixes please.

They all have some leading spaces that I would rather not have.

They are variants of the other cases, and Windows doesn't show them in the Explorer columns which is why I never even noticed that they were there, until I checked via ExifTool.

eg).

#1:

2009-02-22 13-38-06 Test 11 [PIX749502].jpg

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

======== D:/Photos/2009/2009-02-22 Europe River Cruise/2009-02-22 Amsterdam, Netherlands/2009-02-22 13-38-06 Test 11 [PIX749502].jpg
XP Comment                      :  [Amsterdam, Netherlands, 2009]
Comment                         :  [Amsterdam, Netherlands, 2009]


This results in a single unwanted blank space at the start of the output result "if" the filename has nothing after the [PIX......]




#2:

2009-02-22 13-38-06 Test 12 [PIX749502].jpg

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


======== D:/Photos/2009/2009-02-22 Europe River Cruise/2009-02-22 Amsterdam, Netherlands/2009-02-22 13-38-06 Test 12 [PIX749502].jpg
XP Comment                      :     (Sun. Feb 22, 2009)    [Europe River Cruise]
Comment                         :     (Sun. Feb 22, 2009)    [Europe River Cruise]


...and this one has 4x leading blank spaces that I don't want.

Obviously I am inserting these into the strings because normally if the filename had a text caption string, the padding "would" be needed, but in the cases like these where they aren't needed, I need to chop them off again after they've been processed. Once again, I do want to avoid any unnecessary writes to the tags unless required.

So I'm not sure if that can be easily done with Regex, or whether I'd need to use another -if option command?

Perhaps I need a separate -if condition first, to work out whether to add the spaces or not? Not sure how best to do this.


Regards,
-Paul

ps. I worked out how to search for the leading spaces with say: /\s+/ but I'm not too sure how to then "remove them", nor how to incorporate that code into the whole string.

This is how it all looks with test files after automatic processing by ExifTool. All controlled by the Copyright Flags. Note how Windows Explorer is too smart for it's own good, and doesn't show the leading spaces in the Comments. It obviously doesn't matter here, but on a vertical captioned photo where space is at a premium, it sure does.

OS: Windows 11 Pro

StarGeek

Trim leading spaces
s/^\s+//

Trim trailing spaces
s(\s+$)()

Trim leading and trailing spaces
s(^\s+|\s+$)()g
Note the g (global) is necessary because otherwise it would only do one or the other.  I used parens instead of slashes in the second two expressions because $/ is interpreted as a new line in a tag redirection (see FAQ #21d).

Just make that your last regex before the closing brace.
* 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

Thanks StarGeek,

but it didn't seem to work for me, probably because I placed it in the wrong location (more than likely!)

Would you mind modifying one of my codes with it.

Cheers
-Paul
OS: Windows 11 Pro

StarGeek

Ah, I see the problem.  You have a leading space before the Directory part.  If Filename is empty, that's when what would normally be a space between the two parts becomes a leading space.  So my regex doesn't apply to this.

Try changing the first part to
${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +//g;s/ +$//;$_.=' '}
And removing the space just before [${directory;

No, that won't work. 
Hmmm...
* 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

Thanks StarGeek, but would you mind just popping that into a code box, just so I can make sure I get it all correct.

Thanks!  :)

I can't wait to get this going. I think it's the last bit of code I need.

ps. Awww. Your code looked a little bit sad  ?:(?    :P
OS: Windows 11 Pro

mpegleg

Quote from: StarGeek on July 07, 2019, 03:31:39 PM
No, that won't work. 
Hmmm...

ok. No worries mate. I'll leave it with you to ponder.

Cheers,
Paul  :)
OS: Windows 11 Pro

StarGeek

I think it might just be easier to run a trim spaces after the first run

exiftool -api "Filter=s(^\s+|\s+$)()g" -if "$Comment ne $Comment#" -TagsFromFile @ -Comment FileOrDir
* 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

Hmmm. Thanks again StarGeek. It's interesting to learn of that way of after-processing the result. I might have to delve deeper into these -api options later. They look interesting.

But, and it's a big but... running another exiftool command won't really be practical for me, in the way I've got things set up now. I've also got well over 43000 images on my rather slow NAS, that already takes f-o-r-e-v-e-r to process in just one run, let alone two. (Although it will be considerably faster now that I've cut down the amount of unnecessary tag writing).

So, any chance that there might be a possibility of successfully modding this initial code to strip the spaces?

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

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

Perhaps Hayo/Phil might also be able to offer some suggestions as well. Here's hoping we can crack this. Thanks.
OS: Windows 11 Pro

StarGeek

Sorry I couldn't be more helpful, it's just your command line has gotten to complex and too many edge cases for me to pick it apart and figure out what it's doing.

Quote from: mpegleg on July 07, 2019, 04:52:14 PM
It's interesting to learn of that way of after-processing the result. I might have to delve deeper into these -api options later. They look interesting.

One thing that this command will do is only process files in which there was a change.  The -api filter affects every tag, so it may not be the best use if you are dealing with more than one tag.  But I figured out that doing this puts the regex (and other stuff) in one spot and helps prevent typos when using an IF option and modifying a tag.  Too many times I would end up with one thing in the IF and another thing in the tag.  The "$TAG ne $TAG#" compares the TAG modified by the filter ($TAG) to the original value ($TAG#, see the -n (printConv) option).
* 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

No need to apologize, as you've been tremendously helpful to me StarGeek, through my whole evolution of this solution to my photo captioning project. Together with both Phil & Hayo, you've all been tremendously accommodating and patient.

I'm so happy I've got this far, yet it does feel like I'm kind of stuck on the cusp of looking for that elusive "final" piece to the 10000 piece jigsaw puzzle (which is usually hiding under the couch, or, the family pooch has eaten it!) ;D.

Yes, the commands certainly are getting complex now, and it does make it very tricky. It may not matter too much with those few extra spaces anyway, and I may just cut them down a few, so they won't be as noticeable. In those few cases where the captions are just a tad too long to fit onto a single line on a vertical photo, I can just manually edit anyway.

I certainly didn't want to underrate your help in any shape or form, yet at the same time I also didn't want Hayo or Phil to not offer their input, by feeling that we've totally nailed the best solution.


Cheers,
-Paul.
OS: Windows 11 Pro

mpegleg

Wow! The solution turned out to be incredibly simple.

After much testing and brainstorming, I realised that in this case where it will be using the directory names to create the captions, it will ALWAYS require a tag write, so that makes it so much simpler...

It works for both cases of naming using the Parent and/or Current Directory names. It also only updates tags when necessary.

Here's the one for using the Current Dir only (from an arg file)...

-if
substr($Copyright,1,2) eq '0C'
  <-- My test in this particular arg file, to see if I want to include Current Directory name.

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

-execute

-if
substr($Copyright,1,2) eq '0C'

-xpcomment<${xpcomment;s(^\s+|\s+$)()g}
  <--- Yes, I did make use of the amazing magical StarGeek Filter code ;D Thank you!


So, it looks like I've pretty much got this all wrapped up now.

Thanks again to everyone for your help,
-Paul

:) ;) :D ;D 8) ************* Party time ************* :) ;) :D ;D 8)
OS: Windows 11 Pro

mpegleg

Hello.

Could somebody please help me with a Regex expression required to achieve the following:

Filename:

2018-11-07 1428 This is a test.jpg


I would like the first 15 characters rearranged as a string, and then entered into the comment tag exactly as follows:

2018:11:07 14:28:00+08:00


Note: I know it might be unusual, but right now while I'm testing, I'd much prefer not to do any "fancy" date manipulation just yet.

For now, I'd just like a straight literal text manipulation from the filename into the tag.


Many Thanks,
-Paul
OS: Windows 11 Pro