Merge metadata from one dataset to another

Started by juju22, March 14, 2024, 09:59:25 AM

Previous topic - Next topic

juju22

Hello,

I have two sets of pictures for which I am trying to merge metadata.
Set 1 is an automated backup of all image with YYYYMMDD directory tree but it misses some metadata.
Set 2 is a manual backup per album/selection of image which extra metadata, mostly ImageDescription.

From set 2, I am trying to
a. extract metadata to xmp sidecar
b. transfer xmp sidecar to same system than set 1 (reducing amount of data transfer)
c. for each xmp sidecar of set 2, restore selected metadata to set 1 matching image, mainly ImageDescription if present. eventually show other metadata difference.
d. if xmp sidecar in set 2, add exif rate:1 to matching set 1 image (~Favorite/Like)
e. if xmp sidecar in set 2, extract substring of set 2 parent folder and add it as exif keyword

Here are the commands that I'm currently thinking of

a. exiftool -ext EXT -o %d/%f.xmp -r SRCDIR
b. rsync
c. exiftool -ext EXT -tagsfromfile %d%f.xmp -all:all -r DIR
d. exiftool ${exiftool_arg} -rating=1 "$file"
e. exiftool ${exiftool_arg} -keywords+="$w" "$file"

Any pointers to make batch processing work and efficient?

Thanks

Note: set1 is from icloud photo downloader, set2 is manual export from ios device which seems the only way to get legend/ImageDescription.
References
https://exiftool.org/metafiles.html
-AddTagsFromFile per https://exiftool.org/forum/index.php?topic=14167.msg76291#msg76291

StarGeek

Quote from: juju22 on March 14, 2024, 09:59:25 AMa. extract metadata to xmp sidecar

One thing to understand is that not all data in a file will be XMP and an XMP sidecar can only hold XMP data. There are corresponding tag names, but they may not be the same name, requiring you to copy between them.

There are ARGS files that help transfer between different groups.  See here.
* 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).

juju22

Thanks StarGeek!
In my case, ImageDescription is in xmp file, so no issue there.

Here is my current script
#!/bin/sh
# Merge photo metadata between datasets
# https://exiftool.org/forum/index.php?topic=15827.0
# TODO
# * push only selected tags aka ImageDescription

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
umask 077

EXT=JPG
icloud_dir=~/Images/merge-datasets/set1
# meta_dir=~/Images/merge-datasets/set2
meta_dir=~/Images/merge-datasets/set2/album-singapore-manual-export

set -x

# Backup metadata
[ ! -f "${icloud_dir}-exif.csv" ] && exiftool -ext "${EXT}" -csv -r "${icloud_dir}" > "${icloud_dir}-exif.csv"
[ ! -f "${meta_dir}-exif.csv" ] && exiftool -ext "${EXT}" -csv -r "${meta_dir}" > "${meta_dir}-exif.csv"

# Extract tags to xmp file
# FIXME! don't copy image file
# exiftool -ext EXT -o %d/%f.xmp -r "${meta_dir}"
exiftool -ext "${EXT}" -o %f.xmp -r "${meta_dir}"
# grep -rin -A2 '<tiff:ImageDescription' ${meta_dir}/*.xmp

# rsync

# Push tags from xmp file to image
# FIXME! %d is from src subdir, dst subdir ignored... using one album dir. still NOK
# exiftool -ext EXT -tagsfromfile "${meta_dir}/%d%f.xmp" -all:all -r "${icloud_dir}"
# exiftool -tagsfromfile "${meta_dir}/%f.xmp" -all:all -r "${icloud_dir}"
# Supposing xmp file and img file have same filename but extension
for xmp in ${meta_dir}/*.xmp; do
  img=${xmp%%.xmp}
  img=${img##*/}
  havefile=`find "${icloud_dir}" -iname "${img}*.${EXT}" | wc -l`
  if [ "X${havefile}" = X1 ]; then
    file=`find "${icloud_dir}" -iname "${img}*.${EXT}" | xargs`
    exiftool -ext "${EXT}" -tagsfromfile "${xmp}" -all:all "${file}"

    # If in meta_dir/album, means favorite, add Rating 1
    exiftool -ext "${EXT}" -rating=1 "$file"

    # If in meta_dir/album, add Album name as keyword
    album=${xmp%/*.xmp}
    album=${album##*/}
    album=${album#album-}
    album=${album%-manual-export}
    exiftool -ext "${EXT}" -keywords+="${album}" "$file"

  elif [ ${havefile} -gt 1 ]; then
    echo "Warning! Multiple files matching $img in $icloud_dir"
  fi
done

[ ! -f "${icloud_dir}-exif2.csv" ] && exiftool -csv -r "${icloud_dir}" > "${icloud_dir}-exif2.csv"

# Check
# grep <album> merge-datasets/set1-exif2.csv | cut -d',' -f 55,87,88,97,98,103,132

set +x