How to parse list fields

Started by bigfire60, March 16, 2020, 11:15:21 AM

Previous topic - Next topic

bigfire60

Searched the forum and online but couldn't find an example to parse through list values.
Basically, I'd like to read each value in the Microsoft People schema XMP-MP-RegionPersonDisplayName
and add it to XMP-dc:subject and IPTC-keywords if they don't currently exist there.

Any advice would be appreciated.

Phil Harvey

Try this:

exiftool -addtagsfromfile @ "-xmp-dc:subject-<XMP-MP:RegionPersonDisplayName" "-xmp-dc:subject+<XMP-MP:RegionPersonDisplayName" "-iptc:keywords-<XMP-MP:RegionPersonDisplayName" "-iptc:keywords+<XMP-MP:RegionPersonDisplayName" DIR

FAQ 17 describes the technique I used here to avoid duplicate entries.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bigfire60

You are the master!
Thanks for this wonderful piece of software...

bigfire60

One minor issue, keywords are duplicated if they previously existed.

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bigfire60


bigfire60

Hi Phil,
I have a follow-up question.
I'm sure this can be done programmatically, but it may be too complex for the command line / batch file.
I want to check each person name in XMP-MP:RegionPersonDisplayName list for a matching value in IPTC:keywords.
Output the person name if condition is true (no matching name).

Thanks.

Phil Harvey

That can be done with this command:

exiftool -config missingnames.config -missingnames DIR

and this config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MissingNames => {
            Require => {
                0 => 'XMP-MP:RegionPersonDisplayName',
            },
            Desire => {
                1 => 'IPTC:Keywords',
            },
            ValueConv => q{
                my @people = ref $val[0] ? @{$val[0]} : ( $val[0] );
                my @keywords;
                @keywords = ref $val[1] ? @{$val[1]} : ( $val[1] ) if defined $val[1];
                my %keys;
                $keys{$_} = 1 foreach @keywords;
                my @out;
                $keys{$_} or push @out, $_ foreach @people;
                return @out ? \@out : undef;
            },
        },
    },
);
1;  #end


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

bigfire60

Thanks so much.
Worked like a charm.
Didn't even consider config files.
What programming language do they use?


StarGeek

Quote from: bigfire60 on March 20, 2020, 12:13:17 PM
What programming language do they use?

Exiftool and the config files are Perl programs.  Even the Windows executable is just PAR packed Perl code.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bigfire60


bigfire60

Unfortunately, I don't know Perl.
I took a stab but couldn't figure out how to also output the filename when the condition is true.
Could you be so kind?

StarGeek

Just use the same config file
exiftool -config missingnames.config -if "$missingnames" -Filename  <FileOrDir>
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

bigfire60

Now it will output the filename, but not the missing names.

The attached screen capture show the initial run without the if condition
where the missing names appear. The last run shows the filename but not the missing name.


bigfire60

Oops, just had to add the -missingnames to the list.

Is there a way to suppress the linefeed between Filename & missing name?