#!/bin/bash # # wmdd - Weapon of Mass Duplicate Detection # # I wrote this because I was having a hard time identifying duplicate # images in my f-spot Photos folder. I decided I should just rename all # of the pictures based on the EXIF data to YYYY-MM-DD-HH-mm-SS.jpg format. # If pictures have identical EXIF data, then '_copy' is added to the file # name. Operation is recursive. # # To make it a little easier, I have the script copy pictures to a folder, # 'exif/YYYY' or 'noexif' depending on whether there is EXIF info or not. # This also make reimporting to f-spot a little easier. # # Requires exif package. # # To run, cd to the top-level directory of the images you want to rename. # # Todd Slater # 14 May 2007 original_pic_dir=`pwd` # maybe at some point make this an optional argument cp_dir="$original_pic_dir/exif" noexif_dir="$original_pic_dir/noexif" # find images find $original_pic_dir -type f -iname '*.jpg' >> piclist while read line do # test for exif if [ -z `exif -t DateTimeOriginal "$line"` >/dev/null 2>&1 ] ; then # no exif, let's copy it to noexif_dir, but not overwrite existing files pic_name=`echo "$line" |sed s/" "/_/g | xargs basename` while [ -f "$noexif_dir/$pic_name" ] ; do pic_name=`echo "$pic_name" | sed s/\.jpg/_copy\.jpg/` done if [ ! -d $noexif_dir ] ; then mkdir -p $noexif_dir fi cp "$line" "$noexif_dir/$pic_name" else # has exif, let's rename and copy to exif/YYYY folder exif -t DateTimeOriginal "$line" |grep Value > exif.$$ year=`cut -b 10-13 "exif.$$"` month=`cut -b 15-16 "exif.$$"` day=`cut -b 18-19 "exif.$$"` hour=`cut -b 21-22 "exif.$$"` minute=`cut -b 24-25 "exif.$$"` second=`cut -b 27-28 "exif.$$"` rm exif.$$ exif_name="$year-$month-$day-$hour-$minute-$second.jpg" while [ -f "$cp_dir/$year/$exif_name" ] ; do exif_name=`echo $exif_name | sed s/\.jpg/_copy\.jpg/` done if [ ! -d "$cp_dir/$year" ] ; then mkdir -p "$cp_dir/$year" fi cp "$line" "$cp_dir/$year/$exif_name" fi done < piclist rm -f piclist