Copy XMP keywords to other files

Ideas for improvements and requests for new features in XnView MP

Moderators: XnTriq, helmut, xnview

Post Reply
User avatar
orbspider
Posts: 170
Joined: Tue May 22, 2012 5:42 pm
Location: Malayan jungle
Contact:

Copy XMP keywords to other files

Post by orbspider »

Hi there, I am back after quite a few years of silence! Trying to sort out my database just now and need to do some tricky tasks....

Here's the problem:
I have a set of original pictures, around 25,000, organized in dozens of folders. Then I have reduced size copies of these, same file names, same folder names (created in the days of a core duo laptop to save space and resources).
The reduced size set have been tagged with multiple keywords, according to what they show. The original set was not tagged (did the tagging after size reduction.)

So now with a better PC and without display or memory limitations I have reinstated the originals as my main catalogue images.

The task now is to write those keywords from the reduced copies to the originals!!

At the moment the options are:

1. using command line
  • look at a folder of images from reduced set with category sets showing and select all to see what keywords are used.
  • with category filter find and select all images of one keyword
  • do copy to clipboard > file names
  • on the command line use find piped to xargs to write the keyword with exiftool to the files in the originals folder
(another way would be to move those original files matching the names on clipboard to a new folder, but that would be a painful doing it over and over)


2. find similar tool
Find similar files does not allow me to select all the resulting found files and move them all together (to be written with keywords) - if the results linked to batch commands it might be useful in this task.


Ideally, I'd love to be able to...
  • select files in a folder (from category filter)
  • do copy to clipboard > file names
  • move to other folder and run "select files from a file list on the clipboard"
  • apply the category (keywords) to them

Currently there's no option to do this - is this so special case? as normally two folders don't have files with the same file names in them, or do they?

Showing sub-folders in Xnview would help speed up the process, while using two instances of Xnview - one to find files with keywords, one to select files from originals and write keywords.

Another idea would be a batch tool to copy a file's metadata to file of same name somewhere else!!!


Batch convert tool idea:
Under Output: checkbox "Write metadata to files of same name (embedded)" / "Write metadata to files of same name (sidecar)"

Of course, if files have been renamed at any stage separately then this won't work at all.

Any better ideas?
Last edited by orbspider on Sun Jul 26, 2020 3:42 am, edited 1 time in total.
User avatar
ramses
Posts: 27
Joined: Sun Jan 10, 2010 10:54 pm

Re: Copy IPTC data to other files

Post by ramses »

Have a look at this topic, if you are using Linux and Python. It's possible to manage IPTC or XML tags too.
viewtopic.php?f=83&t=39060&p=157159#p157159
Jean
LinuxMint 15 / XnView MP 0.64
User avatar
michel038
XnThusiast
Posts: 1291
Joined: Tue Sep 27, 2016 8:18 am
Location: France
Contact:

Re: Copy IPTC data to other files

Post by michel038 »

Hi,
If files have same names, you can use ExifTool (or XnViewMp) to create a csv file containing full filenames, and keywords.
Then adjust paths in this file with a text editor, and import the keywords in original photos with ExifTool again, using -csv option.
If you need more precisions, please tell us if you know -r, -k, -restore_original, ... options in ExifTool, and the name of metadata containing keywords ( iptc:keywords without hiérarchy ?)
See also http://carlibrary.org/ExifTool.htm
User avatar
orbspider
Posts: 170
Joined: Tue May 22, 2012 5:42 pm
Location: Malayan jungle
Contact:

Re: Copy IPTC data to other files

Post by orbspider »

HI, I'm not too fluent with python, unfortunately... neither French!

The commands I use with exiftool call -subject -hierarchicalsubject

Actually for option 1. above, no need for xargs as I am starting with a list, so I would use..

Code: Select all

while read line; do
  find . -name "$line" -exec exiftool -m -overwrite_original -xmp:subject+="" '{}' \; < filelist

So this is xmp not iptc afterall?

I will look into exiftool more and creating the csv and restoring to files. If done right that could be a great solution.
User avatar
orbspider
Posts: 170
Joined: Tue May 22, 2012 5:42 pm
Location: Malayan jungle
Contact:

Re: Copy XMP keywords to other files

Post by orbspider »

Pretty good tutorial that, thanks for the pointer.

So here's what I came up with..

Code: Select all

#!/bin/bash
#script to save xmp keywords from files and restore them to files of same name elsewhere. Dir tree needs to be identical except for top parent which is replaced by perl command in the created file, keywds.

exiftool -r -subject  -hierarchicalsubject -rating -csv >keywds "`yad --center --title='Select dir to save XMP data from' --file --directory --filename=/media/D1/ --height=400 --width=500`"

perl -pi -e 's/photo_reduced/my_pics/g' keywds

exiftool -r -csv=keywds -ext jpg -overwrite_original  "`yad --center --title='Select dir to write XMP data to' --file --directory --filename=/media/D1/ --height=400 --width=500`" > script_output

I noticed that files can be skipped due to minor errors, and hence I want to examine these errors after the script runs, hence the redirection, > script_output
Also the reason for selecting directories is to offer more control, or to work in stages through several sub-dirs


Edit: actually there are way too many files with minor errors (makernotes offset), -F option to fix them does not work, only -m option to ignore errors does.
User avatar
orbspider
Posts: 170
Joined: Tue May 22, 2012 5:42 pm
Location: Malayan jungle
Contact:

Re: Copy XMP keywords to other files

Post by orbspider »

Something aint working right with the exiftool restore. If I compare a file from reduced set with a file with restored categories, they look identical (at least with the exiftool output)...
but maybe Xnview sees something different, that the external process did to the xmp data.

When I import these restored files, according to Xnview, multiple categories are listed as Subject[1] and there is no Subject[2] or Subject[3] etc

eg.
Subject[1] flower, colours

not
Subject[1] flower
Subject[2] colours

Also, new categories are made with multiple keywords

eg. "flower, colours" as one category

The only work around will be to do a filter Global on one of these new categories, then apply the individual categories that the file(s) should have, then remove the bogus category

Also I noticed that if I wanted to add a category to any of these files which had the xmp subject restored with exiftool, then the XMP data is recreated and previous subjects are lost.
Post Reply