fdenivac / Lightroom-SQL-tools

Python scripts to retrieve and displays photos informations from lightroom catalog
GNU General Public License v3.0
27 stars 3 forks source link

Extracting development settings of images #3

Open l-salewski opened 1 year ago

l-salewski commented 1 year ago

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?

fdenivac commented 1 year ago

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)