ExifTool Command Processor for Duplicate XMP records

Started by Erik, May 22, 2014, 10:43:00 PM

Previous topic - Next topic

Erik

Somewhere along the line Lightroom or Bridge added a duplicate record to my files, which makes viewing the keywords for files ugly.  Every keyword (as well as other XMP data) is shown twice, and it looks messy.

The fix for the situation is not the easiest to accomplish, and I had been relying on the EXIFToolGUI to run through a multiple command process of copying XMP data to an external XMP file, removing the original xmp data and then copying the XMP data from the previously created file back into the original, and finally getting rid of the temporary XMP file created in the process. 

Needless to say, that got tiring, and I decided to learn how to use EXIFTool better in combination with the EXIFTool Command Processor (ECP), so that I could accomplish what needed to be done within IMatch, learn something along the way, and share with other users who may face similar issues.

I'll paste the contents of the argument window at the bottom, but I want to quickly outline what the arguments do.  I utilize the -execute parameter, which allows one to operate Exiftools multiple times from the same command line.  I'm not sure whether there might be a more efficient method, but what I used works, and it should rarely be needed... if you're lucky, you'll never need it.  I'm still not sure how duplicate records got there, but they are not from IM; they are either form Adobe products or Microsoft (google searches suggest some parts of Windows could do this).  In my case I'm mostly certain they come from Adobe as they present themselves in photos that have been processed in Lightroom and ACR (but not all the photos).

Procedure Outline:
1. Copy all XMP data to a temporary XMP file (Filename_a.xmp)    [the extra "_a" is in case the original data is in sidecars.  I don't have sidecars, so I haven't tested it]
    -  the copy process will only take a single copy (the first copy) of each XMP tag. 
2. Delete XMP data from original file
3. Set XMP data to XMP data from Filename_a.xmp (i.e. read the temporary XMP file back into the XMP record)
4. Move the temporary xmp file to another location (here it's called c:\Temp, but you can change that).
    -  I didn't want to keep the temporary XMP files, but I didn't see a way in exiftool to delete sidecar files of any type, so I just move them for deletion later. 
    -  The move also helps to provide a backup in case something goes wrong.

Intermediate to the steps listed I pasted in the "All Keywords" preset with an added "-a" argument to show all duplicate keywords.  This populates the Output window with the keywords fields as they evolve.

Please Test on a back-up / test-file first.

Also note that I have only run this using the run for each file in a selection option rather than once.  I'm not sure if this would work with the once option, but it could.

-overwrite_original
-use
MWG
-tagsfromfile
{File.FullName}
{File.Path}{File.Name}_a.xmp

-execute
-G1
-a
-IPTC:Keywords
-XMP:Subject
-XMP:HierarchicalSubject
{File.FullName}

-execute
-overwrite_original
-xmp=
{File.FullName}

-execute
-G1
-a
-IPTC:Keywords
-XMP:Subject
-XMP:HierarchicalSubject
{File.FullName}

-execute
-overwrite_original
-use
MWG
-xmp<={File.Path}{File.Name}_a.xmp
{File.FullName}

-execute
-G1
-a
-IPTC:Keywords
-XMP:Subject
-XMP:HierarchicalSubject
{File.FullName}

-execute
-srcfile
{File.Path}{File.Name}_a.xmp
-filename=C:\Temp\{File.Name}_a.xmp
{File.FullName}


Note that you can change the C:\Temp\ to any folder you like (but I think it has to exist).  You can also change the _a to anything you want or remove it, but you'll have to do it throughout the code.

You can also remove the blocks for outputting keywords.  I only use them there for visual confirmation that everything works cleanly.

-Erik


Erik

I also realize that some of this may be a no-duh for some, but like IM, I find EXIFTool a powerful and daunting program to run.

I really like Mario's implementation of the ECP here as it allowed me to somewhat clearly learn a bit more of EXIFTool.  I'd been struggling with the command line and GUI for a couple of weeks to put together the code above so I don't have to deal with that further in the future. 

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook