{ pkgs, ... }: # exiftool config and script based on that of @numinit let # An exiftool config that adds the OriginTimestamp property containing the best guess for file creation time exiftool-config = pkgs.writeText "exiftool.config" '' %Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { OriginTimestamp => { Desire => { 0 => 'CreateDate', 1 => 'DateTimeOriginal', 2 => 'FileModifyDate' }, ValueConv => '$val[0] || $val[1] || $val[2] || undef', PrintConv => '$self->ConvertDateTime($val)', PrintConvInv => '$self->InverseDateTime($val)' } } ) ''; # A tool to use `find` and `exiftool` to sort images into YMD folders sibd = pkgs.writeShellScriptBin "sort-images-by-date" '' set -euo pipefail if [ $# -lt 3 ]; then echo "Usage: $0 [prefix] [src] [dest] [exiftool args...]" >&2 exit 1 fi prefix="$1" src="$2" dest="$3" # Remove $1, $2, $3 from $@ so the remainder can be passed to exiftool shift; shift; shift # This find expression matches .jpg/.png modified 14+ days ago. # The -not (-name -prune) expressions exclude directories from the results by name. # The exiftool command will move matched files to $dest/$prefix/year/month/day/filename.ext. # -config loads the config defined above, which adds the OriginTimestamp composite property # -filename tells exiftool to move each file to a new filename, $OriginTimestamp # -d defines how the timestamp will be converted to a string, which ends up handling the pathing ${pkgs.findutils}/bin/find $src \ -not \( -name FalseKnees -prune \) \ -not \( -name Background -prune \) \ -type f \ -mtime +14 \ \( -name "*.jpg" -or -name "*.png" \) \ -exec ${pkgs.exiftool}/bin/exiftool \ -config ${exiftool-config} \ -api largefilesupport=1 \ -progress \ -filename'