Skip to content

Instantly share code, notes, and snippets.

@melalj
Last active August 29, 2015 14:16
Show Gist options
  • Save melalj/4df9799457978aef4af2 to your computer and use it in GitHub Desktop.
Save melalj/4df9799457978aef4af2 to your computer and use it in GitHub Desktop.
Export photos using EXIF metadata
#! /bin/bash
# USE AT YOUR OWN RISK!
# This script will go through your iPhoto Library
# original files and copy them to $EXPORTDIR.
# The script will organize the files in directories
# named YYYY/YYYY-MM and will rename the files using
# EXIF data ("YYYY-MM-DD HH.MM.SS.EXT", like dropbox
# camera import does).
# Written by Panayotis Vryonis, 2013.
# http://blog.vrypan.net/2013/5/20/leaving-iphoto-for-dropbox/
# Distributed under MIT License.
# <http://opensource.org/licenses/MIT>
# USE AT YOUR OWN RISK!
# Make sure you have exiftool installed first
# http://www.sno.phy.queensu.ca/~phil/exiftool/
# UNCOMMENT AND EDIT THE FOLLOWING TWO LINES!!!!!!
SOURCEDIR="/Volumes/My Passport/docs/photos"
EXPORTDIR="/Volumes/CORSAIR/Archive"
if [ ! "$SOURCEDIR" ] || [ ! "$EXPORTDIR" ];
then
echo Please edit script and set \$SOURCEDIR and \$EXPORTDIR.
exit
fi
find "$SOURCEDIR" -type f | grep -v .DS_Store > filelist.txt
total_files=`cat filelist.txt | wc -l | tr -d ' '`
fn=0
max_size="64"
echo
echo Copying $total_files media files media files
echo from \"$SOURCEDIR\"
echo to \"$EXPORTDIR\".
echo
cat filelist.txt | while read fullfile ; do
let fn+=1
let percent=100*$fn/$total_files
file_size_kb=`du -k "$fullfile" | cut -f1`
if [ "${file_size_kb}" -lt "$max_size" ]
then
continue
fi
# Thanks:
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
filename="${fullfile##*/}"
extension="${filename##*.}"
filename="${filename%.*}"
if [ ${filename:0:1} = "." ]; then
continue
fi
#filename=`echo $filename | cut -d '_' -f 2`
#echo -ne "\033[K"
printf "Progress: %3d%% " $percent
echo -ne "[$fn/$total_files]\n"
echo -e " > $fullfile\033[K"
dates=(`exiftool \
-CreateDate \
-MediaCreateDate \
-DateTimeOriginal \
-ModifyDate \
-FileModifyDate \
-d '%Y-%m-%d %H.%M.%S' \
-S -s "$fullfile"`)
thedate="${dates[0]} ${dates[1]}"
filename2=$thedate
path2="$EXPORTDIR/${thedate:0:4}/${thedate:0:7}"
if [ ! -d "$path2" ];
then
mkdir -p "$path2"
fi
if [ ! -f "$path2/$filename2.$extension" ] ;
then
newfile="$path2/$filename2.$extension"
else
i=1
until [ ! -f "$path2/$filename2-$i.$extension" ]; do
let i+=1
done
newfile="$path2/$filename2-$i.$extension"
fi
echo -e " < $newfile\033[K"
echo -ne "\r\033[3A"
cp "$fullfile" "$newfile"
newfile=""
done
echo -e "\nDone.\033[K"
echo -e "Check $EXPORTDIR.\033[K"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment