Calibre custom columns in ExifTool config

Started by Sue Dunham, January 09, 2016, 06:16:04 PM

Previous topic - Next topic

Sue Dunham

Hello all. Rank newbie here, puzzling through perl on up. I'd like to use ExifTool to insert values defined in Calibre's custom columns, which I gather means setting up the config file to read them properly. These seem to be written to either the "calibre" or "calibreCC" namespace, depending on how one looks. Calibre's own additional tags look like they're being interpreted correctly. A sample file looks like this:
> exiftool.pl -xmp:all MyDoc.pdf
Title                           : MyDoc
Description                     :
Publisher                       :
Subject                         : MyTag1, MyTag2
Creator                         : MyAuthor
Date                            : 0100:12:31 16:00:00-08:00
Language                        : en
Metadata Date                   : 2016:01:09 14:28:02.124000-08:00
Timestamp                       : 2016:01:09 14:21:02-08:00
Author link map                 : {"MyAuthor": ""}
Title sort                      : MyDoc
Author sort                     : MyAuthor
Custom metadata Name            : #mytag
Custom metadata                 : {"#value#": "MyValue", "#extra#": null, "link_column": "value", "label": "mytag", "datatype": "text",
"category_sort": "value", "is_multiple2": {}, "rec_index": 22, "is_csp": false, "is_custom": true, "kind": "field", "column": "value",
"is_editable": true, "name": "MyTag", "search_terms": ["#mytag"], "colnum": 11, "is_multiple": null, "display": {"use_decorations": 0,
"description": ""}, "is_category": true, "table": "custom_column_11"}

> exiftool.pl -xmp:all -X MyDoc.pdf
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about='MyDoc.pdf'
  xmlns:et='http://ns.exiftool.ca/1.0/' et:toolkit='Image::ExifTool 10.09'
  xmlns:XMP-dc='http://ns.exiftool.ca/XMP/XMP-dc/1.0/'
  xmlns:XMP-xmp='http://ns.exiftool.ca/XMP/XMP-xmp/1.0/'
  xmlns:XMP-calibre='http://ns.exiftool.ca/XMP/XMP-calibre/1.0/'>
<XMP-dc:Title>MyDoc</XMP-dc:Title>
<XMP-dc:Description></XMP-dc:Description>
<XMP-dc:Publisher></XMP-dc:Publisher>
<XMP-dc:Subject>
  <rdf:Bag>
   <rdf:li>MyTag1</rdf:li>
   <rdf:li>MyTag2</rdf:li>
  </rdf:Bag>
</XMP-dc:Subject>
<XMP-dc:Creator>MyAuthor</XMP-dc:Creator>
<XMP-dc:Date>0100:12:31 16:00:00-08:00</XMP-dc:Date>
<XMP-dc:Language>en</XMP-dc:Language>
<XMP-xmp:MetadataDate>2016:01:09 14:28:02.124000-08:00</XMP-xmp:MetadataDate>
<XMP-calibre:Timestamp>2016:01:09 14:21:02-08:00</XMP-calibre:Timestamp>
<XMP-calibre:Author_link_map>{&quot;MyAuthor&quot;: &quot;&quot;}</XMP-calibre:Author_link_map>
<XMP-calibre:Title_sort>MyDoc</XMP-calibre:Title_sort>
<XMP-calibre:Author_sort>MyAuthor</XMP-calibre:Author_sort>
<XMP-calibre:Custom_metadataName>#mytag</XMP-calibre:Custom_metadataName>
<XMP-calibre:Custom_metadata>{&quot;#value#&quot;: &quot;MyValue&quot;, &quot;#extra#&quot;: null,
&quot;link_column&quot;: &quot;value&quot;, &quot;label&quot;: &quot;mytag&quot;, &quot;datatype&quot;: &quot;text&quot;,
&quot;category_sort&quot;: &quot;value&quot;, &quot;is_multiple2&quot;: {}, &quot;rec_index&quot;: 22, &quot;is_csp&quot;: false,
&quot;is_custom&quot;: true, &quot;kind&quot;: &quot;field&quot;, &quot;column&quot;: &quot;value&quot;,
&quot;is_editable&quot;: true, &quot;name&quot;: &quot;MyTag&quot;, &quot;search_terms&quot;: [&quot;#mytag&quot;],
&quot;colnum&quot;: 11, &quot;is_multiple&quot;: null, &quot;display&quot;: {&quot;use_decorations&quot;: 0,
&quot;description&quot;: &quot;&quot;}, &quot;is_category&quot;: true, &quot;table&quot;: &quot;custom_column_11&quot;}
</XMP-calibre:Custom_metadata>
</rdf:Description>
</rdf:RDF>


Additional custom columns will repeat those custom_metadataName, custom_metadata pairs, with some variations depending on the nature of the tag. Calibre adds a "#" to the start of each name.

My latest attempt at a config file looks like this:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::Main' => {
        calibre => {
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::calibre',
            },
        },
    },
);

%Image::ExifTool::UserDefined::calibre = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-calibre', 2 => 'Document' },
    NAMESPACE => { 'calibre' => 'http://calibre-ebook.com/xmp-namespace-custom-columns' },
    WRITABLE => 'string',
    "#mytag" => {
        Struct => {
            "#extra#" => { Writable => 'string' },
            'table" => { Writable => 'string' },
            'colnum' => { Writable => 'integer' },
            'datatype' => { Writable => 'string' },
            "#value#" => { Writable => 'string' },
            'is_category' => { Writable => 'boolean' },             
            'rec_index' => { Writable => 'integer' },
            'column" => { Writable => 'string' },
            'is_csp' => { Writable => 'string' },
            'display' => {
                 'description' => { Writable => 'string' },
                 'use_decorations' => { Writable => 'string' },
            },
            'is_multiple2' => {
                  'ui_to_list' => { Writable => 'string' },
                  'list_to_ui' => { Writable => 'string' },
                  'cache_to_list" => { Writable => 'string' },
            },             'search_terms' => { Writable => 'string' },
            'name' => { Writable => 'string' },
            'link_column' => { Writable => 'string' },
            'category_sort' => { Writable => 'string' },
            'kind' => { Writable => 'string' },
            'is_multiple' => { Writable => 'string' },
            'is_custom' => { Writable => 'boolean' },
            'is_editable' => { Writable => 'boolean' },
            'label' => { Writable => 'string' },
        },
    },
);


Am I on the right track? Making obvious syntax errors? Would I actually want all of those to be writable? Too complicated? I suspect changing stuff like this behind Calibre's back might just blow it up, but that's a problem for another forum.

Phil Harvey

#1
You are very close, but there are a couple of problems:

1. You have used double quotes in a few places in the config file instead of single quotes.

2. ExifTool has a problem with the "#" in the structure field names.  This is something I'll have to look into.

Other than this, your config file should work.

- Phil

Edit: I have looked into this a bit.  I still need to do some research to see if a # is legal in a tag ID.  If it is, then I will update ExifTool to be able to handle this.
...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

If I am reading the XML specification correctly, "#" is not allowed in an XML element name.

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