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

Extract XMP

HamzaFarhan opened this issue · comments

Is there a way wo load a catalog and extract all the xmp files along with their images? Like in a dictionary or 2 lists?

Yes there is a way to extract all the xmp files from a catalog, but not for the images themselves, because lightroom only has the reference of the original file (without development settings).
For extract all xmp files in same directories as original images :

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

try:
    lrdb = LRCatDB("C:\Lightroom\La Totale\La Totale.lrcat")
    for original_image_name, xmp in lrdb.lrphoto.select_generic('name=full, xmp', '').fetchall():
        directory, _ = os.path.split(original_image_name)
        basename, _ =  os.path.splitext(os.path.basename(original_image_name))
        xmpname = os.path.join(os.path.normpath(directory), basename + '.xmp')
        with open(xmpname, 'w') as xmpfile:
            xmpfile.write(xmp)
            xmpfile.close()
except (LRCatException, LRSelectException) as _e:
    sys.exit(' ==> FAILED: %s' % _e)