Remove _ and - from tags when writing based on file name

Started by avalut, January 02, 2019, 05:54:22 PM

Previous topic - Next topic

avalut

Hi,

I have been slowly getting there with adding meta data to a load of images in a folder.

Say first file name is:

Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg

I can with this command
perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.jpg$//i}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

Write Lot_439_1-Heathrow-T1-Aviation-Glass-Desk to the title tag.

I would like to remove to write the title as below:

Lot 439 Heathrow T1 Aviation Glass Desk

I then need to do the same for the Subject tag and comments tag.

Also then apply a fixed name "Auctioneersvault Ltd" to the Copywrite and Author tag

Once I get this working I will attempt to call it from within a UBot exe, which currently downloads all the images and names them on download from 1.jpg etc to the above.

sorry if I asked 3 things at once.

Andrew

StarGeek

You can add s/[-_]/ /g to replace all dashes and underscores with spaces.  For example, ${filename;s/\.jpg$//i;s/[-_]/ /g}
* 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).

avalut

I tried this command and it didn't remove them ?

perl c:\windows\exiftool.pl -P -r "-subject<${filename;s/[-_]/ /g/\.jpg$//i}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

avalut

Sorry, going blind tried
perl c:\windows\exiftool.pl -P -r "-subject<${filename;s/\.jpg$//i;s/[-_]/ /g}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

its replacing the spaces with a ;and a space

StarGeek

I just copy/pasted your command and it worked, though maybe not how you want it.  Separating on space puts Lot, 439, and 1 as individual keywords, where I think you would actually want "Lot 439 1" as a single keyword.

C:\>exiftool -overwrite_original -P -r "-subject<${filename;s/\.jpg$//i;s/[-_]/ /g}" -sep " " -ext jpg "Y:\!temp\bb\Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg"
    1 image files updated

C:\>exiftool -g1 -a -s -subject "Y:\!temp\bb\Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg"
---- XMP-dc ----
Subject                         : Lot, 439, 1, Heathrow, T1, Aviation, Glass, Desk
* 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).

avalut

I need it to remove the , its putting in then its how I am after it.

so
Lot, 439, 1, Heathrow, T1, Aviation, Glass, Desk

To become
Lot 439 1 Heathrow T1 Aviation Glass Desk

Phil Harvey

The ", " is just the default separator for list items.  XMP:Subject is a list-type tag, and list items are stored individually.  You can add -sep " " to the extraction command to display them with just spaces between 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 ($).

avalut

Hi Phil,
Slightly confused as it has the -sep " " command in. do I need to add it again in the string?

Stephen Marsh

#8
avalut, I don't wish to confuse things, however your request interested me...

For the first part to add the filename to the title removing underscore/hyphen/extension, I would offer the following method of combining two regular expressions together:

exiftool "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r DIR

However I think that you will need to clarify the exact fields that you wish to write to for the Copyright and Author tag. The easiest way is to use the exiftool -a -G1 -s FILE command to list the writable tag names on a file that you know has this data.

EDIT: Ah, I now see that StarGeek has already offered a similar approach!

avalut

Hi Stephen,
The files have the following fields

Artist
Creator
Subject
Title
Copyright

avalut

This works great:
perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

and does what I want.

I cannot follow why when I change -title to -subject or comments to write the same data it just says "the system cannot find the file specified.

What am I missing?

Stephen Marsh

#11
I was hoping for the full tag and value, such as:

[IFD0]          Artist                          : Auctioneersvault Ltd
[IFD0]          Copyright                       : Auctioneersvault Ltd
[XMP-dc]        Rights                          : Auctioneersvault Ltd
[XMP-xmpRights] Marked                          : True
[Photoshop]     CopyrightFlag                   : True
[IPTC]          By-line                         : Auctioneersvault Ltd
[IPTC]          CopyrightNotice                 : Auctioneersvault Ltd
[XMP-dc]        Creator                         : Auctioneersvault Ltd
[XMP-dc]        Rights                          : Auctioneersvault Ltd
[XMP-photoshop] AuthorsPosition                 : Lot 439 1 Heathrow T1 Aviation Glass Desk
[IPTC]          By-lineTitle                    : Lot 439 1 Heathrow T1 Aviation G


Stephen Marsh

Could it be something as simple as:

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

vs.

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage.jpg

Which does not answer why one works and the other does not...

I would remove the duplicate -r recursive command, I generally now put it directly before the target file/directory.

avalut

testimage is the folder, I am trying to change about 2600 images (but only one currently in testimage) if that makes sense

avalut

its also the same as another question I posted - one works and the other not as

perl c:\windows\exiftool.pl -artist="Phil Harvey" -copyright="2011 Phil Harvey" C:\Users\Andrew\Desktop\testimage

and it writes correctly to the file but if I change it to

