Extending IMatch and ExifTool

Extending IMatch and ExifTool


This is for those who know what they are doing. We'll be doing some unsafe, undocumented and unsupported stuff on our own risk here. The description in this article may seem terse to some, so let me warn you: If you find these instructions unhelpful, then you do not belong to those who know what they are doing. Don't let me know if you have any problems, and if you break something that's your problem not mine. Don't tell Mario either. Test everything on a test database and backup your data. Everything here is presented as-is with no warranties whatsoever expressed or implied. You use the information here on your own risk.

The reason why I'm doing this turned out to be quite lengthy, so I ended up putting it in a separate article: IMatch and Metadata.

1. Customizing the ExifTool Config

IMatch comes with its own ExifTool config, so we're going to keep most of our changes in our own file.

  1. Create a file named imatch_et_custom.config in the IMatch folder with the contents:

    1;  #end

    All configuration then goes into the space above the line.

  2. Add the following to the imatch_et.config file:

    eval { require 'imatch_et_custom.config' };

    This is how ExifTool loads its own config, so we're just extending it one step.

1.1. Config File Documentation

See the example config[a] for an overview and lib/Image/ExifTool/README[b] for the real in-depth guide.

1.2. Adding to Hashes

Since the example config assumes that it is the only config file, we'll have to adopt a slightly different idiom to add to the hashes that make up the ExifTool config. Instead of:

%Image::ExifTool::UserDefined = (
    'Key' => { 
        # Value

We will add to an already existing hash with:

$Image::ExifTool::UserDefined{ 'Key' } = { 
    # Value

2. Testing ExifTool

Before we start using the new config with IMatch, we should test it with ExifTool command line. This is done by doing the metadata operations you hope to achieve with:

exiftool -config imatch_et_custom.config ...

to just test the custom bits you've added, and:

exiftool -config imatch_et.config ...

to test everything, as IMatch would see it. I recommend that you at least try to start ExifTool with just your custom config file before trying an all-up test. If there are any errors in the configuration file, they will only be reported when it is used by itself and not when you test everything. (I'm not a Perl hacker, so I have no explanation for this behavior - maybe it's related to Perl's propensity to keep on truckin' no matter what[c].)

3. Working With IMatch Databases

An IMatch database is an SQLite[d] database, so grab the command line tool[e].

4. Updating the IMatch Database

Once we have the ExifTool definitions figured out, it's time to update the IMatch database's internal tables. Since version 5.4.8, IMatch will record the last modified time of the imatch_et.config file, so loading it into a text editor and saving it will trigger an update the next time you start IMatch.

Versions prior to 5.4.8 didn't have this test. Since there is no way to trigger this from within the application, nor is there a (reasonable) way to change the ExifTool version number, so for versions prior to 5.4.8 we'll just clobber the value in the DB and force an update that way:

sqlite3 <path to imd5> "update md_system set tvalue = '' where sname = 'etversion';"

5. Removing Tag Definitions

I think there are much better ways of doing this using the IMatch tag manager, but if you for some reason want to remove a tag definition from the IMatch database, you can delete it from the md_tag table. The deletion will cascade from there, so you will delete more than just the single row in that table.

delete from md_tag where id = 'myTagName';