Sunday, August 2, 2009

Canon HF200 Linux transfer script

#!/bin/bash
#Startup settings
date=`date "+%Y-%m-%dT%H:%M:%S"`
ddir=`date "+%Y-%m-%d"`
destdir="/home/sgoggin/TransferAREA"
logfile='/tmp/TransferPhotosCardReader'

echo "Started TransferPhotosCardReader on $date" | tee $logfile
echo " Dest Dir is $destdir" | tee $logfile

mkdir -p $destdir

# Step 1a - Move the existing Transfer Area into a dated copy
# mv $destdir $destdir_$ddir

# Step 1 - Transfer files from card to Transfer AREA
cd $destdir;

# Set path for Video Camera
if [ -d /media/disk/PRIVATE/AVCHD/BDMV ]; then sourcedir="/media/disk/PRIVATE/AVCHD/BDMV";

echo " Copying HD Video from source Dir $sourcedir " | tee $logfile
echo " Transferring file ..."
find $sourcedir -type f -exec rsync -av {} $destdir \; | tee $logfile
# Step 1 - Rename imapges that are still in canon format
cd $destdir;
for f in $( ls | grep -i MTS);
do
echo "Processing $f" | tee $logfile
echo " Checking to see if "${f/.MTS}.CPI" exists" | tee $logfile
FileName=`ls -l --time-style=+%Y%m%d-%H%M%S $f |cut -d' ' -f6`
echo " Timestamp is $FileName"
mv -v $f $FileName.MTS

if [ -e "${f/.MTS}.CPI" ]; then
echo " moving CPI file $f.CPI"
mv -v ${f/.MTS}.CPI $FileName.CPI
fi;
done;

fi;

# Retrieve photos from the plugged in camera
# gphoto2 -P
if [ -d /media/CANON_DC ]; then sourcedir="/media/CANON_DC/DCIM/"; fi;
# Set path for Video Camera
if [ -d /media/disk ]; then sourcedir="/media/disk/DCIM/"; fi;


if [ -d /media/EOS_DIGITAL ]; then sourcedir="/media/EOS_DIGITAL"; fi;
echo " Source Dir is $sourcedir " | tee $logfile

echo " Transferring file ..."
find $sourcedir -type f -exec rsync -av {} $destdir \; | tee $logfile

# Step 1 - Rename imapges that are still in canon format
cd $destdir;
for f in $( ls | grep -i jpg);
do
echo "Processing $f" | tee $logfile
echo " Checking to see if "img${f/.jpg}.cr2" exists" | tee $logfile
if [ -e "img${f/_r.jpg}.cr2" ]; then
echo " [Originated from a CR2 therefore skipping]" | tee $logfile
else
echo " No it does not exist, renaming" | tee $logfile
# Rename the jpegs
jhead -ft -nf%Y%m%d-%H%M%S $f | tee $logfile
fi;
done;

# Ensure all files are in lower case
rename 'y/A-Z/a-z/' *

# Step 2 - Rename the CR2's
exiv2 -Ft rename img*2 | tee $logfile
exiv2 -Ft rename crw*crw | tee $logfile

# Rename the AVI files
/usr/local/bin/RenameAVI *avi | tee $logfile

# Step3 - Now sort the files into a tree based in the file name.
for ftm in 200*; do
echo ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}/$ftm
echo "Processing $ftm into ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}/$ftm" | tee $logfile
if [ ! -d ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}/$ftm ]; then
echo "Creating ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}/$ftm" | tee $logfile
mkdir -v -p ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}
fi
mv -i -b $ftm ${ftm:0:4}/${ftm:4:2}/${ftm:6:2}/$ftm
done



tree -D

No comments: