Page 1 of 2

Help searching for files using EXIF criteria

Posted: 06 Sep 2019 14:39
by DanielMcKinney
Would anyone like to give me hand writing a script that would search within an image file's EXIF data, if this is possible? PM if you can help!

:)

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 15:25
by highend
Be a bit more specific please...

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 15:47
by DanielMcKinney
Sure thing!

I would like to be able to input a location, and then input a number of specific exposure times (for example, 1/20, 1/50, 1/80) and have the script search for all images within that particular location that match either of those exposure times.

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 16:18
by highend
It starts the search from the current folder in the active pane...

Code: Select all

    $times = input("Enter exposure time(s)", "Separate them by comma!", "1/20, 1/50, 1/80", , , 600, 400);

    if (!$times) { status "No exposure times given, aborted!", "8B4513", "stop"; end true; }
    $times = "(" . regexreplace($times, ",[ ]*", "|") . ")";
    $files = quicksearch("/types={:Image} /f", , , "s");
    $result = "";
    foreach($file, $files, <crlf>, "e") {
        $time = property("#image.exposuretime", $file);
        if (!$time) { continue; }
        $time = regexreplace($time, "[ ][s]$");
        if (regexmatches($times, $time)) { $result .= $file . <crlf>; }
    }
    if ($result) { tab("new"); paperfolder("Exposure_Times", $result, , "nl"); end true; }
    status "No image file(s) found, that match any of these times...", "8B4513", "stop";

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 17:37
by DanielMcKinney
Excellent! Thanks. But can it search for image files other than jpg? I am also working with tif, dng, and rw2 files, all of which should have EXIF data.

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 18:06
by highend
This quicksearch("/types={:Image} /f", , , "s");
where {:Image} is a container for the following file types:

Code: Select all

text formatlist(get("genericfiletype", "{:Image}"), "s", <crlf>);

Code: Select all

*.arw
*.bmp
*.clip
*.cpt
*.cr2
*.crw
*.cur
*.dcr
*.dds
*.dib
*.dng
*.emf
*.erf
*.exr
*.fff
*.gif
*.hdr
*.ico
*.jfif
*.jpe
*.jpeg
*.jpg
*.lip
*.mef
*.mrw
*.nef
*.nrw
*.orf
*.pef
*.pic
*.pict
*.png
*.psb
*.psd
*.raf
*.raw
*.rle
*.rw2
*.rwl
*.sr2
*.srf
*.srw
*.tga
*.tif
*.tiff
*.tpic
*.webp
*.wmf
*.x3f
In other words, these image types are searched as well. If the property() script command can access this property
for rw2, dng, etc.? No clue, I don't have any of those files with exif data in them...

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 18:44
by DanielMcKinney
OK! For some reason, I guess the EXIF data in the dng files can't be accessed? Running a search on a folder with both dng and jpg only turns up the jpg files. Would it help you at all if I sent you a dng file?

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 19:07
by highend
Yeah, upload a .dng and a .rw2 file (zipped together if possible) which contain an exposure time somewhere (dropbox, ...) and send me the link...

It's very likely that XY doesn't support these file types but there are two command line utils that can extract exif info from these file types...

Re: Help searching for files using EXIF criteria

Posted: 06 Sep 2019 20:01
by DanielMcKinney
When I work with photos, I start with raw files, either .dng or .rw2, and they get processed & converted to .tif, and eventually to .jpg. Both the .tif and .jpg versions inherit the EXIF info from the original raw format (whether rw2 or dng).

But I guess the EXIF info is read differently along the way? For instance, Windows will show me the EXIF info for a jpg, but won't display it for tif or dng. Likewise, the XY script seems to only find the EXIF data for jpg - not .dng or .rw2 or .tif either.

So I've zipped together dng, tif, and rw2 files for you! On my Google Drive...

http://bit.ly/2kwjQak

Re: Help searching for files using EXIF criteria

Posted: 07 Sep 2019 00:16
by highend
Windows does only display this data if it has a codec with the correct bitness installed.
The same goes for XY, only that it needs a 32-bit codec for them...

To avoid codec hell, we'll use exiv2 for all other formats than .jpg
You get it from here: https://www.exiv2.org/index.html
It needs Visual C++ 2015 (iirc 64-bit) installed (or copied its files into the root of the exiv2 folder...)
It is not unicode compliant so be careful with file names...
The only alternative would be exiftool which would only be fast if it can process all files
in a single core (start up time is HUGE)...

