Question to -api struct=2 for listtype tags

Started by herb, August 20, 2018, 11:20:20 AM

Previous topic - Next topic

herb

Hello Phil,

I work with Exiftool v11.10 on a Windows 7 system.

In order to test structures and also string-tags with multiline content I read all tags of an image
exiftool.exe -t -G0:1 -all:all -sep ?? -api struct=2 some-other-options  image.jpg
My application starts Exiftool using the -stay_open mechanism and the "some-other-options" are out of interest for the described problem.

For listtype tags (in my case -by-linetitle) I have the following problem:
- only in case of -by-linetitle has > 1 elements, all elements are inside brackets []
  which are used when also structures are output.
- in case of -by-linetitle has only 1 element, its value is sent without brackets:
QuoteIPTC \t by-linetitle \t [title1

I had expected that also this one element is inside brackets: [[title1].

Now my question: How to differ between:
- the first bracket [ is part of tag value
- the first bracket is because of -api struct=2 for a listtype tag   

Is this an error?
Thanks for your help in advance

Best regards
Herb

Phil Harvey

Hi Herb,

I can't reproduce the wayward leading "[":

> exiftool a.jpg -by-linetitle=a
    1 image files updated
> exiftool a.jpg -t -s -G0:1 -by-linetitle -sep '??' -api struct=2
IPTC By-lineTitle a
> exiftool a.jpg -by-linetitle+=b
    1 image files updated
> exiftool a.jpg -t -s -G0:1 -by-linetitle -sep '??' -api struct=2
IPTC By-lineTitle [a,b]


But yes, IPTC list-type tags with only a single value won't be in square brackets.  Currently this is only done for XMP tags.  The Struct option is really designed only for XMP, but it does have some spill-over as you discovered.  I suppose I could also apply this to other metadata types, but I worry about backward compatbility so I wouldn't be making such a significant change just before an anticipated production release.

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

Phil Harvey

Ah.  I see.  Your question is how to distinguish a list from a single item in square brackets in the Struct output:

> exiftool a.jpg -by-linetitle='[a,b]'
    1 image files updated
> exiftool a.jpg -by-linetitle -sep '??'
By-line Title                   : [a,b]
> exiftool a.jpg -t -s -G0:1 -by-linetitle -sep '??' -api struct=2
IPTC By-lineTitle [a,b]    <== THIS
> exiftool a.jpg -by-linetitle=a -by-linetitle=b
    1 image files updated
> exiftool a.jpg -by-linetitle -sep '??'
By-line Title                   : a??b
> exiftool a.jpg -t -s -G0:1 -by-linetitle -sep '??' -api struct=2
IPTC By-lineTitle [a,b]    <== IS THE SAME AS THIS


  Good question.  Let me think...
...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 ($).

Phil Harvey

Actually, I would probably recommend using either -j or -X instead of -t for your output format, and dropping the -sep option.  With -j for example, this is the difference:

  "IPTC:By-lineTitle": "[a,b]"

vs.

  "IPTC:By-lineTitle": ["a","b"]

and with -X:

<IPTC:By-lineTitle>[a,b]</IPTC:By-lineTitle>

vs.

<IPTC:By-lineTitle>
  <rdf:Bag>
   <rdf:li>a</rdf:li>
   <rdf:li>b</rdf:li>
  </rdf:Bag>
</IPTC:By-lineTitle>


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

herb

Hello Phil,

thanks for your quick reply.
Yes you are right, for XMP listtype tags also one element is sent inside brackets.

Thanks also for your hints how to solve this problem, but currently my application is not able to parse json or xml output.

Best regards
Herb

Phil Harvey

Just FYI:  I tried implementing this for other tag types and it resulted in failure of 32 of the 509 tests in the test suite.  So it could have a significant impact on other developers using ExifTool.

Parsing JSON is quite straightforward and may be worth the effort.

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