Quotation marks in subject interacting poorly with -args argument

Started by alanterra, February 08, 2015, 06:16:05 PM

Previous topic - Next topic

alanterra

Hi

I have been trying to track down a bug in a script I am writing, and I think I isolated it. I'm not sure if this is a bug or a feature in exiftool.

If you put a quote in a subject tag
exiftool -subject+='A "quoted" subject' -subject+='An unquoted subject' test.JPG
and then you try to transfer the tags to another image via writing and reading to a text file
exiftool -args -subject test.JPG > temp.txt
exiftool -@ temp.txt test2.JPG
the tags do not come over as you would wish. Looking at the tags in Photoshop (which uses a semicolon as a separator), the tags of the first file are

A "quoted" subject; An unquoted subject

but the tags of the second file are

"A ""quoted"" subject, An unquoted subject"

or, in other words, the first file has two tags, but the second has one tag.

What I am trying to do is to pull the tags from a file, run them through a script, and then reapply them to the file. Of course, the best thing would be to get rid of the quotes in the tags, which I will probably do. But I thought that this bug report (if it is a bug) might be useful.

Phil Harvey

When outputting a list-type tag using the -args option, the individual items are concatenated (by default with a ", " separator).  So when reading this back, you should use -sep ", ".

Also, if you want to preserve XMP structures, you may want to add -struct to the exporting command.

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

alanterra

Huh.

I had been using -s3 -subject to write out the subject tags, modify them, and read them back in, and using the -sep ", " didn't help. I've lost the details of that version of my script, but I was seeing the final carriage return in the text file find its way into the last tag entered. (Carriage return is signified by a "." character when you display your tags, and it took me a long time to figure out what that meant!)

But you are right (of course), using -args for output and -sep ', " on input solves this problem perfectly. Now I don't have to remove the quote that snuck into my subject tags a long time ago (long before I even knew what metadata were). I suspect that for my purposes I don't want to use the -struct tag, but I am trying to figure that out.

Thanks once again!

Phil Harvey

You're right that you could wind up with a newline be importing the output from -s3, but the -sep option should still work:

> exiftool a.jpg -subject=1 -subject=2 -subject=3
    1 image files updated
> exiftool a.jpg -subject -s3 > t1
> ./hexdump t1
    0000: 31 2c 20 32 2c 20 33 0a                         [1, 2, 3.]
> ./exiftool a.jpg "-subject<=t1" -sep ", "
    1 image files updated
> exiftool a.jpg -subject -sep ";"
Subject                         : 1;2;3.


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