#!/bin/bash # # Supprime les fichiers CR2 qui n'ont aucun fichier JPG correspondant dans le répertoire # # Script à éxécuter après avoir fait le tri dans un répertoire avec un "viewer classique" # dans les fichiers JPG générés par l'APN (moins lourds que les RAW donc plus rapide à visualiser / supprimer) # # Ce script crée ensuite un dossier "cr2" et y déplace les RAW # Il supprime ensuite les fichiers JPG de la APN (ces derniers seront remplacés par les JPG générés depuis les RAW) # # Utilise : dcraw, cjpeg/ppmtojpeg # # Sources : # http://marc.merlins.org/linux/technotes/cr2_dcraw_jhead.html # # Returns : # 0 si OK # 1 si erreur # 2 si user cancel # RAWFILESEXT=CR2 JPGFILESEXT=JPG # Source and destination directories PWD="$1" DEST="$2" ZENSEP='|' # options dcraw : si besoin DCRAWOPT="" function testprog { if which $1 >/dev/null; then echo "Program $1 exists => OK" else echo "ERROR : $1 should be installed (try debian/ubuntu $2 package) or replace binary path in script." exit 1 fi } # Testing programs testprog zenity zenity testprog dcraw ? testprog ppmtojpeg netpbm # debian package : netpbm testprog cjpeg ? # ======================================================= # Options : # # Files directory : # .../photos/raw : raw files # .../photos/jpg_import : imported jpg files # .../photos/converted : generated jpg files # ======================================================= # - Import JPG => ./jpg_import # - Import RAWs (CR2) => ./raw # - Create JPG from RAWs ? => ./converted # ======================================================= # Post-treatment options : # ======================================================= # - Order files by date # - Set file date before file name (RAW + JPG) # OR # - Delete RAWs with no JPG file # ======================================================= # User options selection OPTLIST=`zenity --list --multiple --checklist --hide-header --hide-column=2 \ --title="Choose what you want to do" --text="Please select script options...\nNB : process will be recursive for all subdirectories" \ --column="" --column="opt" --column="Option" \ FALSE "1" "Import JPG" \ TRUE "2" "Import RAWs (${RAWFILESEXT})" \ TRUE "3" "Create JPG from RAWs" \ TRUE "4" "Order imported / created files by date" \ TRUE "5" "Set file date before file name (RAW + JPG)"` echo "Liste des options à traiter : $OPTLIST" if [[ "$OPTLIST" == "" ]] ; then zenity --error --title="User cancel" --text="User canceled !" exit 2 fi # ======== SELECT SOURCE DIR ========================= if [[ -d "$PWD" ]] ; then zenity --question --title="Source directory" --text="Do you to process \n$PWD\n directory ?" if [[ $? -eq 1 ]] ; then PWD=`zenity --file-selection --directory --confirm-overwrite --title="Select source directory"` fi fi if [[ $? -eq 1 ]] ; then zenity --error --title="User cancel" --text="User canceled !" exit 2 fi if [[ ! -d "$PWD" ]] ; then zenity --error --title="Source directory not found" --text="$PWD doesn't exist !" exit 1 else zenity --question --title="Source directory" --text="Files in \n$PWD\n will be processed" fi if [[ $? -eq 1 ]] ; then zenity --error --title="User cancel" --text="User canceled !" exit 2 fi # ======== SELECT OUTPUT DIR ========================= zenity --question --title="Files destination directory" --text="Do you wish origin files to be copyied in \n$DEST ?" if [[ $? -eq 1 ]] ; then DEST=`zenity --file-selection --directory --confirm-overwrite --title="Select destination directory"` else if [[ -d "$DEST" ]] ; then zenity --info --title="Directory error" --text="$DEST exists : aborting !" exit 1 fi mkdir -p "$DEST" fi; if [[ ! -d "$DEST" ]] ; then zenity --info --title="Directory not found" --text="$DEST doesn't exist !" exit 1 else # set RAWS / JPEG directory RAWDEST="$DEST/$RAWFILESEXT" JPGDEST="$DEST/$JPGFILESEXT" CONVERTEDDEST="$DEST/auto-converted" zenity --question --title="Files destination directory" \ --text="Output directory organisation (depending on selected options) :\n- $RAWDEST : RAWs\n- $JPGDEST : JPGs\n- $CONVERTEDDEST : Converted files" if [[ $? -eq 1 ]] ; then zenity --error --title="User cancel" --text="User canceled !" exit 2 fi fi # DO THE STUFF OLDIFS=$IFS IFS=$ZENSEP for opt in $OPTLIST; do echo "====> Option $i en cours..." case $opt in # ======== IMPORT JPG FILES ========================= 1) echo "=====> Import JPG" mkdir -p "$JPGDEST" ;; # ======== IMPORT RAW FILES ========================= 2) # Select RAW files echo "=====> Import RAWs (${RAWFILESEXT})" mkdir -p "$RAWDEST" find $PWD -name *.$RAWFILESEXT -exec cp '{}' "${RAWDEST}/" \; ;; # ======== CREATE JPG FROM RAW FILES ========================= 3) echo "=====> Create JPG from RAWs" mkdir -p "$CONVERTEDDEST" RAWFILES=`find $RAWDEST -name *.$RAWFILESEXT` NBRAWFILES=`echo $RAWFILES | wc -w` IFS=$OLDIFS RAWLIST=`zenity --list --multiple --title="$NBFILES CR2 Files found" --text="Please select which files should be treated" --column="CR2" $RAWFILES` OLDIFS=$IFS IFS=$ZENSEP echo "Liste des fichiers à traiter : $RAWLIST" for i in $RAWLIST; do echo " process $i..." # dcraw -c ${DCRAWOPT} "$i" | cjpeg -quality 100 -optimize -progressive > $CONVERTEDFILESDIR/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT}); dcraw -c ${DCRAWOPT} "$i" | ppmtojpeg --progressive --optimize --quality=100 > "$CONVERTEDDEST/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT})" # réinitialisation de la date des photos avec la date EXIF du RAW dcraw -z $i touch -r $i $CONVERTEDDEST/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT}) done ;; # ======== ORDER IMPORTED / CREATED FILES ========================= 4) echo "=====> Order imported / created files by date" ;; # ======== RENAME FILES WITH DATE ========================= 5) echo "=====> Set file date before file name (RAW + JPG)" ;; esac done IFS=$OLDIFS exit 0 # Select RAW files RAWLIST=`zenity --list --multiple --title="$NBRAWFILES CR2 Files found" --text="Please select which files should be treated" --column="$RAWFILESEXT" $RAWFILES` echo "Liste des fichiers à traiter : $RAWLIST" zenity --question --title="JPG preview directory" --text="Do you wish JPG previews to be generated in $RAWDEST ?" if [[ $? -eq 1 ]] ; then RAWDEST=`zenity --file-selection --directory --confirm-overwrite` else if [[ -d "$RAWDEST" ]] ; then zenity --info --title="Directory error" --text="$RAWDEST exists : aborting !" exit 1 fi mkdir -p "$RAWDEST" fi; if [[ ! -d "$RAWDEST" ]] ; then zenity --info --title="Directory not found" --text="$RAWDEST doesn't exist !" exit 1 else zenity --info --title="JPG preview directory" --text="Files will be processed in $RAWDEST" fi OLDIFS=$IFS IFS=$ZENSEP for i in $RAWLIST; do echo " traitement $i en cours..." # dcraw -c ${DCRAWOPT} "$i" | cjpeg -quality 100 -optimize -progressive > $CONVERTEDFILESDIR/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT}); dcraw -c ${DCRAWOPT} "$i" | ppmtojpeg --progressive --optimize --quality=60 > "$RAWDEST/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT})" # réinitialisation de la date des photos avec la date EXIF du RAW #dcraw -z $i #touch -r $i $CONVERTEDFILESDIR/$(echo $(basename "$i" ".${RAWFILESEXT}").${JPGFILESEXT}) done IFS=$OLDIFS exit 0 while [[ $# -gt 0 ]] ; do shift done # Longueur du nom des fichiers à traiter (sans extension) RAWFILESDIR=CR2 CANONFILESDIR=jpg_canon CONVERTEDFILESDIR=converted # on se place dans le répertoire spécifié dans la ligne de commande cd $1 # on met tous les fichiers raw dans le répertoire courant echo "=> Déplacement des fichiers RAW du répertoire ${RAWFILESDIR} dans $1" mv ${RAWFILESDIR}/*.${RAWFILESEXT} . # 20100530 : on ne fait plus la conversion en direct (passage par rawtherapee + performant) # convertion des RAW en JPG progressif qualité 100% avec DCRAW et CJPEG et déplacement dans le répertoire CONVERTEDFILESDIR echo "=> Conversion des fichiers RAW dans le répertoire $CONVERTEDFILESDIR" mkdir $CONVERTEDFILESDIR for i in `ls -1 *.${RAWFILESEXT}`; do done # déplacement des fichiers RAW dans le répertoire RAWFILESDIR echo "=> Déplacement des fichiers JPG canon dans le répertoire $RAWFILESDIR" mkdir $RAWFILESDIR mv *.${RAWFILESEXT} $RAWFILESDIR echo "*** TRAITEMENT TERMINE : fin du script."