Conditionally move NEF files based on star rating and "Active D" value?

Started by mrverdantgreen, June 12, 2020, 07:05:59 PM

Previous topic - Next topic

mrverdantgreen

Being brand new to exiftool, I have no idea if this is even possible, but I want to move or copy NEF files from one directory to another if and only if those files have been given a certain star rating in Photo Mechanic AND if there is a non-zero value in the proprietary Nikon setting for "Active D Lighting" (in other words if Active D was turned on at all for that image). If this IS possible, I'd love a few pointers on how to make this work, and maybe some mention of whether the solution depends on the specific camera model (I have several models I'd like to do this for).

Thanks!

StarGeek

It should be possible.  First, run the command in FAQ #3 on one of the files you know will satisfy your criteria.  Look through the output for the tags and the values you want to select and post them here.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mrverdantgreen

Here is the output for the Nikon proprietary "Active-D Lighting" field:

[Nikon]         ActiveD-Lighting                : Extra High 2

I want to catch any files for which the value is anything other than 'Off'.

And here is the output for the star rating field:

[XMP-xmp]       Rating                          : 0

The problem is, this is incorrect. If I look at the XML in the .xmp sidecar file for the image I ran exiftool on, it shows:

   xmpRights:Marked="True"
   photoshop:DateCreated="2020-06-09T05:20:48.09"
   xmp:CreateDate="2020-06-09T05:20:48.09"
   xmp:Rating="2"
   photomechanic:ColorClass="0"
   photomechanic:Tagged="False"
   photomechanic:Prefs="0:0:2:000021"


So Photo Mechanic tagged the file with a rating of 2, and this appears correctly in the XMP file, but exiftool is showing 0 for the rating. I can see no other field with the word 'rating' in it. Is there any way to pull the correct value for rating?

StarGeek

For the first part, you could use
exiftool -if "lc $ActiveD-Lighting ne 'off' " -filename /path/to/files/
to get a list of the files where ActiveD-Lighting wasn't equal to off.

But this is more complicated for two reason.  First, you want to use the Rating from the XMP sidecar.  Second, when you want to move/copy the NEF files, you are probably going to want to move the XMP sidecar files as well.

Off hand I can't think of a way to do this directly.  But one options would be to copy the Rating from the sidecar into the NEF, then you could check for both in the NEF and then it would be possible to move both the NEF and the sidecar.  But a lot of people don't like editing their RAW images directly.

Hmmm...  Another option would be to copy the ActiveD-Lighting value to a rarely used XMP tag.  Then you could check both of the values in the sidecar and move based on that. IMO, Creative Commons tags are good to use as temporary storage.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mrverdantgreen

Yes, modifying the RAW files would not be my first choice, but if there's no other option, then ok. Alternatively, can you explain how to copy the ActiveD-Lighting value to a Creative Commons tag in the sidecar file?  And then, remembering that I am a complete newbie with exiftool, how would I incorporate that into something that would check both the ActiveD-Lighting value and the Rating value to conditionally move/copy files to another directory?

Reading between the lines of your last reply, it sounds like the values being checked have to either both be in the NEF or both be in the XMP?  Why is that?

Also, the command: exiftool -if "lc $ActiveD-Lighting ne 'off' " -filename /path/to/files/ doesn't seem to work. It shows all files, regardless of the value of ActiveD-Lighting. Is this because this value is in the MakerNotes, and is thus probably actually some string of hex values?

Phil Harvey

Quote from: mrverdantgreen on June 13, 2020, 11:45:09 AM
Alternatively, can you explain how to copy the ActiveD-Lighting value to a Creative Commons tag in the sidecar file?

exiftool "-SOMETAG<ActiveD-Lighting" -srcfile %d%f.xmp -ext nef DIR

Where SOMETAG is any tag you choose.

Quotehow would I incorporate that into something that would check both the ActiveD-Lighting value and the Rating value to conditionally move/copy files to another directory?

This gets somewhat more complicated if you are using a sidecar file.  I don't have time at the moment to come up with a strategy for this.

QuoteAlso, the command: exiftool -if "lc $ActiveD-Lighting ne 'off' " -filename /path/to/files/ doesn't seem to work. It shows all files, regardless of the value of ActiveD-Lighting. Is this because this value is in the MakerNotes, and is thus probably actually some string of hex values?

No.  This should work if ExifTool shows ActiveD-Lighting anything but "Off" (case insensitive).  But the tag must exist.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on June 13, 2020, 01:18:18 PM
Quote from: mrverdantgreen on June 13, 2020, 11:45:09 AM
Alternatively, can you explain how to copy the ActiveD-Lighting value to a Creative Commons tag in the sidecar file?

exiftool "-SOMETAG<ActiveD-Lighting" -srcfile %d%f.xmp -ext nef DIR

Where SOMETAG is any tag you choose.

As an example, you could use AttributionName, the first tag listed under the Creative Commons tags.  That's what I'm using to test with.

Quote
Quotehow would I incorporate that into something that would check both the ActiveD-Lighting value and the Rating value to conditionally move/copy files to another directory?

This gets somewhat more complicated if you are using a sidecar file.  I don't have time at the moment to come up with a strategy for this.

Yeah, it's turning out to be pretty tricky. Trickier than I thought.  Still working on it, though.

Quote
QuoteAlso, the command: exiftool -if "lc $ActiveD-Lighting ne 'off' " -filename /path/to/files/ doesn't seem to work. It shows all files, regardless of the value of ActiveD-Lighting. Is this because this value is in the MakerNotes, and is thus probably actually some string of hex values?

