How to read/write meta tags

Started by ParandroidAnnoyed, February 28, 2023, 12:59:20 PM

Previous topic - Next topic

ParandroidAnnoyed

Total newbie here!

I have 40.000 jpgs in many subfolders and I need to fill both the Title and the Comment tags by using the existent Keyword attribute and/or containing folder name.

Eg: image.jpg with keyword attribute "KEY" inside the subfolder "FOLDERNAME".

I need to fill the Title attribute with something like "Blahblahblah KEY" and the Comment attribute with something like "Blahblahblah FOLDERNAME".

Is it possible? If yes, how?  :P

Thank you!


Phil Harvey

I'll assume your keyword is stored in XMP:Subject, and that you want to write the JPEG Comment (which isn't really advisable, but here goes...).

Then the command would look something like this:

exiftool "-title<Blahblahblah $subject" "-comment<Blahblahblah ${directory;s(.*/)()}" -ext jpg -r DIR

Read FAQs 2 and 3 for help determining which tag names you should be using.

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

StarGeek

Quote from: ParandroidAnnoyed on February 28, 2023, 12:59:20 PMI need to fill both the Title and the Comment tags

Are you looking at a file's properties on the desktop for these name?  Such as RightClick->Properties on Windows or through Finder on Mac?  If so, understand that the names listed are often not the actual tag names. Often there are multiple tags where the displayed date can be read from.  In the case of Windows, you can look at this post to find out what the actual tags are that Windows uses to fill the Property with.

Otherwise, you probably what to use the command in FAQ #3 to figure out the actual names of the tags you want to write.
* 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).

ParandroidAnnoyed

Quote from: StarGeek on February 28, 2023, 01:41:17 PM
Quote from: ParandroidAnnoyed on February 28, 2023, 12:59:20 PMI need to fill both the Title and the Comment tags

Are you looking at a file's properties on the desktop for these name?  Such as RightClick->Properties on Windows or through Finder on Mac?  If so, understand that the names listed are often not the actual tag names. Often there are multiple tags where the displayed date can be read from.  In the case of Windows, you can look at this post to find out what the actual tags are that Windows uses to fill the Property with.

Otherwise, you probably what to use the command in FAQ #3 to figure out the actual names of the tags you want to write.

Yes, I'm referring to the Windows file properties! I don't event knew there were other type of properties  ;D

Quote from: Phil Harvey on February 28, 2023, 01:28:25 PMI'll assume your keyword is stored in XMP:Subject, and that you want to write the JPEG Comment (which isn't really advisable, but here goes...).

Then the command would look something like this:

exiftool "-title<Blahblahblah $subject" "-comment<Blahblahblah ${directory;s(.*/)()}" -ext jpg -r DIR

- Phil

Now I don't know if we are talking about the same attributes  :P . If it's not, then I think we need to substitute the "$subject" and the "-comment" part...

StarGeek

Quote from: ParandroidAnnoyed on February 28, 2023, 02:41:59 PMYes, I'm referring to the Windows file properties! I don't event knew there were other type of properties

A big example is the "Date Taken" property.  There's no such thing as a "Date Taken" tag.  There 6 different tags that Windows will read in order to fill this property.

Quote from: Phil Harvey on February 28, 2023, 01:28:25 PMNow I don't know if we are talking about the same attributes  :P . If it's not, then I think we need to substitute the "$subject" and the "-comment" part...

See the link I posted above.  It will tell you what the real tags to use for each Windows property.
* 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).

ParandroidAnnoyed

Quote from: StarGeek on February 28, 2023, 06:50:44 PMSee the link I posted above.  It will tell you what the real tags to use for each Windows property.

I've extracted all the attributes with ExifTool and I suppose that I have to use the following 3:

[IFD0] XPComment
[IFD0] XPTitle
[IFD0] XPKeywords

XPTitle is also stored inside "[IFD0] ImageDescription", "[XMP-dc] Title" and "[XMP-dc] Description"

XPKeyword is also stored inside "[XMP-dc] Subject"

Do we need more information?

Phil Harvey

I would recommend against using the XP tags -- these are Windows-specific.  I would suggest using Title, Description and Subject (all default to XMP-dc in ExifTool if you don't specify the group).

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

ParandroidAnnoyed

Quote from: Phil Harvey on March 01, 2023, 07:34:00 AMI would recommend against using the XP tags -- these are Windows-specific.  I would suggest using Title, Description and Subject (all default to XMP-dc in ExifTool if you don't specify the group).

- Phil

I have to use these tags because they are easily manageable later by other collaborators  :-[

I've tested your first suggestion and it works perfectly! Just a question: is it possible to run it without creating the file "*.original"?

StarGeek

Quote from: ParandroidAnnoyed on March 01, 2023, 10:16:02 AMJust a question: is it possible to run it without creating the file "*.original"?

Add the -overwrite_original option.

If you need to write the XP* tags, then I would suggest you write also write to the tags Phil suggested at the same time.  As Phil says, the XP* tags are Windows only and if you have to migrated the images to another program, you will not be able to access the data.

When writing to the XPKeywords tag, you want to write the keywords as a semicolon separated string, e.g. -XPKeywords="Keyword 1;Keyword 2;Keyword 3".  This is different than other keyword type tags as it is not a list type tag where every keyword is separate from the others.
* 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).

ParandroidAnnoyed

Quote from: StarGeek on March 01, 2023, 11:54:50 AM
Quote from: ParandroidAnnoyed on March 01, 2023, 10:16:02 AMJust a question: is it possible to run it without creating the file "*.original"?

Add the -overwrite_original option.

If you need to write the XP* tags, then I would suggest you write also write to the tags Phil suggested at the same time.  As Phil says, the XP* tags are Windows only and if you have to migrated the images to another program, you will not be able to access the data.

When writing to the XPKeywords tag, you want to write the keywords as a semicolon separated string, e.g. -XPKeywords="Keyword 1;Keyword 2;Keyword 3".  This is different than other keyword type tags as it is not a list type tag where every keyword is separate from the others.

Thank you so much! It works great and you solved all my problems  ;D

Just one thing: the title in the Windows properties is not the "XPTitle", but it changes with the "-title" command, that seems to overwrite the "XMP Title", but also the "XMP Description" and the "IFD0 ImageDescription", so I can't understand which one of these actually is. But it works, so it's ok!

Thank you guys, you are great!

ParandroidAnnoyed

Hi again!

I need a little modification to the perfect string you helped me pack a while ago.

exiftool "-XPTitle<$subject" "-title<$subject"

I would need to use only the first subject if there is more than one... is it possible?

Thank you!

Phil Harvey

Try this:

exiftool "-XPTitle<${subject;s/,.*//}" "-title<${subject;s/,.*//}" ...

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

ParandroidAnnoyed