perl c:\windows\exiftool.pl -artist="Silverstone Auctions" -copyright="2019 Silverstone Auctions" C:\Users\Andrew\Desktop\testimage

it come up with an error file not found, both are text fields and apart from more characters there is no change om what the command is asking unless I am missing something.

so something must be causing one thing to work and another not, what I have no idea.

avalut

This is what it is doing
======== C:/Users/Andrew/Desktop/testimage/Lot_439_1-Heathrow-T1-Aviation-Glass-
Desk.jpg
ExifTool Version Number         : 11.23
File Name                       : Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg
Directory                       : C:/Users/Andrew/Desktop/testimage
File Size                       : 234 kB
File Modification Date/Time     : 2019:01:03 03:22:26-08:00
File Access Date/Time           : 2019:01:03 03:22:26-08:00
File Creation Date/Time         : 2019:01:02 12:22:33-08:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Exif Byte Order                 : Big-endian (Motorola, MM)
X Resolution                    : 96
Y Resolution                    : 96
Resolution Unit                 : inches
Artist                          : Phil Harvey
Y Cb Cr Positioning             : Centered
Copyright                       : 2011 Phil Harvey
XMP Toolkit                     : Image::ExifTool 11.23
Creator                         : Creator
Subject                         : Lot_439_1-Heathrow-T1-Aviation-Glass-Desk
Title                           : Lot 439 1 Heathrow T1 Aviation Glass Desk
Comment                         : CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), de
fault quality.
Image Width                     : 1000
Image Height                    : 750
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1000x750
Megapixels                      : 0.750

Stephen Marsh

Rather than using tag shortcuts, perhaps try the full form, such as:

-IFD0:Artist="Auctioneersvault Ltd"

Rather than:

-artist="Auctioneersvault Ltd"

Again, not an answer, just clutching at straws...

Stephen Marsh

Please try:

exiftool -a -G1 -s FILE

Rather than:

exiftool FILE

To receive the unambiguous full tag name/group etc.

avalut

ahahahahhahahhahahahha

Bloody Mac was producing a funny " when pasted in to my windows VPS.

Just got it to accept the artist fine so will try again with the others.
about 5 hours of going mad..

Don't copy and paste from a Mac to a windows machine.

avalut

Ok so now have it working with these 3 commands

perl c:\windows\exiftool.pl -artist="Silverstone Auction" -copyright="2019 Silverstone Auction" C:\Users\Andrew\Desktop\testimage

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

perl c:\windows\exiftool.pl -subject="Silverstone Auction AUTOSPORT INTERNATIONAL SHOW SALE 12th January 2019" C:\Users\Andrew\Desktop\testimage

The subject tag writes to the Tags section and subject is still blank.
Cannot write to comments tag - says it cannot be written to.

So how would I combine the 3 above or is it best to do one at a time?

Is there a command to create an Alt Tag for SEO that would be the Title tag?

Thanks
Andrew

Stephen Marsh

#20
Again

exiftool -a -G1 -s FILE

or

exiftool -a -G1 -s -r DIR

is your friend!

Ensure the test file has the metadata that you wish to write.

"Subject" is actually -XMP-dc:Subject which is the modern replacement of the legacy "Keyword" tag  -IPTC:Keyword.

I believe you are looking for:

-IFD0:XPSubject if you are expecting the MS Windows "Subject" field viewed under "properties"...


This is why it is helpful to use full tag names rather than shortcuts!

avalut

The alt Tag is not in the current file so has to be added - presume this is the issue.

Stephen Marsh

I have not tested, however if all of the following tags were correct, then it should just be simple matter of stringing the arguments together:

perl c:\windows\exiftool.pl -ext jpg -P -artist="Silverstone Auction" -copyright="2019 Silverstone Auction" "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -sep " " -subject="Silverstone Auction AUTOSPORT INTERNATIONAL SHOW SALE 12th January 2019" -r "C:\Users\Andrew\Desktop\testimage"

If run from a batch file in Windows, then you could put the arguments on separate lines which would help make it easier to read!

However, again I would suggest that you use the full tag names rather than shortcut tags so that the metadata write is to the correct field, not a similar named but different field.

avalut


avalut

Stephen,

I have finally managed to get 90% of the fields with data.
Where do I find the "full tag names"

I want to populate the comments tag in windows preview.

Then I think I am as good as its going to be.

avalut

Ok found where they are https://exiftool.org/TagNames/EXIF.html
that so all my actions are below and it doesn't like me combining them for some reason so will just action one at a time and if called from Ubot it should just move down them.


perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$ //;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -artist="Silverstone Auctions" -copyright="2019 Silverstone Auctions" C:\Users\Andrew\Desktop\testimage
perl c:\windows\exiftool.pl -subject="Silverstone Auctions AUTOSPORT INTERNATIONAL SHOW SALE 12th January 2019" C:\Users\Andrew\Desktop\testimage


