ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: robstott on August 12, 2013, 05:27:35 AM

Title: ExifTool_config help please!
Post by: robstott on August 12, 2013, 05:27:35 AM
Hi,

Apologies if this is a bit of a newbie question. I'm so close (yet so far) from having solved a big problem but I'm just missing a small piece of the solution. Basically, I want to write into the "egBarc:Code" field here:

<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 9.32'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about=''
  xmlns:egBarc='http://ns.esko-graphics.com/barcode/1.0/'
  xmlns:egBarcL='http://ns.esko-graphics.com/barcodelist/1.0/'>

  <egBarcL:barcodes>
   <rdf:Bag>
    <rdf:li rdf:parseType='Resource'>
     <egBarc:Code>Xxx</egBarc:Code>
    </rdf:li>
   </rdf:Bag>
  </egBarcL:barcodes>
</rdf:Description>

</rdf:RDF>
</x:xmpmeta>


...but when I write to it, I end up with:

<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 9.32'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about=''
  xmlns:egBarc='http://ns.esko-graphics.com/barcode/1.0/'
  xmlns:egBarcL='http://ns.esko-graphics.com/barcodelist/1.0/'>

  <egBarcL:barcodes rdf:parseType='Resource'>
   <egBarc:Code>ooops</egBarc:Code>
  </egBarcL:barcodes>
</rdf:Description>

</rdf:RDF>
</x:xmpmeta>



I'm using the command:

exiftool /Users/Admin/Desktop/barcode.pdf  -barcodes={Code=ooops}

And I've modified my Exiftool_config file to look like this:


%Image::ExifTool::UserDefined = (

   # new XMP namespaces (ie. xxx) must be added to the Main XMP table:
    'Image::ExifTool::XMP::Main' => {
        egBarcL => { # <-- must be the same as the NAMESPACE prefix
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::egBarcL',
                # (see the definition of this table below)
            },
        },
       

        # add more user-defined XMP namespaces here...
    },
 
);

# This is a basic example of the definition for a new XMP namespace.
# This table is referenced through a SubDirectory tag definition
# in the %Image::ExifTool::UserDefined definition above.
# The namespace prefix for these tags is 'xxx', which corresponds to
# an ExifTool family 1 group name of 'XMP-xxx'.
%Image::ExifTool::UserDefined::egBarcL = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-egBarcL', 2 => 'Image' },
    NAMESPACE => { 'egBarcL' => 'http://ns.esko-graphics.com/barcodelist/1.0/' },
    WRITABLE => 'string',

   
   
#   barcodes => { List => 'Bag',
  #  },
   
    barcodes => {
        # the "Struct" entry defines the structure fields
        Struct => {
            # optional namespace prefix and URI for structure fields
            # (required only if different than NAMESPACE above)
            NAMESPACE => { 'egBarc' => 'http://ns.esko-graphics.com/barcode/1.0/' },
            # optional structure name (used for warning messages only)
            STRUCT_NAME => '',

            Code => { Writable => 'string' },
            Magnification => { Writable => 'string' },
            Type => { Writable => 'string' },


        },
    },

);



#------------------------------------------------------------------------------
1;  #end



Can anyone show me what I'm doing wrong here? I assume my Exiftool_config is wrong... but how?

Thanks in advance,

Rob

Title: Re: ExifTool_config help please!
Post by: Phil Harvey on August 12, 2013, 07:38:48 AM
Hi Rob,

Very close.

You just need to add List => 'Bag', to your "barcodes" tag.  I see you have commented out a line with this in it.  Maybe you are missing the syntax:

    barcodes => {
        List => 'Bag',
        Struct => {
            NAMESPACE => { 'egBarc' => 'http://ns.esko-graphics.com/barcode/1.0/' },
            STRUCT_NAME => 'Barcodes',
            Code => { },
            Magnification => { },
            Type => { },
        },
    },


Also, since you defined the default WRITABLE type in your tag table, you don't need to define the individual Writable types for each tag if the are the same (all "string").

