fdenivac / Lightroom-SQL-tools

Python scripts to retrieve and displays photos informations from lightroom catalog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extracting development settings of images

l-salewski opened this issue · comments

I am currently trying to identify duplicate virtual copies which lightroom created after some partially failed catalog imports. These copies should be identical (almost) all aspects, most importantly the development settings.
So far I have identified a number of virtual copies which are identical according to a number of columns that I can access with this tool (e.g. "rating", "colorlabel", "keywords", "dims", "caption", "creator", "latitude", "longitude", "pubname"). However, this does not differentiate between virtual copies which only differ in their development settings.

Thus, it would be nice to also access image development settings like exposure and white balance. Therefore, I am kindly asking whether this would be possible?

Unfortunately, it's not that simple: indeed the development parameters are all stored in the xmp field (a string in Extensible Metadata Platform format) of the Adobe_AdditionalMetadata table.
It is therefore not possible to access a particular setting by SQL queries.
But you may be able to draw inspiration from the code below to achieve your goals...

import sys
import hashlib
from lrtools.lrcat import LRCatDB, LRCatException
from lrtools.lrselectgeneric import LRSelectException

try:
    lrdb = LRCatDB(r"F:\Lightroom\work.lrcat")
    rows = lrdb.lrphoto.select_generic("master", "vcopies=true").fetchall()
    print(f"{len(rows)} virtual copies")
    # get all masters
    masters = [
        row[0]
        for row in lrdb.lrphoto.select_generic("master", "vcopies=true").fetchall()
    ]

    for master in masters:
        master_name, xmp = lrdb.lrphoto.select_generic(
            "name, xmp", f"id='{master}'"
        ).fetchone()
        hash = hashlib.md5(xmp.encode("utf-8")).hexdigest()
        print(f"Master | {master_name} |  | {hash}")

        for idphoto, short_name, vname, xmp in lrdb.lrphoto.select_generic(
            "id, name, vname, xmp", f"vcopies='{master}'"
        ).fetchall():
            hash = hashlib.md5(xmp.encode("utf-8")).hexdigest()
            print(f"Virtual copy | {short_name} | {vname} | {hash}")

except (LRCatException, LRSelectException) as _e:
    sys.exit(" ==> FAILED: %s" % _e)