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

Extract XMP #2

Open HamzaFarhan opened 3 years ago

HamzaFarhan commented 3 years ago

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?

fdenivac commented 3 years ago

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)