Author Topic: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords  (Read 5582 times)

SimoneConti

  • Newbie
  • *
  • Posts: 2
Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« on: November 16, 2013, 06:31:09 AM »
Hi.
congratulations for the software, it's great.

I have a problem I cannot resolve, maybe you can help me.

I want to copy all my XMP-mwg-rs:RegionName (written by Picasa face tags) to IPTC:Keywords, to make all the people in a photo avaible in every other programs, like Adobe Lightroom.

I did this script:

exiftool -k -overwrite_original -IPTC:keywords-<XMP-mwg-rs:RegionName -IPTC:keywords+<XMP-mwg-rs:RegionName C:\Users\Simone\Dropbox\Immagini\Album\test

but it creates me duplicates, don't know why.

Another thing... I have about 4000+ photos in a dropbox folder. I need each file to be updated only if needed, namely when in a photo there is a XML regionName than is not present in IPTC Keywords.
Otherwise everytime I run the script dropbox will re-sych all the 4000+ photo, when only 5-6 really needed.

Thank you.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #1 on: November 16, 2013, 07:51:09 AM »
This is a bit tricky, but the reason is explained in note 5 of the -tagsFromFile documentation:

            5) The normal behaviour of copied tags differs subtly from that of
            assigned tags for list-type tags.  When copying to a list, each
            copied tag overrides any previous operations on the list.  While
            this avoids duplicate list items when copying groups of tags from
            a file containing redundant information, it also prevents values
            of different tags from being copied into the same list when this
            is the intent.  So a -addTagsFromFile option is provided which
            allows copying of multiple tags into the same list.  ie)

                exiftool -addtagsfromfile @ '-subject<make' '-subject<model' ...

            Other than this difference, the -tagsFromFile and -addTagsFromFile
            options are equivalent.


One might think that the -< and +< would change this, but they don't since the +/- applies to adding/deleting tags in the target file, and doesn't affect the the tags accumulated from the command line.

The only way I can see to avoid updating the file when all of the regions already exist in the keywords is to create a user-defined Composite tag based on IPTC:Keywords and XMP-mwg-rs:RegionName.  Then construct the new list yourself, or return undef if nothing changed (then the file won't be changed).

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

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #2 on: November 16, 2013, 08:07:55 AM »
I was feeling generous, so here is the config file to define the Composite tag I mentioned (called MyKeywords).  See the sample config file for instructions on activating the config file.

Code: [Select]
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyKeywords => {
            Require => {
                0 => 'XMP-mwg-rs:RegionName',
            },
            Desire => {
                1 => 'IPTC:Keywords',
            },
            ValueConv => q{
                my (@key, %key, $changed);
                my @reg = ref $val[0] eq 'ARRAY' ? @{$val[0]} : ($val[0]);
                @key = ref $val[1] eq 'ARRAY' ? @{$val[1]} : ($val[1]) if defined $val[1];
                $key{$_} = 1 foreach @key;
                foreach (@reg) {
                    next if $key{$_};
                    push @key, $_;
                    $changed = 1;
                }
                return $changed ? \@key : undef;
            },
        },
    },
);
1; # end

With this, the command would be:

exiftool "-iptc:keywords<mykeywords" FILE

- Phil

Edit: Removed a useless line from the code.
« Last Edit: November 17, 2013, 06:32:56 AM by 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 ($).

SimoneConti

  • Newbie
  • *
  • Posts: 2
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #3 on: November 17, 2013, 05:29:03 AM »
This is simply beautifull, works as expected.

Thanks for your time, very appreciated.

adityagulavani

  • Newbie
  • *
  • Posts: 1
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #4 on: May 06, 2014, 06:42:42 AM »
Thankyou Very Much!
and Congratulation ! This is a great software! ;D

zurvan2

  • Newbie
  • *
  • Posts: 3
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #5 on: June 01, 2014, 11:34:56 AM »
*so* close.

I'm interested in getting this exact thing to work. I've created the config file as in the example, but the result is not updating the Keywords tag:

Code: [Select]
$ exiftool "-mykeywords" DSC00315.JPG
My Keywords                     : Foo, Bar

Code: [Select]
$ exiftool "-iptc:keywords<mykeywords" DSC00315.JPG
    0 image files updated
    1 image files unchanged

And adding -addTagsFromFile doesn't help either:

Code: [Select]
$ exiftool '-addTagsFromFile @'  "-iptc:keywords<mykeywords" DSC00315.JPG
    0 image files updated
    1 image files unchanged

Thanks in advance.

Edit to add (in case it's relevant):
Code: [Select]
$ exiftool -ver
8.60

zurvan2

  • Newbie
  • *
  • Posts: 3
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #6 on: June 01, 2014, 12:53:29 PM »

Nevermind. I tried the latest version (9.63) and it works there, so my only problem was the version.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #7 on: June 01, 2014, 02:03:13 PM »
This should have worked with 8.60.  Your quoting is wrong though:

Quote
exiftool '-addTagsFromFile @'  "-iptc:keywords<mykeywords" DSC00315.JPG

You shouldn't have quotes around '-addTagsFromFile @'.

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

zurvan2

  • Newbie
  • *
  • Posts: 3
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #8 on: June 01, 2014, 03:00:21 PM »
Without the quotes:

Code: [Select]
$ exiftool -addTagsFromFile @  "-iptc:keywords<mykeywords" DSC00315.JPG
Error: Error opening file - @
    0 image files updated
    1 image files unchanged
    1 files weren't updated due to errors

The current version works without this, of course.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Add tags from XMP-mwg-rs:RegionName to IPTC:Keywords
« Reply #9 on: June 01, 2014, 06:19:33 PM »
I don't understand.  The -addTagsFromFile option was added in version 7.37.

Oh well.  No need to worry about what may have changed since the current version is working for you.

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