13 Replies Latest reply on Jan 18, 2011 6:25 AM by johnrellis

    Find Photos by capture time?

    ckhorne

      I'm having a bit of trouble finding photos by capture time. It seems that catalog:findPhotos() works on captureDate, but not time.

       

      I have a photo that I know the date is 2010-11-28 02:10:00 - I can do a getAllPhotos() and dump the capture time to verify.

       

      This works:

       

      local catalog = import 'LrApplication'.activeCatalog()
          local foundPhotos = catalog:findPhotos {
               searchDesc = {
                   {
                       criteria = "captureTime",
                       operation = "in",
                       value = "2010-11-27",
                       value2 = "2010-11-29",
                   },
              }
          }

       

      This doesn't:

       

               searchDesc = {
                    {
                        criteria = "captureTime",
                        operation = "=",
                        value = "2010-11-28",
                    },

       

      nor does:

                       value = "2010-11-28T02:10:00",

       

      or does any other variant I've tried, and I've tried all the sqllite query formats for date time. In fact, I can't find any solution that a "=" criteria works for captureTime.

       

      This is pretty big for my plugin... can anyone help? Please?

        • 1. Re: Find Photos by capture time?
          areohbee Level 5

          Use dateTimeOriginal from raw-metadata (instead of formatted metadata) and do the comparison numerically (instead of via string op).

          • 2. Re: Find Photos by capture time?
            ckhorne Level 1

            Hmm- I've tried that, but I'll try again, just to be sure.

            • 3. Re: Find Photos by capture time?
              areohbee Level 5

              I dont know where you're getting the dates from that you are using to compare, but as long as you convert them to the same numerical format (seconds since midnight GMT January 1, 2001 - the standard numerical time format in Lightroom), you can compare them nicely. Note: you can break them into components too in case you want to add options like (same year, all the ones on Sunday, ... )

              • 4. Re: Find Photos by capture time?
                ckhorne Level 1

                Still no luck.

                 

                Here's what I'm trying (with a different image, so the dates are now different than my original post):

                 

                    local foundPhotos = catalog:findPhotos {
                         searchDesc = {
                             {
                                 criteria = "camera", -- searches Camera Model
                                 operation = "==",
                                 value = "Canon EOS 7D",
                             },
                             {
                                 criteria = "captureTime",
                                 operation = "==",
                                 value = 294962994,
                             },
                             combine = "intersect",
                        }
                    }

                 

                for x = 1, #foundPhotos do
                        local photo = foundPhotos[x];

                        log("\traw dateTimeOriginal: " .. (photo:getRawMetadata("dateTimeOriginal") or null));

                end

                 

                if I run this, I get 9 entries. here's the last 3:

                 

                [1676] ErisApp TRACE  raw dateTimeOriginal: 299806234

                [1676] ErisApp TRACE  raw dateTimeOriginal: 294962994

                [1676] ErisApp TRACE  raw dateTimeOriginal: 294962966

                 

                Camera model does match, so I know at least part of the search critiera is working correctly.

                 

                Surely I'm doing something wrong?

                 

                Thanks for your help!

                • 5. Re: Find Photos by capture time?
                  areohbee Level 5

                  Dont use find-photos.

                   

                  Find them in a loop, comparing each photo to your own criteria as you see fit.

                   

                  Find-photos only works on formatted metadata.

                  • 6. Re: Find Photos by capture time?
                    ckhorne Level 1

                    Seems like that's a lot less efficient, but I guess I can narrow it down a little bit.

                     

                    Thanks-

                    -chris

                    • 7. Re: Find Photos by capture time?
                      areohbee Level 5

                      ckhorne wrote:

                       

                      Seems like that's a lot less efficient, but I guess I can narrow it down a little bit.

                       

                      I dont know - please provide results if you measure it, eh?

                       

                      Rob

                      • 8. Re: Find Photos by capture time?
                        ckhorne Level 1

                        Will do.

                        • 9. Re: Find Photos by capture time?
                          areohbee Level 5

                          You got me curious:

                           

                          11,000 photos:

                           

                          base loop: .07 seconds

                          with time read: 120 seconds

                           

                          You're right: a lot less efficient, on WIndows anyway. Its not using much CPU nor even chunking on the hard drive - maybe one of those threading issues. John Ellis did some disturbing benchmarks showing how inefficient Lr-task-switching is on Windows vs. Mac. Yep - takes exactly the same amount of time (120 seconds) with nothing but a yield in the loop - very disturbing indeed.

                           

                          Rob

                          • 10. Re: Find Photos by capture time?
                            ckhorne Level 1

                            You beat me to it.

                             

                            I can only presume that they're transforming the criteria from findPhotos into the where clause of a sql statement - that's what I would do if I were writing the API.

                             

                             

                            So.. know that I know this, I think I'll use a combination of searching on the camera make and capture time within a day's range, and then looping through and looking for specific information from there. It's not ideal, but a workaround for what I need.

                             

                            I suppose I should submit a bug report for this...

                            • 11. Re: Find Photos by capture time?
                              areohbee Level 5

                              ckhorne wrote:

                               

                              I can only presume that they're transforming the criteria from findPhotos into the where clause of a sql statement


                              I'd bet on it.

                               

                               

                              ckhorne wrote:

                               

                               

                              So.. know that I know this, I think I'll use a combination of searching on the camera make and capture time within a day's range, and then looping through and looking for specific information from there. It's not ideal, but a workaround for what I need.

                               

                              I suppose I should submit a bug report for this...

                               

                              Sounds like a plan...

                              • 12. Re: Find Photos by capture time?
                                johnrellis Most Valuable Participant

                                This doesn't:

                                 

                                         searchDesc = {
                                              {
                                                  criteria = "captureTime",
                                                  operation = "=",
                                                  value = "2010-11-28",
                                              },

                                 

                                In fact, I can't find any solution that a "=" criteria works for captureTime.

                                 

                                One issue here is that the operation is "==", not "=".  If you change it to "==", you should get all photos whose capture date is the one specified.

                                 

                                I've found that the documentation for findPhotos() is incomplete.  A good way to understand the syntax of "searchDesc" is to create a Smart Collection in the user interface, select and right-click it, and do Export Smart Collection Settings.  This will create a ".lrsmcol" file containing the "searchDesc" that you can edit in a text editor.

                                 

                                Another issue is that findPhotos() does indeed seem to operate only on dates, not date/times.  If you really need to specicify a time, I think Rob's solution is the only one.

                                • 13. Re: Find Photos by capture time?
                                  ckhorne Level 1

                                  My apologies - in the post with the "=", I had simply copy and pasted within the post and mis-typed - there wasn't any benefit to re-coding and copy/pasting it over. My code was actually "==" in both my original test and in the second test I showed above (with 9 results).

                                   

                                  Great tip on the Smart Collections export- I didn't know that!

                                   

                                  I think what threw me is that the docs specify "captureTime" as a date. I erroneously assumed that "captureTime" would include the date, or else it would have been "captureDate".

                                   


                                  My final solution was to use findPhotos(), searching for anything matching that date, and then looping through those with the specific getRawMetadata("dateTimeOriginal") number until I found a match.

                                   

                                  Thanks for your help!