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

StarGeek

Grab the example config file and save it in the same directory as exiftool as .ExifTool_config.  That gives you a new tag called BaseName.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mpegleg

Thanks StarGeek, but I was hoping to avoid having to use a config file (for now at least).

Is there no other way?

Also, is there an easy regex expression that would simply chop off the first 20 characters of the filename and store the remainder in the comment tag (...and of course... chop off the last 4 characters ie. the ".jpg" (without using a config file??)) ;)

eg. Filename:2019-06-14 10-32-12 This is a test.jpg

tag comment:This is a test



ps. This will probably be all that I need from exiftool and regex, as my needs are very simple, and I've almost done all the work that I needed with these handy tools.

I was hoping to avoid the use of a config file, for a couple of reasons. I use various GUI shells that mean that I'll have to remember to copy them to various folders, and most importantly also I'd love to see and learn the regex expressions that would enable these operations. :)
OS: Windows 11 Pro

StarGeek

Quote from: mpegleg on June 14, 2019, 11:42:00 PM
Thanks StarGeek, but I was hoping to avoid having to use a config file (for now at least).

Config files rock.  My base config file is about 1,800 lines long and I have multiple specialty config files for various, rarely used data.

But Basename the standard answer because it's easy and less prone to mistakes..  You can lift the code directly from the example config, but I usually like to do something like this:
${Filename;s/\.[^.]*$//}

To chop the first 20 characters would be
${Filename;s/^.{20}//}

Combined would be
${Filename;s/^.{20}//;s/\.[^.]*$//}
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mpegleg

Perfecto!

Thanks again StarGeek.

Yes, I know where you're coming from with the use of Config files, and I'll probably get into using them at a later date, but just for now I really wanted to know the base regex code that would achieve these simple operations. Now you've done that for me.

Wonderful  :)

-Paul

ps. I use ExifMixer to store all of my ExifTool and Regex chained operations, so I guess that's kind of like using a config file, but I can see where config files could simplify it all.
OS: Windows 11 Pro

mpegleg

... and if I could just ask one more favo(u)r please...

What Regex code would I use (once again without using a config file) to copy filename contents to the comment tag, minus my PIX ID and EXT?...

In other words I'd like 12 characters removed beginning with "[PIX".
(Obviously that includes removing either the the leading space before the "[", or the trailing space after the "]").

It's kind of a combination/reversal of all of the previous scenarios,...


Note: As before, only [PIXxxxxxx] is constant, yet it may appear anywhere in the filename.

eg.
Filename:Test 123 [PIX817263] xyz.jpg             

I want to end up with the comment tag containing:Test 123 xyz


I'm just not sure how to combine all of the Regex parts together.

Hopefully after this Regex 101 workout I should be able to complete most other basic scenarios on my own. 8)

Thanks again.
-Paul
OS: Windows 11 Pro

StarGeek

In the first example, that used a regex match and capture.  Instead of matching, you would just substitute with nothing.

${Filename;s/\[PIX\d{6}\] //}

Removed the parenthesis (the capture), changed the m (match) to s (substitute), added the extra space at the end of the original match, and then a final slash added to the end.  The pattern for substitution is s/SEARCHPATTERN/REPLACE/  Here, since REPLACE is empty, the pattern is basically removed.

Heading to bed now, so that's all outta me for now.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mpegleg

So combined that would be...

${Filename;s/\[PIX\d{6}\] //;s/\.[^.]*$//}

That works.

Thanks again for all your help StarGeek (and Phil of course!)

G'nite! It's the middle of the day over here in oz! :)
OS: Windows 11 Pro

Stephen Marsh

Greetings from Sydney mpegleg, although I have not tried in ExifTool, the following single regex should work – the pipe | alternator allows for more than one match (i.e. match A "or" B, where the | pipe symbol is the "or"):

${Filename;s/\[PIX\d{6}\] |\.[^.]*$//}

mpegleg

Hi Stephen. Greetings from Perth!

I tried your Regex example, but unfortunately it doesn't remove the ".jpg" extension. The tag had the correct content, but it still had the extension included.

The example that I constructed with StarGeek's help did the job. Almost. Unfortunately it still doesn't remove the PIX id if the [PIXxxxxxx] has nothing immediately after it, just before the .jpg

So this filename will work:Test 123 [PIX123456] .jpg     <---ie. it has a space (or anything else) just before the extension.

               but this doesn't:Test 123 [PIX123456].jpg





--------------------
ps. * Just on an unrelated side-note for anyone using Windows 10, beware of the icon enhancement utility called SageThumbs. I've spent the better part of the day trying to sort out why I kept getting continual Windows Blue Screens of Death (BSODs). These only started today, so perhaps an auto Windows Update has stuffed things up. Not nice. Luckily with Windows 10, I rarely get BSODs. Apparently after much uninstalling of apps, doing image restores, etc, I finally tracked it down to this utility. Useful that it is, it just isn't worth the headaches that it causes, and it r e a l l y slows down the loading of folders with many images.
OS: Windows 11 Pro

StarGeek

Quote from: Stephen Marsh on June 15, 2019, 09:48:01 AM
${Filename;s/\[PIX\d{6}\] |\.[^.]*$//}

The thing to remember here is that it will only do the first match.  If you want it to do both, you need to add the g (global) modifier
${Filename;s/\[PIX\d{6}\] |\.[^.]*$//g}

I haven't tested it though

Quote from: mpegleg on June 15, 2019, 10:28:54 AM
Unfortunately it still doesn't remove the PIX id if the [PIXxxxxxx] has nothing immediately after it, just before the .jpg

That's because regex has to be very exact.  You have to try and figure out all the edge cases ahead of time.  but in this case, it's pretty easy.  There may or may not be a space, for which there is the ? (match 0 or 1 of the previous character).

So either
${Filename;s/\[PIX\d{6}\] ?//;s/\.[^.]*$//}
or
${Filename;s/\[PIX\d{6}\] ?|\.[^.]*$//g}
should work.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mpegleg

Thanks again StarGeek.

I just tried that first example, and I'll stick with that. It worked well.

Cheers
-Paul
OS: Windows 11 Pro

Stephen Marsh

Thanks StarGeek, I did forget to include the global flag in my example, that's what comes from not testing in ExifTool! I tested using RegEx101 which by default has the G flag turned on (out of sight, out of mind). I know that ExifTool is fast and so is RegEx, so there is probably little to no practical performance hit running two sequential vs. a single RegEx.

mpegleg

I know it's unrelated but can I just ask a question here without writing a new topic, as I'm sure it's been asked before, and I feel it's going to make me look like a right ETn00b (which I am!), but I can't seem to find what seems would be so obvious.

So, please excuse my ignorance here, but I am very new to this whole ExifTool experience, and I realize the whole Tag naming thing is extremely complex...

but when I list the available tags with ExifTool, I get the "friendly tag names", but why doesn't it (or how do I?) list the actual tag names that I'd have to use to list those specific tags.

For example:

ExifTool (with no arguments entered) will list my old Panasonic Travel camera's tag details as follows:

Make                            : Panasonic    <-- Ok, so here "make" is the same as the friendly tag name
Camera Model Name      : DMC-TZ40    <-- but here, in any expressions, I'd have to already know that
                                                                    I must use "model", and not "Camera Model Name"



Is it possible to do a list that would be along the lines of:

Actual Tag Name     Friendly Tag Name          Value
-------------------    ---------------------          ------
make                     Make                            : Panasonic
model                    Camera Model Name      : DMC-TZ40



I hope that makes sense?! I just feel that I'm "missing" something here in my understanding... and I've looked at the FAQ's etc, but I'm sure I've missed that info somewhere.

ie. Not so much in my example here, but often the Friendly Name that is output, can often be very different to the tag name that I'd have to use in an ExifTool expression.



Feel free to just point me along to the relevant FAQ, documentation, or any applicable Forum Topic if possible.

-Paul
OS: Windows 11 Pro

Stephen Marsh

You are right:

exiftool DIRorFILE

results in "descriptions", not actual tag names. To get the tag names:

exiftool -s DIRorFILE

However the following may be a better approach:

exiftool -a -G1 -s DIRorFILE

https://www.exiftool.org/faq.html (#2, #3c)


https://exiftool.org/exiftool_pod.html


-a          (-duplicates)        Allow duplicate tags to be extracted
-G[NUM...]  (-groupNames)        Print group name for each tag
-s[NUM]     (-short)             Short output format



Therefore, a simple command may not reveal everything:

exiftool -tagname DIRorFILE

Worth noting, the same entry may be written to many different groups and tags, which is revealed with -a -G1 -s:

[IFD0]          ImageDescription
[XMP-dc]        Description
[IPTC]          Caption-Abstract


This is often the case with programs that are writing to both current (XMP-dc) and legacy (IPTC) metadata fields/tags, such as with Adobe apps.

https://exiftool.org/TagNames/index.html

https://exiftool.org/TagNames/MWG.html

So you can write just using the "shorthand" tag name:

exiftool -subject='foo' DIRorFILE

To avoid being ambiguous, you can use both the group and tag to be very explicit, which should only be an issue if there were conflicting tag names in different groups... I personally often prefer to use the "longhand" version with both group and name:

exiftool -XMP-dc:Subject='foo' DIRorFILE

mpegleg

Stephen. Many Thanks.

I just knew there had to be a (ton of) switch(es) for it.


exiftool -a -G1 -s DIRorFILE is much more useful for me! Perfect.


All I need now is an ExifTool switch that will automatically turn on my coffee machine. Hmmm. Is there a (hidden?) switch for that? Probably... wouldn't surprise me... or if not... I'm sure Phil is working on it.   exiftool -MakeCoffeeNow -lotsof "COFFEE" +MILK +SUGAR ;D
OS: Windows 11 Pro