Skip to content

Instantly share code, notes, and snippets.

@elcontraption
Created March 14, 2012 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elcontraption/2039718 to your computer and use it in GitHub Desktop.
Save elcontraption/2039718 to your computer and use it in GitHub Desktop.
Director.lua snippet
function DirectorAPI.processExport( functionContext, exportContext )
prefs.useMetaData = exportContext.propertyTable.useMetaData
prefs.openDirector = exportContext.propertyTable.openDirector
local exportSession = exportContext.exportSession
local nPhotos = exportSession:countRenditions()
local album_type = exportContext.propertyTable.album_type
local new_album_name = exportContext.propertyTable.new_album_name
local album_id = exportContext.propertyTable.selected_album_id
local progressScope = exportContext:configureProgress{
title = nPhotos > 1
and string.format("Uploading %d photos to %s", nPhotos, prefs.directorURL)
or "Uploading one photo to " .. prefs.directorURL,
}
if album_type == 2 then
album_id = DirectorAPI.createAlbum(new_album_name)
end
prefs.lastAlbum = album_id
for i, rendition in exportContext:renditions() do
-- Wait until Lightroom has finished rendering this photo.
local success, pathOrMessage = rendition:waitForRender()
local photo = rendition.photo
if progressScope:isCanceled() then break end
-- Do something with the rendered photo.
if success then
local title, caption, keywords
if exportContext.propertyTable.useMetaData then
photo.catalog:withReadAccessDo( function()
title = photo:getFormattedMetadata 'title'
caption = photo:getFormattedMetadata 'caption'
keywords = photo:getFormattedMetadata 'keywordTags'
end )
else
title, caption, keywords = nil
end
DirectorAPI.uploadPhoto{ filePath = pathOrMessage, album = album_id, title = title, caption = caption, tags = keywords }
else
-- when success if false, pathOrMessage contains the error message
error( pathOrMessage )
end
end
if exportContext.propertyTable.openDirector then
to_append = ''
if DirectorAPI.isLocal() then
to_append = '/index.php?'
end
local content_tab = 'http://' .. prefs.directorURL .. to_append .. '/albums/edit/' .. album_id .. '/content'
LrHttp.openUrlInBrowser( content_tab )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment