22 Replies Latest reply on Feb 5, 2015 2:54 PM by craigs22120920

    Accessing custom metadata from Web Engine gallery

    Blatman888
      Hi folks - using LR 2.0 and slogging through the SDK and Web Engine stuff.
      Basically, can custom metadata fields from a plugin be accessed from a Web Engine at all and if so how?

      I have managed to create a custom metadata field (I don't really want to use one of the inbuilt dedicated metadata fields) in the Library module and it works fine, I can add notes to each image and the info is kept in the Catalog not in the XMP or with image (SDK says this) however I wish to access this field from the Web Gallery via the galleryInfo.lrweb file but not sure how or if it can be done.

      My custom plugin name is "nz.org.wh.metadata.photogallerynotes" and the field id (set in metadataFieldsForPhotos = { part of plugin ) is "notes".
      I tried using the perImageSettings parameter with "nz.org.wh.metadata.photogallerynotes.notes" as a value but no good - I think maybe that the perImageSetting parameter can only be used with "com.adobe" type fields such as title, caption, etc. Maybe I am asking for a LR 3.0 DCR ... :-)

      Cheers.
        • 1. Re: Accessing custom metadata from Web Engine gallery
          SeanMcCormack Adobe Community Professional
          I've been thinking about that myself. Let me know if you find anything ;)
          • 2. Re: Accessing custom metadata from Web Engine gallery
            I would have responded sooner, but I just learned this myself (you may have figured it out yourself already). You should be able to do something like this in your web engine gallery:

            local catalog = import'LrApplication'.activeCatalog()

            catalog:withWriteAccessDo('some_string', function()

            local photos = catalog:findPhotosWithProperty('nz.org.wh.metadata.photogallerynotes', 'notes')

            for i, v in ipairs(photos) do
            -- whatever it is you want to do with these photos...
            end
            end)

            In my own experiment, this code appears inside the 'action' function for a button which appears in a panel for my web engine gallery, and the property was written by a plug-in appearing as a 'plug-in extra'.

            The above code assumes, of course, that the 'notes' property was successfully written at some point in the past by the plugin identified by 'nz.org.wh.metadata.photogallerynotes'

            Hope this helps.
            • 3. Re: Accessing custom metadata from Web Engine gallery
              Blatman888 Level 1
              Looks interesting Chet - using the lua search methods. However wasn't aware that a button with an action could be used in the Web engine UI Panels ( not really mentioned in SDK). Maybe a binding would be possible with a nonCSS parameter in the galleryInfo.lrweb file and therefore allow the notes metadata for each image to be inserted into the HTML.
              Alternatively I was thinking that if the notes metadata could somehow be inserted (and be selectable) into the Text Template Editor that is used from the UI panels then that may provide a key.
              Cheers.
              • 4. Re: Accessing custom metadata from Web Engine gallery
                Level 1
                I'm just learning the web engine side of things myself, and now I think I am beginning to understand better what it is you need.

                I just realized (and verified) that I can define custom tags to get at custom metadata for display with each photo in the grid view (and presumably other views as well). In the definition of the custom tags, you have the opportunity to write LUA functions which dig into the custom metadata using LrPhoto:getPropertyForPlugin, LrCatalog:findPhotosWithProperty, etc. Custom tags are described in the SDK guide.
                • 5. Re: Accessing custom metadata from Web Engine gallery
                  Blatman888 Level 1
                  Yes, I had a quick glance at the custom tags stuff a while ago but moved away from it since the custom tags will be OK in LR as XML but I want to keep standard HTML tags on the web pages. Essentially what I am doing is creating an XHTML 1.0 web page and through the use of CSS and Javascript it will show a bunch of scrollable thumbs (in a grid page) which will if clicked open a large image in another box (with Thickbox optional) . Info such as caption, exif/iptc ( & notes ) is presented on the page in different formats. This essentially is a personal photo album which can be used on a local web or even CHM'd. I'm moving a pre-populated XHTML web page into LR so I can develop a Web Engine that will allow CSS tuning and image/metadata generation on the page so any info entered in the library module against an image will be available in the Web Gallery and be written to the HTML via the galleryInfo.lrweb file. Currently the original XHTML page contains metadata in SPAN tags with ID's attached so LR can populate these easily (except custom notes at this stage). The other possibility I was thinking of was trying to get the custom notes written out to an XML file which can then be DOM parsed by Javascript back into the XHTML - however it would be nice to keep as much of the 'machinery' inside LR. Extending the perImageSettings to encompass custom metadata rather than just adobe.com metadata would do the trick obviously .... Adobe listening????? The end result for quite a large album will be an XHTML page full of grid frames with associated span tags containing attached metadata that can be presented via CSS/JS. Bandwidth is no issue being a local photo album (just like the ol' paper ones!).
                  • 6. Re: Accessing custom metadata from Web Engine gallery
                    john beardsworth Adobe Community Professional & MVP
                    I think you have a good point in there, Blane. It's no good Adobe letting us add custom fields if we can't do much with them, whether it's displaying them in Web, Print, or saving the information to the image sidecar or embedded metadata.
                    • 7. Re: Accessing custom metadata from Web Engine gallery
                      Blatman888 Level 1
                      Yes John I agree - it did cross my my mind about being able to add custom metadata to the library module but not being able to use it in another module. I guess Adobe has this sort of thing in the 'pipeline' for a later version and I suppose that is what SDK's are all about. It does seem though that the modules are being developed somewhat as separate 'silos' in some cases - interestingly I was looking at the Slide module the other day and was thinking about the Text Overlay feature which is nice and adjustable for font/size/position, etc and I thought how good would this be if it could be used as the Watermark in the Web Module ( at the moment I just exit the 'professional' app and use Faststone to do watermarks).
                      Probably if I can't work out all the Lua stuff eventually I'll have to just write the notes into the XHTML pages directly and forget about entering the info as metadata in the catalog - tedious!
                      • 8. Re: Accessing custom metadata from Web Engine gallery
                        SeanMcCormack Adobe Community Professional
                        Blane,
                        The guy doing the Web Module and the Slideshow Module are one and the same: Andy Rahn (Hi Andy!). Better watermarking would be great indeed...
                        • 9. Re: Accessing custom metadata from Web Engine gallery
                          Chet,

                          How did you use LrPhoto:GetPropertyForPlugin?
                          I get an error when using it: Galleries\mysample.lrwebengine\myExampleTags.lrweb:41: attempt to index global 'LrPhoto' (a nil value).
                          • 10. Re: Accessing custom metadata from Web Engine gallery
                            Did you remember to put "local LrPhoto = import 'LrPhoto'" somewhere before this?
                            • 11. Re: Accessing custom metadata from Web Engine gallery
                              Blatman888 Level 1
                              Hello again folks,<br />Been trying a few things and have now managed to extract custom<br />metadata from the catalog (via plugin) into a table which can be<br />written into the index.html page produced by the web engine. Once <br />in the XHTML page the data can be DOM parsed with javascript and<br />used appropriately.<br /><br />Code in galleryInfo.lrweb file ::<br />(thanks Chet for your guidance earlier in thread)<br /><pre><br /><br />-- placed before return { at top of file<br /><br />     START<br />     local LrApplication = import 'LrApplication'<br />     local LrDialogs = import 'LrDialogs'<br />     local LrStringUtils = import 'LrStringUtils'<br /><br />     catalog = LrApplication.activeCatalog()<br />     catalog:withReadAccessDo( function()<br />          photos = catalog.allPhotos<br />     end )<br />          local container1 = "<div>" .. "\n"   -- omit if hippo array used<br />          local buffString = "" .. container1<br /><br />     for i, photo in ipairs(photos) do<br />          biggo = nil<br />          catalog:withReadAccessDo( function()<br />               biggo = photo:getPropertyForPlugin( 'nz.org.wh.metadata.photogallerynotes', 'notes' )<br />          end )<br /><br />          local tagno = i<br />          local tag = '<span id="pgs' .. tagno .. '" class="thickbox">'<br />          if biggo ~= nil then                              <br />               tnotes = LrStringUtils.trimWhitespace(biggo)<br />               tag = tag .. tnotes .. "</span>" .. "\n"<br />          else<br />               tag = tag .. "</span>" .. "\n"               <br />          end<br /><br />          hippo[i] = tag  -- alternative is to populate an array, working on this<br />               <br />          buffString = buffString .. tag<br />     end -- for/do<br />     <br />          buffString = buffString .. "</div>"<br /><br />     local notes = buffString -- use if span's in div required, hippo array doesn't require<br /><br />     FINISH<br />     <br />     buffString (or notes) should give something like -<br />     <br />     <div><br />     <span id="pgs1" class="thickbox">1st photo notes</span><br />     <span id="pgs2" class="thickbox">2nd photo notes</span><br />     ..... etc<br />     </div><br />     <br />     The notes variable can be attached to a model item -<br />     <br />     eg:  ["nonCSS.hippo"] = notes,<br />     <br />     This model item can then be inserted into the XHTML index template using<br />     <br />     <%= metadata.notes %>  type notation.<br />     <br />     Once embedded in the index page the data can be extracted with javascript<br />     DOM parsing and then styled etc.<br />     <br />     Ideally I wanted to take each unique span id line and use it in the grid<br />     (this can be done with the com.adobe metadata OK) along with cellIndex but just <br />     can't manage to get it to work (closest I get is Table 0E444720 or whatever).<br />     I used the hippo[x] array to store the unique span id's -<br />     eg:<br />     in galleryInfo -<br />     ["metadata.notes3"] = hippo[3],<br />     then in XHTML template -<br />     <%= model.metadata.notes3 %> <br />     Result: <span id="pgs3" class="thickbox">3rd photo notes</span> <br />     Works fine (but can't use hard-coded number in GridPhotoCell repetitively)<br />     <br />     in galleryInfo -<br />     ["metadata.notes"] = hippo,<br />     then in XHTML template -<br />     <%= model.metadata.notes %>[<%= cellIndex %>] <br />     Result: table: 0E444720[3]<br />     No good<br />     <br />     STOP PRESS::::<br />     Tried - hippo array method<br /><br />function initializeArray ( elementCount )<br /><br />    local tmpArray = {}<br /><br />    for i=1, elementCount do<br />        tempArray[i] = 0<br />    end<br /><br />    return tmpArray<br />end<br /><br />hippo =  initializeArray ( 13 )<br />     <br />     in galleryInfo -<br />     ["metadata.notes"] = hippo,<br />     then in XHTML template -<br />     <%= model.metadata.notes[cellIndex] %><br />     Result: <span id="pgsx" class="thickbox">x photo notes</span> <br />     Damn good!!!!!!!!!!  Life is good again!<br />     <br />     I can now get something like -<br />     <lr:GridPhotoCell><br />     <div class="frame"><br />          <a id="pg-3" href="#nogo" onmouseover="xshow_notes('3')" onclick="load_snap('3')" rel="ja" title="Typical farming homestead"><span class="itemNumber">3</span><img src="images/pg/thumb/ja_03.jpg" alt="pg 3" class="gallerythumb" title="" /></a><br />          <span id="pgs3" class="thickbox">You could almost be forgiven that it was Switzerland! The coos (Scottish accent there) looked healthy enough.</span><br />          <span id="pge3">Canon EOS 5D,EF24-105mm f/4L IS USM,1/100 sec at f / 13,ISO 100,Shutter priority,Did not fire,,-2/3 EV,Pattern,28 mm,02/07/2007 10:41:29,600 x 400</span><br />          <span id="pgi3">BlatSnap,UK,© BlatSnap</span><br />          <span id="ifn3">ja_03</span><br />     </div><br />     </lr:GridPhotoCell>     <br />     <br />     So after c. 62,003 restarts of LR I can now move custom metadata from the Library module<br />     in the WebEngine to exported web pages.<br />     <br />     I think this code can also be shifted to a button in the UI panel<br />     which I have learn't how to use by perusing the Fotoplayer plugin.<br />     (Thanks again Chet for the clue that buttons can be used in the WE)<br />     This would allow notes to be updated in Library then processed in the WE.<br />     <br />     As a sidenote this code can be used along with the LrXML and LrLogger to produce XML dumps of all<br />     metadata.<br />     <br />     I suppose a new version will now appear from Adobe that will do this elegantly in c. 3 lines ... :)<br />     - and a lot less heavy animal references.<br />     <br /></pre>
                              • 12. Re: Accessing custom metadata from Web Engine gallery
                                SeanMcCormack Adobe Community Professional
                                62,003 restarts is why I want a restart shortcut key :)

                                Nice work Blane, although it takes some reading.

                                I've literally only started calling LrColor inside a Web Engine and am working my way through the rest of the [non Web] SDK.
                                • 13. Re: Accessing custom metadata from Web Engine gallery
                                  Blatman888 Level 1
                                  Unfortunately my last post didn't show all the HTML details but it does show if the Page Source is viewed - this will make the examples clearer.
                                  Cheers.
                                  • 14. Re: Accessing custom metadata from Web Engine gallery
                                    DawMatt Level 3
                                    Sean, Blane,

                                    Not quite a "restart shortcut key" but I have just posted a Lightroom restart script here:
                                    http://thephotogeek.com/lightroom-power-nap-restart-script/

                                    Makes those 62,003 restarts a one step process at least. :-)

                                    Matt
                                    • 15. Re: Accessing custom metadata from Web Engine gallery
                                      Blatman888 Level 1
                                      Thanks Matt,

                                      seems to work OK and will save a few keystrokes whilst I fumble about in the not so 'light' room with this Lua stuff.

                                      Cheers,

                                      Blane
                                      • 16. Re: Accessing custom metadata from Web Engine gallery
                                        Blatman888 Level 1

                                        Here we go - the forums have changed so I have attached a text file with the html/lua stuff which should make a lot more sense.

                                         

                                        Cheers,

                                        Blane

                                        • 17. Re: Accessing custom metadata from Web Engine gallery
                                          craigs22120920

                                          Have things advanced in Lightroom to support access to custom metadata in a web gallery plugin? @Blatman888, I have tried to understand the workflow in fixup.txt, but with no luck. Are there sample plugins that can be reviewed?

                                           

                                          I recently posted this question on stackexchange looking for help:

                                          lua - In Lightroom how do you reference custom metadata in a web plugin? - Stack Overflow

                                           

                                          Thanks,

                                          Craig

                                          • 19. Re: Accessing custom metadata from Web Engine gallery
                                            johnrellis Most Valuable Participant
                                            Have things advanced in Lightroom to support access to custom metadata in a web gallery plugin?

                                            I don't totally understand the web engine, but I was able to modify the SDK example "mysample.lrwebengine" to show another plugin's custom metadata field underneath the image shown on "large.html".  The basic idea is to map the image proxy returned by getImage(index) to its corresponding LrPhoto in the catalog, using the image proxy's "imageID" property.  That "imageID" property is the the same as the underlying photo's "localIdentifier" property.  Once you have an LrPhoto, you can use the photo:getPropertyForPlugin() method to retrieve the custom metadata field for any plugin.

                                             

                                            Here's a modified version of "large.html" that displays the metadata field "file" of the plugin "com.johnrellis.anyfile" underneath the image:

                                            <%
                                            --[[ Define some variables to make locating other resources easier.]]
                                            
                                                local image = getImage( index )
                                                local theRoot = ".."
                                                local others = "."
                                                local mySize = "large"
                                            
                                            --[[ Code added by John R. Ellis ]]
                                            local LrApplication = import 'LrApplication'
                                            local catalog = LrApplication.activeCatalog ()
                                            local idToPhoto = {}
                                            for _, photo in ipairs (catalog:getAllPhotos ()) do
                                                idToPhoto [photo.localIdentifier] = photo
                                                end
                                            local photo = idToPhoto [image.imageID]
                                            local anyfileFile = photo:getPropertyForPlugin ("com.johnrellis.anyfile", "file")
                                            --[[ End code added by John R. Ellis ]]
                                            %>
                                            
                                            
                                            <% --[[ Include the page header]] %>
                                            <%@ include file="header.html" %>
                                            <div>
                                                <ul>
                                                  <lr:Pagination>
                                                    <lr:PreviousEnabled>
                                                      <li><a href="$link">Previous</a></li>
                                                    </lr:PreviousEnabled>
                                                    <lr:PreviousDisabled>
                                                      <li>Previous</li>
                                                    </lr:PreviousDisabled>
                                                    <li><a href="$gridPageLink">Index</a></li>
                                                    <lr:NextEnabled>
                                                      <li><a href="$link">Next</a></li>
                                                    </lr:NextEnabled>
                                                    <lr:NextDisabled>
                                                      <li>Next</li>
                                                    </lr:NextDisabled>
                                                  </lr:Pagination>
                                                </ul>
                                            </div>
                                             <a href="$gridPageLink">
                                            <img src="bin/images/large/<%= image.exportFilename %>.jpg" />
                                            </a>
                                            
                                            <pre> <%= --[[ Code added by John R. Ellis ]]
                                            "Value of com.johnrellis.anyfile:file -- " .. (anyfileFile or "") 
                                            --[[ End of code added by John R. Ellis ]] %> 
                                            </pre>
                                            
                                            <xmpl:aQuote>You know what they say:<br>
                                              <xmpl:saying> <br />....how interesting!<br /></xmpl:saying>
                                            </xmpl:aQuote>
                                            
                                            <% --[[ Include the page footer]] %>
                                            <%@ include file="footer.html" %>
                                            
                                            • 20. Re: Accessing custom metadata from Web Engine gallery
                                              craigs22120920 Level 1

                                              Thank you. Very helpful.  Sorry to ask for this, but how would you do it if you were to add custom metadata to the grid.html, perhaps adding the metadata below the thumbnail?

                                               

                                              Craig

                                              • 21. Re: Accessing custom metadata from Web Engine gallery
                                                johnrellis Most Valuable Participant
                                                <%
                                                --[[ Define some variables to make locating other resources easier.]]
                                                   
                                                    local mySize = "thumb"
                                                    local others = "content"
                                                    local theRoot = "."
                                                
                                                --[[ Code added by John R. Ellis ]]
                                                local LrApplication = import 'LrApplication'
                                                local catalog = LrApplication.activeCatalog ()
                                                local idToPhoto = {}
                                                for _, photo in ipairs (catalog:getAllPhotos ()) do
                                                    idToPhoto [photo.localIdentifier] = photo
                                                    end
                                                --[[ End code added by John R. Ellis ]] 
                                                %>
                                                
                                                <% --[[ Include the page header]] %>
                                                <%@ include file="header.html" %>
                                                
                                                
                                                <lr:ThumbnailGrid>
                                                  <lr:GridPhotoCell>
                                                            <a href="$others/<%= image.exportFilename %>_large.html">
                                                <% --[[ Code added by John R. Ellis ]]
                                                local photo = idToPhoto [image.imageID]
                                                local anyfileFile = photo:getPropertyForPlugin ("com.johnrellis.anyfile", "file")
                                                --[[ End code added by John R. Ellis ]] 
                                                %>
                                                                <img src="$others/bin/images/thumb/<%= image.exportFilename %>.jpg" id="<%= image.imageID %>" class="thumb" />
                                                            </a>
                                                    <%= --[[ Code added by John R. Ellis ]]
                                                        anyfileFile %>
                                                    </lr:GridPhotoCell>
                                                </lr:ThumbnailGrid>
                                                
                                                <% if numGridPages > 1 then %>
                                                  <div class="pagination">
                                                    <ul>
                                                      <lr:Pagination>
                                                        <lr:CurrentPage>
                                                          <li>$page</li>
                                                        </lr:CurrentPage>
                                                        <lr:OtherPages>
                                                          <li><a href="$link">$page</a></li>
                                                        </lr:OtherPages>
                                                  <lr:PreviousEnabled>
                                                  <li><a href="$link">Previous</a></li>
                                                  </lr:PreviousEnabled>
                                                  <lr:PreviousDisabled>
                                                  <li>Previous</li>
                                                  </lr:PreviousDisabled>
                                                  <lr:NextEnabled>
                                                  <li><a href="$link">Next</a></li>
                                                  </lr:NextEnabled>
                                                  <lr:NextDisabled>
                                                  <li>Next</li>
                                                  </lr:NextDisabled>
                                                      </lr:Pagination>
                                                    </ul>
                                                  </div>
                                                <% end %>
                                                
                                                <% --[[ Include the page footer]] %>
                                                <%@ include file="footer.html" %>
                                                
                                                • 22. Re: Accessing custom metadata from Web Engine gallery
                                                  craigs22120920 Level 1

                                                  Brilliant. John, thank you for the great example.

                                                   

                                                  Craig