BTW, the STRUCT_NAME isn't used in writing the XMP, and is only used for ExifTool warning messages if there are any problems.

- Phil

Edit: Oops.  You wanted the entire structure in a Bag, not just the Code tag --  moved 'Bag' definition up to the "barcodes" level.
Title: Re: ExifTool_config help please!
Post by: robstott on August 12, 2013, 08:47:11 AM
Hi Phil,

Thanks so much for that, very helpful.

There's just one small snag, which is my fault for not giving a clearer example. In short, when I write multiple fields, for example:

exiftool /path/to/my/file.pdf -barcodes={{Code=YYYYY,Type=XXXXXX,Magnification=1}}

...then I get...



<rdf:Description rdf:about=''
  xmlns:egBarc='http://ns.esko-graphics.com/barcode/1.0/'
  xmlns:egBarcL='http://ns.esko-graphics.com/barcodelist/1.0/'>
 
<egBarcL:barcodes>
   
<rdf:Bag>
   
<rdf:li rdf:parseType='Resource'>

<egBarc:Code>YYYYY</egBarc:Code>
</rdf:li>

<rdf:li rdf:parseType='Resource'>
<egBarc:Type>XXXXXX</egBarc:Type>

</rdf:li>

<rdf:li rdf:parseType='Resource'>
<egBarc:Magnification>1</egBarc:Magnification>
</rdf:li>

</rdf:Bag>
</egBarcL:barcodes>



Where what I actually want is...

<rdf:Description rdf:about=''
  xmlns:egBarc='http://ns.esko-graphics.com/barcode/1.0/'
  xmlns:egBarcL='http://ns.esko-graphics.com/barcodelist/1.0/'>
 
<egBarcL:barcodes>
   
<rdf:Bag>
   
<rdf:li rdf:parseType='Resource'>
<egBarc:Code>YYYYY</egBarc:Code>
<egBarc:Type>XXXXXX</egBarc:Type>
<egBarc:Magnification>1</egBarc:Magnification>
</rdf:li>

</rdf:Bag>
</egBarcL:barcodes>




Any idea where I'm going wrong?

Thanks again,

Rob
Title: Re: ExifTool_config help please!
Post by: Phil Harvey on August 12, 2013, 09:04:31 AM
Hi Rob,

No idea (other than the incorrect bracing, which should give an error).  With the config definition i posted, I get this:

> exiftool a.xmp '-barcodes={Code=YYYYY,Type=XXXXXX,Magnification=1}'
    1 image files created

> cat a.xmp
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 9.35'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about=''
  xmlns:egBarc='http://ns.esko-graphics.com/barcode/1.0/'
  xmlns:egBarcL='http://ns.esko-graphics.com/barcodelist/1.0/'>
  <egBarcL:barcodes>
   <rdf:Bag>
    <rdf:li rdf:parseType='Resource'>
     <egBarc:Code>YYYYY</egBarc:Code>
     <egBarc:Magnification>1</egBarc:Magnification>
     <egBarc:Type>XXXXXX</egBarc:Type>
    </rdf:li>
   </rdf:Bag>
  </egBarcL:barcodes>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>


Writing multiple barcodes structures can be done either by assigning more "barcodes" elements in the same command:

exiftool '-barcodes={code=a,type=b,magnification=1}' '-barcodes={code=x,type=y,magnification=2}' FILE

or added to existing barcodes using +=:

exiftool '-barcodes+={code=x,type=y,magnification=2}' FILE

or written as a list

exiftool '-barcodes=[{code=a,type=b,magnification=1},{code=x,type=y,magnification=2}]' FILE

Also, you can of course write using the flattened tag names too if you want, but it is harder to keep multiple structures organized like this.

And one more thing: I notice that Magnification should probably be 'real', not 'string'-type.

- Phil
Title: Re: ExifTool_config help please!
Post by: robstott on August 12, 2013, 09:25:34 AM
Absolutely spot on! Thanks for your help, much appreciated!