dots/.scripts/cam/importcam

39 lines
894 B
Plaintext
Raw Normal View History

2021-08-15 17:28:10 +02:00
#!/usr/bin/env zsh
2022-07-20 00:50:37 +02:00
# copy photos with exif data on them into a date-structured directory hierarchy
2021-08-15 17:28:10 +02:00
2022-07-20 00:50:37 +02:00
# source and destination locations
srcdir="$CAM_PIC_SRC"
picdir="$(xdg-user-dir PICTURES)/cam"
2021-08-15 17:28:10 +02:00
2022-07-20 00:50:37 +02:00
start=1
total=`ls $srcdir | wc -l`
2022-07-20 00:50:37 +02:00
for f in `ls $srcdir`
do
progress="$start/$total"
start=$((start+1))
2021-08-15 17:28:10 +02:00
2022-07-20 00:50:37 +02:00
src="$srcdir/$f"
# get the exif create date and turn it into a filepath
datestr=`exiftool -CreateDate "$src"`
datedir=`echo "$datestr" | awk '{ gsub(":","/",$4); print $4; }'`
datedir="$picdir/$datedir"
# make sure the destination exists
[ ! -d $datedir ] && mkdir -p $datedir
dest="$datedir/$f"
# if the file exists, don't overwrite
if [ -f $dest ]; then
print "[$progress] skipping $src->$dest: destination file already exists"
else
print "[$progress] sync $src -> $dest"
rsync $src $dest
fi
done
2021-08-15 17:28:10 +02:00
exit 0