2 Replies Latest reply on May 24, 2016 11:38 AM by DFBurns

    Custom metadata plugin: how to run code automatically for new files?

    DFBurns Level 1

      I have a goal of seeing some Fuji-specific metadata fields within Lightroom. I can see these when I run Fuji files through Exiftool from the command line. I'd like to be able to filter and search on them. (Before going on, if anyone knows of an existing plugin that will import arbitrary EXIF data from Exiftool, please let me know.)

       

      I can write a custom metadata plugin for this. Defining the custom fields and tagset is clear to me; I've done that before. What's not clear to me is how to trigger the code that scans files for the metadata and imports that. I can have the user do it manually by selecting images and then using a menu option - that's easy. Is there a way to invoke that automatically instead? Say, when files are imported?

       

      Other opinions on how this could work smoothly are welcome. Thanks,

       

      db

        • 1. Re: Custom metadata plugin: how to run code automatically for new files?
          johnrellis Most Valuable Participant

          There used to be a plugin ExifMeta that would automatically synchronize one or more fields from the image to custom metadata in the catalog, available for display, filtering, and searching.   Unfortunately, the developer disappeared, along with his plugins, about 1.5 years ago.

           

          The Data Explorer plugin lets you view and search arbitrary metadata fields accessible to Exiftool.  But you have to run it manually each time you want to see the current values.

           

          What's not clear to me is how to trigger the code that scans files for the metadata and imports that.

          The plugin needs to have a background task (or tasks) that runs periodically and checks for new files and files that have changed since the last time it extracted their metadata.  This can be made pretty efficient, but it takes effort.

           

          The background task can scan for new photos by calling catalog:getAllPhotos() and comparing the result with the last time it called it.   I'd guess doing this every 5 seconds wouldn't consume any noticeable CPU.  It could be implemented in 10 or 20 lines.

           

          If you care about the plugin noticing changes to files' metadata after they've been imported into LR (e.g. because an external app changed them), that would be harder to do in a timely way.  The plugin could record the file's modification date in custom metadata for a photo each time it extracted metadata.  The background task would periodically sweep through all photos in the catalog, looking for files whose current modification date is newer than that recorded in custom metadata.   I don't have a good feel for the CPU cost this would impose, but I'd guess you could probably do 10 files/second without noticeable load.  That would mean it would take several hours to sweep through a catalog of 100K files.   (Windows and OS X have mechanisms to notify apps of changes to the file system, but those mechanisms aren't available via the SDK of course.)

           

          With further complexity, you could also have a background task that periodically uses catalog:findPhotos() to run the smart-collection criteria "Medata Status is Changed On Disk or Metadata Status is Conflict Detected".  This would piggyback on LR's mechanism for noticing that files have changed and would be very low-cost. You could run that query every few seconds without any noticeable impact.  However, there's a chance that this task would miss some changed photos, e.g. if the user did Metadata > Read Metadata From File before the task had a chance to notice the file had changed.  So you'd still need to the task that periodically sweeps all photos in the catalog.

           

          I never asked the developer of ExifMetadata exactly what it did on this score, but I'm guessing something similar.

          • 2. Re: Custom metadata plugin: how to run code automatically for new files?
            DFBurns Level 1

            Ah, thanks, John. I'd forgotten about ExifMeta and that Rob had written it (his disappearance is mysterious indeed). I Googled around and found someone with their own download link to version 5.9. I'll give that a whirl. It'll be great to save myself the development time if it still works with CC 2015.5.1.

             

            db