Help streamlining script

Started by WalterS, April 15, 2024, 01:07:01 PM

Previous topic - Next topic

WalterS

In my import script for Olympus raw files, I use the following three commands subsequently:

# Rename all files according to creation date
exiftool -F -overwrite_original -m -creator="$MY_NAME" -copyright="$COPYRIGHT" '-filename<${DateTimeOriginal.%le'\
  -d '%Y%m%d_%H%M%S%%-c' '-FileModifyDate<${DateTimeOriginal}${subsectimeoriginal;$_ = /_(\d+)/ ? "-$1" : ""}}'

# Add counter for serial shots
exiftool -m -P -if '$drivemode =~ /continuous/i' \
  '-FileName<${EXIF:DateTimeOriginal}-${drivemode;$_ = /Shot (\d+)/ ? sprintf("%.2d",$1) : undef}%-c.%le'\
  -d '%Y%m%d_%H%M%S' "$@"

# Add counter for bracket shots
exiftool -m -P -if '$drivemode =~ /bracket/i' \
  '-FileName<${EXIF:DateTimeOriginal}-${drivemode;$_ = /Shot (\d+)/ ? sprintf("%.3d",$1) : undef}%-c.%le'\
  -d '%Y%m%d_%H%M%S' "$@"


This works so far, but running exiftool three times on a file seems a bit much and I get an exit code > 0 from the two if conditionals.

Also sometimes on imports with more than 1k files a counter is added to files even if there is no duplicate file name.

How can I streamline this and cut processing time?

Using exiftool 12.70 on Linux.
Using exiftool 12.70 on Linux

StarGeek

Is it necessary to have one sprintf with %.2d and one with %.3d?

If you can use one or the other, you can probably drop the -if and use "If two assignments affect the same tag, the latter takes precedence" operation (see Note #1 under the -TAG[+-^]=[VALUE] option).  Though it might be tricky with the addition of the -m (-ignoreMinorErrors) option, as that means that DriveMode[/url] will never be undefined.

Quote from: WalterS on April 15, 2024, 01:07:01 PMI get an exit code > 0 from the two if conditionals.

From the docs on Exit Status
QuoteThe exiftool application exits with a status of 0 on success, or 1 if an error occurred, or 2 if all files failed the -if condition (for any of the commands if -execute was used).

You could check specifically for an exit status of 1 rather than >0.  This is something I had to alter in some of my scrips when it took effect.
"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