improve camera import script

This commit is contained in:
ktyl 2022-07-19 23:50:37 +01:00
parent 6d65beff8f
commit 8336ffdacf
2 changed files with 31 additions and 10 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
export CAM_SRC="/run/media/$USER/disk/" export CAM_SRC="/run/media/$USER/disk/"
export CAM_PIC_SRC="$CAM_SRC/DCIM/100MSDCF"
# TODO: this is actually garbage lol, when importing pictures we should sort them # TODO: this is actually garbage lol, when importing pictures we should sort them
# by their metadata, not by todays date and CERTAINLY not in an env variable which could # by their metadata, not by todays date and CERTAINLY not in an env variable which could

View File

@ -1,18 +1,38 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# TODO: offer to clear camera storage # copy photos with exif data on them into a date-structured directory hierarchy
src=$CAM_SRC # source and destination locations
pic=$CAM_PIC srcdir="$CAM_PIC_SRC"
picdir="$(xdg-user-dir PICTURES)/cam"
if [ "$#" -eq 2 ]; then start=1
srcdir=$1 total=`ls $srcdir | wc -l`
bkpdir=$2
for f in `ls $srcdir`
do
progress="$start/$total"
start=$((start+1))
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 fi
done
[ ! -d $srcdir ] && echo "$srcdir not found" && exit 1
[ ! -d $bkpdir ] && echo "$bkpdir not found" && exit 1
rsync --update --recursive --human-readable --progress $srcdir $bkpdir
exit 0 exit 0