No.  This should work if ExifTool shows ActiveD-Lighting anything but "Off" (case insensitive).  But the tag must exist.

What OS?  If you're on Linux/Mac, swap Single/Double quotes and make sure you aren't using Fancy quotes.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

That was a tough one. I finally figured it out with Note 4 under the -if option.

It's going to require a temporary file. First, to find the files that match your requirements, you would run this, assuming the use of AttributionName as I mentioned above. Replace /path/to/files/ with the path to files to process.
exiftool -srcfile %d%f.xmp -if "lc $AttributionName ne 'off' and $Rating==5"-p "$OriginalDirectory/$OriginalFileName" /path/to/files/ >temp.txt

Then, to move files you would run
exiftool "-Directory=/path/to/moved/" -@ temp.txt

To copy files, you would run (trailing slash is important)
exiftool -o . "-Directory=/path/to/copiedFiles/" -@ temp.txt
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mrverdantgreen

Quote from: StarGeek on June 13, 2020, 01:52:07 PM
Quote
QuoteAlso, the command: exiftool -if "lc $ActiveD-Lighting ne 'off' " -filename /path/to/files/ doesn't seem to work. It shows all files, regardless of the value of ActiveD-Lighting. Is this because this value is in the MakerNotes, and is thus probably actually some string of hex values?

No.  This should work if ExifTool shows ActiveD-Lighting anything but "Off" (case insensitive).  But the tag must exist.

What OS?  If you're on Linux/Mac, swap Single/Double quotes and make sure you aren't using Fancy quotes.
I'm on MacOS 10.15.5 and swapping the single for double quotes fixed this command. Is this a general rule - use single quotes on the outside, double quotes on the inside?

Quote from: StarGeek on June 13, 2020, 01:52:07 PM
Quote from: Phil Harvey on June 13, 2020, 01:18:18 PM
Quote from: mrverdantgreen on June 13, 2020, 11:45:09 AM
Alternatively, can you explain how to copy the ActiveD-Lighting value to a Creative Commons tag in the sidecar file?

exiftool "-SOMETAG<ActiveD-Lighting" -srcfile %d%f.xmp -ext nef DIR

Where SOMETAG is any tag you choose.

As an example, you could use AttributionName, the first tag listed under the Creative Commons tags.  That's what I'm using to test with.
This did exactly what I had hoped - it copied the values from the ActiveD-Lighting field in the Nikon MakerNotes in the NEF into the AttributionName field in the XMP file. However, it also creates a backup of the original XMP file with the extension .xmp_original. I'm all for backups, but once I'm confident that this is doing what I want, is there a way to disable the creation of these backups? Also, it changed the extension from .XMP to .xmp. I don't think this is significant for my purposes, but changing the case of the extension might trip up someone else?

Quote from: StarGeek on June 13, 2020, 02:45:44 PM
That was a tough one. I finally figured it out with Note 4 under the -if option.

It's going to require a temporary file. First, to find the files that match your requirements, you would run this, assuming the use of AttributionName as I mentioned above. Replace /path/to/files/ with the path to files to process.
exiftool -srcfile %d%f.xmp -if "lc $AttributionName ne 'off' and $Rating==5"-p "$OriginalDirectory/$OriginalFileName" /path/to/files/ >temp.txt
Once I swap the single for double quotes in this command, it seems to build the temp.txt file correctly, listing both the .NEF and the .xmp for files that meet the criteria, but is also throws an error: Error: File not found - ./temp.xmp which I can't figure out. Any ideas?  Also, what is the exact syntax if I want files for example with a rating >= 2, or > 3 AND less than or equal to 5?

Quote from: StarGeek on June 13, 2020, 02:45:44 PM
Then, to move files you would run
exiftool "-Directory=/path/to/moved/" -@ temp.txt

To copy files, you would run (trailing slash is important)
exiftool -o . "-Directory=/path/to/copiedFiles/" -@ temp.txt
This works as expected.

Thank you so much StarGeek and Phil for your diligent tracking down of an answer for this!

For the benefit of future searchers, here is why I want to do this. I shoot Nikon (obviously), and the Active D-Lighting option on many Nikon bodies is like a single exposure HDR feature. It's not helpful in all situations, but especially in high-contrast scenes like bright sunlight and deep shadow it can save a lot of detail that would otherwise be lost. It works by under-exposing the shot to save highlight detail and tagging it with the amount of Active D you specified. Unfortunately, almost no software knows about Active D. If you load a file with Active D into Lightroom or Photoshop, it just looks like an underexposed shot. If you load it into Nikon Capture NX however, the software recognizes the Active D tag and applies a proprietary tone curve (based on the amount of Active D specified) to the file that pulls back a lot of detail from the shadows. It's the word "proprietary" that's the problem and why only Nikon software can properly handle Active D files.

So why not just use Capture NX and be done? Because Capture NX just isn't suited to general high-volume daily image processing. It lacks features like local adjustments, among many others, and is quite slow. So I want to use Capture NX to open and save ONLY those files with Active D, and continue to do everything else in Lightroom.

So now using exiftool, I plan to cull my photos as usual in Photo Mechanic, then run exiftool to move all files with a certain rating AND some amount of Active D to a new directory. Then I batch process those files in Capture NX, just opening them and saving them as TIFFs, which is enough to apply the proprietary Active D tone curve. Then I will move these TIFFs back to the main project directory (with their XMPs, which will probably have to be edited to reflect that they are now representing TIFFs and not NEFs), and process as usual in Lightroom. Given that I may come back from a shoot with hundreds of Active D files, this will save me vast amounts of time and sanity.