Skip to main content
Participant
November 14, 2014
Answered

How to use certain entries from a txt file as metadata?

  • November 14, 2014
  • 1 reply
  • 968 views

So during my plugin development I stumbled on a problem.

I have created a txt file for each picture telling me who's in the photos. So the first column in the file shows all the names that appear in the photo.

I want to add those names into LR for each photo. I thought using them as metadata would be a good idea. Then I could let the user enter a name of some person and create a smart collection having all photos with that person in them.

But putting it into practice isn't that easy.

So I started with the classic metadata definition:

metadataFieldsForPhotos = {

  {

  id = 'Person',

  title = 'Person'

  dataType = 'string',

  searchable = true,

  browsable = true,

  },

  },

Now I don't know how to actually read only the column entries of the txt file and displaying all the names appearing in it. Another problem is that each photo has its own txt file in "nameofphoto.jpg.txt" So LR must know which txt file belongs to a photo.

I know my question isn't very specific but it would be great if someone could help...

This topic has been closed for replies.
Correct answer johnrellis

That error message means another plugin is trying to access the catalog.  Perhaps you had another instance of your plugin that you ran that was still running in background?  Do you have other plugins installed that access the catalog in background?

The first thing to try is to add a timeout parameter of, say, 15 seconds.

Also, you'll find out soon enough that you need to pass a boolean parameter to catalog:createKeyword() to return an existing keyword if it already exists.

1 reply

johnrellis
Legend
November 14, 2014
Now I don't know how to actually read only the column entries of the txt file and displaying all the names appearing in it.

You can use LrFileUtils.readFile() to read the contents of a file into a string.

Another problem is that each photo has its own txt file in "nameofphoto.jpg.txt" So LR must know which txt file belongs to a photo.

photo:getRawMetadata ("path") will get you the full file path of a photo, which you can then use to find and open the corresponding .txt file.

So I started with the classic metadata definition:

Are you sure you want to create your own plugin-specific fields that can only be read by your plugin and LR?  Consider instead using industry-standard metadata fields.  E.g. the plugin could put the person names into a keyword and attach the keyword to the photo, or it could use the IPTC Extension field Person Shown (which might be better depends on the downstream use of the photos).   The plugin can set the metadata fields using photo:setRawMetadata().

Nebula85Author
Participant
November 16, 2014

Thank you for the reply. Reading the file how I wanted worked fine and I chose to use keywords, as you suggested.

So now I tried to add the keywords to the pictures and I get:

"LrCatalog:withWriteAccessDo: could not execute action 'keywordProvider'. It was blocked by another write access call, and no timeout parameters were provided."

There's my function so far:

function Finder.findPerson(smartCollectionName)

     local catalog = LrApplication.activeCatalog()

     local photos = catalog:getMultipleSelectedOrAllPhotos()

       LrTasks.startAsyncTask( function()

            for i=1,#photos do

                 local photo = photos

                 local photopath = photo:getRawMetadata("path")

                 local photoname = photo:getFormattedMetadata("fileName")

                 local folderpath = string.sub(photopath, 1, string.len(photopath) - string.len(photoname))

                 local metadataPath = folderpath .. "\.metaface\\" .. photoname .. ".txt"

                 local text = LrFileUtils.readFile(metadataPath)

                 local metadataValues = stringSplit(text)

                 for i = 0, #metadataValues do

                      catalog:withWriteAccessDo( "keywordProvider", function()

                           local keywords = catalog:createKeyword(metadataValues)

                           photos:addKeyword(keywords)

                      end)

                 end

           end

      end)

end


So what am I doing wrong?

johnrellis
johnrellisCorrect answer
Legend
November 17, 2014

That error message means another plugin is trying to access the catalog.  Perhaps you had another instance of your plugin that you ran that was still running in background?  Do you have other plugins installed that access the catalog in background?

The first thing to try is to add a timeout parameter of, say, 15 seconds.

Also, you'll find out soon enough that you need to pass a boolean parameter to catalog:createKeyword() to return an existing keyword if it already exists.