Adapt the path to it in the script!

When the script has finished its task, it will copy a log of all files and their times into the clipboard...

Code: Select all

    // .jpg / .rw2 use Exif.Photo.ExposureTime
    // .dng use Exif.Image.ExposureTime
    // If the time contains a dot, it needs to be converted...
    // $time = 0.00107169 -> 1 / $time;

    $exiv2 = "D:\Tools\@Command Line Tools\exiv2\exiv2.exe";
    $exiv2Options = "-K Exif.Photo.ExposureTime −K Exif.Image.ExposureTime -Pt";

    $times = input("Enter exposure time(s)", "Separate them by comma!", "1/20, 1/50, 1/80", , , 600, 400);

    if (!$times) { status "No exposure times given, aborted!", "8B4513", "stop"; end true; }
    $times = "(" . regexreplace($times, ",[ ]*", "|") . ")";
    $files = quicksearch("/types={:Image} /f", , , "s");
    $log   = ""; $logTime = ""; $logNoTime = ""; $result = "";
    foreach($file, $files, <crlf>, "e") {
        status "Processing: " . gpc($file, "file"), , "progress";
        $ext = gpc($file, "ext");
        // XYplorer can only? get the exif data from .jpg files
        if ($ext LikeI "jpg") {
            $time = property("#image.exposuretime", $file);
            $time = regexreplace($time, "[ ][s]$");
        // exiv2 alternative...
        } else {
            $time = gettoken(runret("""$exiv2"" $exiv2Options ""$file"""), 1, <crlf>);
            sysdebug $time;
            $time = regexreplace($time, "[ ][s]$");
            // Convert format if necessary
            if (strpos($time, ".") != -1) {
                $time = "1/" . regexreplace((1 / eval($time)), "(\.|,)\d*?$");
            }
        }
        if (!$time) { $logNoTime .= $file . <crlf>; continue; }
        $logTime .= $file . " <--> Time: " . $time . <crlf>;
        if (regexmatches($times, $time)) { $result .= $file . <crlf>; }
    }
    if ($result) {
        tab("new");
        paperfolder("Exposure_Times", $result, , "nl");
        $logTimeHeader   = "File(s) with exposure time";
        $logNoTimeHeader = "File(s) WITHOUT exposure time";
        if ($logTime)   { $log .= $logTimeHeader   . <crlf> . strrepeat("=", strlen($logTimeHeader))   . <crlf> . $logTime   . <crlf 2>; }
        if ($logNoTime) { $log .= $logNoTimeHeader . <crlf> . strrepeat("=", strlen($logNoTimeHeader)) . <crlf> . $logNoTime . <crlf 2>; }
        copytext $log;
    } else {
        status "No image file(s) found, that match any of these times...", "8B4513", "stop";
    }

Re: Help searching for files using EXIF criteria

Posted: 07 Sep 2019 21:18
by DanielMcKinney
Thanks! Exiftool looks very cool. Give me a day or two to check this out.

Re: Help searching for files using EXIF criteria

Posted: 08 Sep 2019 09:15
by admin
DanielMcKinney wrote: 06 Sep 2019 17:37 Excellent! Thanks. But can it search for image files other than jpg? I am also working with tif, dng, and rw2 files, all of which should have EXIF data.
XY looks for EXIF data in the following file types:

RAW: .arw.cpt.cr2.crw.dcr.dng.erf.fff.mrw.mef.nef.nrw.orf.pef.raf.raw.rw2.rwl.sr2.srf.srw.x3f.tif.tiff
other: .jfif.jpg.jpeg.jpe.psb.psd

Re: Help searching for files using EXIF criteria

Posted: 08 Sep 2019 09:21
by highend
It doesn't see the exposure time in dng/rw2/tif here, though... (while exiv2 does)

Re: Help searching for files using EXIF criteria

Posted: 08 Sep 2019 09:27
by admin
Can you send me such a file?

Re: Help searching for files using EXIF criteria

Posted: 08 Sep 2019 11:51
by admin
Thanks for the files!

Well, I was mistaken, :whistle: indeed only ".jfif.jpg.jpeg.jpe" are natively supported, and the next beta will improve support for ".tif.tiff". For other formats you need appropriate CODECs installed.