Populate metadata from parts of filename & directory?

Started by Archive, May 12, 2010, 08:54:40 AM

Previous topic - Next topic

Archive

[Originally posted by dd27 on 2009-09-16 18:00:30-07]

Hi,

I would like to populate the metadata fields of a collection of jpgs with information from their filenames; I'm hoping ExifTool can do this and I'd be delighted if somebody could show me how.  (My apologies if the question has already been asked; I have searched in vain for quite awhile.)

To be more specific, I have jpgs of famous artwork that I have named in the following format:

[yearofpainting] Title of Painting (Lastname, Firstname).jpg

So, for example:

[1504] The Garden of Delights (Bosch, Hieronymus).jpg

I would like ExifTool to input these details into the metadata of the jpg; so in this example Title="The Garden of Delights", Copyright="1504", Authors="Bosch, Hieronymus".  Anybody have an idea how to do this?

Thanks very much,

Dave

Archive

[Originally posted by exiftool on 2009-09-16 22:37:32-07]

hi dave. Yes exiftool can do this. It is a bit
involved and requires user-defined tags.
I will explain in detail tomorrow when I am
at a keyboard (on the iPod right now).  - phil

Archive

[Originally posted by exiftool on 2009-09-17 11:04:46-07]

OK, I'm on a keyboard now.  You can do what you want
with this command line:

Code:
exiftool "-rights<Copyright $myyear" "-title<mytitle" "-creator<myauthor" DIR

(where DIR is the directory containing the images).  Note that
you must use single quotes instead of double quotes around the argument
containing a dollar sign ($) if you are running on a Mac or Linux.  Here I have
assumed that you want to write this information to XMP, but you can
of course change the command to write whatever tags you want.

And here is the config file you need to define the "My" tags:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyYear => {
            Require => 'FileName',
            ValueConv => '$val=~/\[(.*)\]\s*(.*?)\s*\((.*)\)/; $1',
        },
        MyTitle => {
            Require => 'FileName',
            ValueConv => '$val=~/\[(.*)\]\s*(.*?)\s*\((.*)\)/; $2',
        },
        MyAuthor => {
            Require => 'FileName',
            ValueConv => '$val=~/\[(.*)\]\s*(.*?)\s*\((.*)\)/; $3',
        },
    },
);
1;  #end

The command will only add metadata to files with names that match
the format you specified.  See the
config
file documentation
for instructions on how to use the config file.
The tricky part here (from a non Perl programmer point of view)
is the expression in the ValueConv definition above which pulls the
required information from the filename string.

- Phil