perl c:\windows\exiftool.pl -creator="Silverstone Auctions" C:\Users\Andrew\Desktop\testimage

perl c:\windows\exiftool.pl -P -r "-description<${filename;s/\.[^\.]+$ //;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

perl c:\windows\exiftool.pl -P -r "-IFD0:XPSubject<${filename;s/\.[^\.]+$ //;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

perl c:\windows\exiftool.pl -P -r "-IFD0:XPComment<${filename;s/\.[^\.]+$ //;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

Still don't have the alt Tag element but think that should give the search engines enough info.

Many thanks again.
Andrew

avalut

Stephen,

This command works better from reading the description of the lot
perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$ //;s/[-]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

So I have dropped the _
so we get say Lot_101_3 a big blue badge

The reason there are a number of images per lot so need to make that obvious.

Is there a way to remove only the first _ and substitute with a space rather than both it would then read
Lot 101_3 a big blue badge

Which would be exactly what I was after.

Andrew

Phil Harvey

Hi Andrew,

Try this to change the first underline to a space: "-title<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"

You should be able to combine all your commands into 2 commands.  The complication is that the -sep " " will write each word separately when writing a list-type tag, so you need one command with -sep " " and one without so that the words don't get written as separate items when writing tags like XMP:Subject.

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

avalut

Hi Phil,

That has worked perfect   - thank you.
I will look at trying to combine, and see how I get on.

I was looking at this post from a while back on the Alt tag is this method described at the end still valid
https://exiftool.org/forum/index.php?topic=6433.0

Finally getting my head around the tool, after spending today and last night on it.

I do like pushing things so will after I have this sorted move on to geo-location tagging and see how much of a mess I get in.

Best regards Andrew


StarGeek

Quote from: avalut on January 03, 2019, 10:47:15 AM
I was looking at this post from a while back on the Alt tag is this method described at the end still valid
https://exiftool.org/forum/index.php?topic=6433.0

It's important to note that answer has to do with what data the Zenfolio website would read.  If you're not working on Zenfolio, then it probably doesn't apply.

As to whether it still works or not would require someone with access to Zenfolio to test.
* 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).

Stephen Marsh

Where do I find the "full tag names"


I use the following command on a file with known metadata populated in the target fields, in order to confirm which fields should be written in other files:

exiftool -a -G1 -s FILE


https://exiftool.org/index.html#tagnames

https://exiftool.org/faq.html#Q2

avalut

for some reason the tags are still writing the jpg at the end of the descriptions with .jpg"

How do I delete that, I didn't notice it was still writing that element it was supposed to have removed that, I thought the -ext jpg woud remove it.

so all tags below have same issue ?

Thanks in advance.

Andrew

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-description<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-IFD0:XPSubject<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-IFD0:XPComment<${filename;s/\.[^\.]+$ //;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages

Phil Harvey

It is this part that should remove the file extension:  s/\.[^\.]+$//

... but you have a space after the dollar sign that would stop this from working.

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

avalut

Not using that site, was just looking at placing on a site, but maybe it will pick the tags up in any event.

avalut

Hi Phil,

Bugger, didn't notice that.. ahahah that's why it was working and then didn't and I copied the error into the other tags.
Thank you, will fix it now.

Added the codes into Ubot and with their shell scrip plugin can run from it, so my program does now what I need as far as downloading the images/renaming and then applying all the tags from one program.

Thanks again
Andrew

avalut

Hi Phil,

I am still getting an addtional " at the end of the description as per
Lot 117_1 Signed Mercedes Benz 300SE door"

There seems to be to many " in the string, which one is the odd one out ?
Andrew

Stephen Marsh

Remove the red "

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-description<${filename;s/\.[^\.]+$//;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-IFD0:XPSubject<${filename;s/\.[^\.]+$//;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages
perl c:\windows\exiftool.pl -P -r "-IFD0:XPComment<${filename;s/\.[^\.]+$//;s/[-]/ /g;s/_/ /}"" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\SilverstoneImages


Stephen Marsh


Stephen Marsh

Quote from: Phil Harvey on January 03, 2019, 10:31:22 AM
You should be able to combine all your commands into 2 commands.  The complication is that the -sep " " will write each word separately when writing a list-type tag, so you need one command with -sep " " and one without so that the words don't get written as separate items when writing tags like XMP:Subject.

- Phil

Ah, thank you Phil, I did not consider the separator bit when I made the simple suggestion to combine the various arguments into one!

Thinking out loud, couldn't one use the execute argument to string together two separate commands into a single command?

https://exiftool.org/exiftool_pod.html#execute-NUM

Phil Harvey

Quote from: Stephen Marsh on January 04, 2019, 07:06:57 AM
Thinking out loud, couldn't one use the execute argument to string together two separate commands into a single command?

Yes.  I was would have mentioned this but I was worried about information overload.

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