6 Replies Latest reply on Jan 29, 2016 5:08 PM by flingo

    Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection

    flingo Level 1

      I'm about to implement support for 'Get Ratings from Pulished Collection' and 'Comments on Published Photos' in my publish service provider (for Synology's PhotoStation). While the implementation of that functionality is quite straight forward, I'm in trouble with the configuration of that option. Since the process of getting ratings from a remote server might be quite time-killing in particular for large collection (> 1.000 photos) in my scenario, I would like to make this feature configurable per Published Collection. This is what the Flickr Publish Service Provider sample code also suggests.

       

      Unfortunately, the following hooks won't give me a reference to the respective publishedCollection or publischedCollection settings but only to the Publish Service settings:

      1. publishServiceProvider.addCommentToPublishedPhoto( publishSettings, remotePhotoId, commentText )
      2. publishServiceProvider.canAddCommentsToService( publishSettings )
      3. publishServiceProvider.getCommentsFromPublishedCollection( publishSettings, arrayOfPhotoInfo, commentCallback )
      4. publishServiceProvider.getRatingsFromPublishedCollection( publishSettings, arrayOfPhotoInfo, ratingCallback )

      In case 1, 3 and 4 I could try to get the appropriate collection settings via tracing back to the containing collection of the published photo(s), but this may lead to a wrong collection, since the photo may be contained in more than one published collection, each having different settings.

       

      So, I basicly thinking about two ways to do it:

      1. put the option into the Publish Service settings
      2. redefine the layout of the publishedPhoto's remoteId to include the localId of its belonging Published Collections via exportSession:recordRemoteCollectionId( remoteId )

       

      Option 1 isn't quite sexy or intuitive, since it requires two different Publish Services being completely identical except the comment and rating support option. Hmm

      Option 2 would make the plugin backward incompatible: if you decide to upgrade to this new version of the plugin, there is no easy way back, since the older version wouldn't understand the new format of the published photo's remoteId.

       

      Am I missing the point or some undocumented features? How would the suggested Flickr example work?

        • 1. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
          johnrellis Most Valuable Participant

          One suggestion: Have the per-published-collection setting "Get Ratings and Comments".  But whether that is checked or not, the user can always add comments from LR to published photos.  Thus, it's only important to examine that setting for getCommentsFromPublishedCollection() and getRatingsFromPublishedCollection().

           

          I believe that an LrPublishedPhoto is contained in exactly one LrPublishedCollection.  Thus, you can reliably "trace back" from an LrPublishedPhoto to the LrPublishedCollection containing it.  Here's code that does that efficiently, building a table that maps the LrPublishedPhotos in "arrayOfInfo" to their corresponding LrPublishedCollections:

           

          local pubPhotoToPubCol, didPubCol = {}, {}
          for _, photoInfo in ipairs (arrayOfPhotoInfo) do
              local photo = photoInfo.publishedPhoto:getPhoto ()
              for _, pubCol in ipairs (photo:getContainedPublishedCollections ()) do
                  if not didPubCol [pubCol] then
                      for _, pubPhoto in ipairs (pubCol:getPublishedPhotos ()) do
                          pubPhotoToPubCol [pubPhoto] = pubCol
                          end
                      didPubCol [pubCol] = true
                      end
                  end
              end 
          

           

          Building the map "pubPhotoToPubCol" in this way ensures that you don't have an O(n^2) algorithm for tracing back to the published collections.

          • 2. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
            flingo Level 1

            Hi John,

            thanks for your impressive feedback! It shows that this issue is obiously not as simple as it should be!

             

            I'm still thinking about your approach, in fact I missed my train station to jump off this morning while thinking about the solution. ;-)

             

            I agree with you that your solution will find one collection per photo but I'm not convinced it will find the right one.

             

            Here is my scenario is: I have one Published Collection "All Photos" which includes all my photos (>20.000) and I definitely don't want this collection to sync ratings and comments! I have some other Published Collections within the same Publish Service, each having less than 100 photos from those >20.000 photos being published to a different album, which I want to sync ratings and comments (since these collections are shared with some friends).

             

            When I publish "All Photos" Lr will call the getCommentsFromPublishedCollection() hook with an array of > 20.000 photos. Going through all this photos - even as local lookup - will take a reasonable time which I would like to avoid.

             

            I think I will do some more testing on that. Stay tuned!

            • 3. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
              johnrellis Most Valuable Participant
              I agree with you that your solution will find one collection per photo but I'm not convinced it will find the right one.

              The key idea to my solution is that an LrPublishedPhoto is contained in exactly one LrPublishedCollection.  Abstractly, an LrPublishedPhoto represents the pair <LrPhoto, LrPublishedCollection>.  If you publish the same photo into two published collections, then there will be two different LrPublishedPhoto objects, one for each of the collections.   pubPhoto:getPhoto() will return the single underlying LrPhoto.

               

              I just verified this by publishing two Flickr collections, each containing the same photo.  I selected the two collections in the Publish Services panel in Library.  Using my Debugging Toolkit, I evaluated the following expression:

               

              catalog:getActiveSources()[1]:getPublishedPhotos()[1] == catalog:getActiveSources()[2]:getPublishedPhotos()[1]

               

              This expression compares the single LrPublishedPhoto in the first published collection with the single LrPublishedPhoto in the second.  It evaluates to false, as expected. I then evaluated this expression to compare the underlying LrPhoto objects:

               

              catalog:getActiveSources()[1]:getPublishedPhotos()[1]:getPhoto() == catalog:getActiveSources()[2]:getPublishedPhotos()[1]:getPhoto()


              It evaluates to true, as expected.

              • 4. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
                flingo Level 1

                Thanks, that's good information!

                 

                Anyway, I tried your code snippet for the following scenario on paper:

                • 4 photos: A - D
                • 2 collections: CA (no comments), CB (comments)
                • all 4 photos are in CA, thus we have 4 PublishPhotos PA-CA, ... PD-CA
                • photo B and C also in CB: PB-CB, PC-CB
                • when Publishing CA: no comments should be sync-ed

                Here is what I get:

                PublishPhotos.jpg

                So, the snippet is good to get all involved collections in didPubColl, but it won't give me clear indication where or not to sync the comments of the published photos in arrayOfPhotoInfo.

                 

                But with your info on Photos and Published Photos in mind, If think I found another viable solution which allows to put the "Support Comments and Ratings" option into the Published Collection settings and which will also be backward compatible to my current implementation:

                • Doing some "Pubish"s today on single collections and on collection sets, I realized that Lr will always call the getCommentsFromPublishedCollection() for each individual collection, not for the whole collection set.
                • that means, it's sufficient to identify the correct Published Collection for the first photo, all other photos will be in the same Published Collection
                • how do I get a link back from a published photo to the belonging published collection: I store it in remoteUrl during upload of the photo via exportRendition:recordPublishedPhotoUrl(). This field is not needed in my implementation, it would be completely redundant information with the knowledge of the remoteId.
                • getCommentsFromPublishedCollection() and getRatingsFromPublishedCollection() both deliver the remoteUrl

                Do you see any obstacles in that solution?

                • 5. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
                  johnrellis Most Valuable Participant

                  I don't know all of the details of your plugin, but it sounds plausible.

                  • 6. Re: Lr SDK publishServiceProvider.getRatingsFromPublishedCollection() - no reference to publishedCollection
                    flingo Level 1

                    It works!!!

                     

                    processRenderedPhotos()

                         ...

                         rendition:recordPublishedPhotoUrl(tostring(publishedCollection.localIdentifier))

                         ...

                     

                    getCommentsFromPublishedCollection()

                         ...

                        publishedCollection = LrApplication.activeCatalog():getPublishedCollectionByLocalIdentifier(tonumber(arrayOfPho toInfo[1].url))
                    if not publishedCollection:getCollectionInfoSummary().collectionSettings.enableComments then
                       return

                      end

                     

                    Thanks for the fruitful discussions!

                     

                    Martin