Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Use dateTimeOriginal from raw-metadata (instead of formatted metadata) and do the comparison numerically (instead of via string op).
Copy link to clipboard
Copied
Hmm- I've tried that, but I'll try again, just to be sure.
Copy link to clipboard
Copied
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, ... )
Copy link to clipboard
Copied
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
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Seems like that's a lot less efficient, but I guess I can narrow it down a little bit.
Thanks-
-chris
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Will do.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now