charge_photos / load_photos

retour
commentaires (pour les brouteurs minables)
©left 2000-2003, Thomas Harding

download / téléchargement

load_photos est un script bash interactif, front-end à zophImport, le chargeur de photos de zoph, album photos web. Il permet à tout à chacun de charger des photos dans l'album familial, tout en donnant la possibilité d'utiliser toutes les options de zophImport.
load_photos utilise qiv pour contrôler les photos, exiftran pour passer les images en portrait, jhead pour extraire et conserver les tags exifs, gimp pour retoucher les photos, at pour passer en arrière plan le (si) long travail d'importation.
load_photos est internationnalisé (pour l'instant, en anglais et français.
syntaxe : load_photos --help
load_photos is a bash interactive front-end to zophImport, the photo loader of zoph, web based photos album. It permit to everyone to load photos in the family album, as so as to use all zophImport options.
load_photos use qiv to display images, exiftran to fix them as portrait, jhead to extract and keep exif informations, gimp to tidy photos, at to make in backround the (so) long importation work.
load_photos is I10n (Internationalized) in, at time, (I think bad) English and French.
syntax: load_photos --help

Installation

su apt-get install qiv exiftran jhead gimp || urpmi qiv exiftran jhead gimp make install make addgrpphoto exit

Code

#!/bin/bash #V 1.6 # front-end to zophImport # Copyright (C) 2005, Thomas HARDING. thomas.harding@laposte.net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # # <http://tom.harding.free.fr/chargephotos.php> ############ # # CONFIG # PHOTOS_ROOT=/var/lib/zoph ZOPH_PASSWD='zoph_rw' ZOPH_DB='zoph' PHOTO_EDITOR="gimp" LANGUAGE_PATH=/usr/share/zoph/lang if [ -d /mnt/removable ] ; then MOUNT_POINT="/mnt/removable" else MOUNT_POINT='/usbdisk' fi # # messages # OTHER='Other' ALBUM_MSG="Select album" ALBUM_TYPE_MSG="Type the name of the album" CATEGORY_MSG="Select category" CATEGORY_TYPE_MSG="Type the name of the category" DIRECTORY_MSG="Select directory" DIRECTORY_TYPE_MSG="Type the name of directory" DIRECTORY_INSANE_MSG="Cannot create directory with spaces." USE_DATEDIRS_MSG="file photos by date? [Y/n]" ROTATE_MSG="rotate? [y/N]" KEEP_MSG="keep? [Y/n]" WORK="job " MAIL_MSG="A message will be sent to you as work will be finished:\n1dot per photo\nDO NOT SWITCH OFF COMPUTER BEFORE HAVE RECEIPT THE MESSAGE" MAIL="Message from load_photos: " MAIL2="Photos loaded!" NO_EXIF_DATE_MSG="No date information in exif tags,\ images will be not file by date." DATE_MSG="date:" ADD_COMMENT_MSG="Would you add a comment? [N/d=>default/comment]\\nDefault : " DATE_OF_PHOTO_MSG="(photo date)" EDIT_MSG="Tidy photo?" NO_PHOTO_MSG="There is no photo to load" ############# # # PROGRAM # # # set messages language # LANGUAGE=$( echo $LANG | awk -F_ '{ print $1 }') if [[ "$LANGUAGE" != en ]] ; then if [ -f $LANGUAGE_PATH/${LANGUAGE}_load_photos ] ; then . $LANGUAGE_PATH/${LANGUAGE}_load_photos fi fi # # load personal settings # if [ -f ~/.load_photos ] ; then . ~/.load_photos fi # # load arguments from command line # i=0 IFS='\' until [ -z "$1" ] do case $1 in -h|--help) cat <<-END USAGE $(basename $0) [--nodatedDirs][--noload][--nopath][--nocomment] [--nocontrol][--noroot][--comment "Blah blah"] [-zophImport_Option \"blah blah\"][-other-option][...] --nodatedDirs causes photos will be not filed by date --noload will only load photos presents in /var/lib/zoph/incoming --nopath photos will be let in place --nocomment no comment in jpeg comment section --nocontrol photos will not be displayed, all photos will be load --noroot photos will be displayed in a window instead of root window (not it can be harmfull, depending of your focus setting) --comment type your comment yourself, no question about it will be dispalayed other options : all options of zophImport, see zophImport manpage FILES /usr/share/zoph/lang/lc_load_photos (lc is your language code) ~/.load_photos : personal settings END exit 0 ;; --datedDirs) DATEDIR="$1" shift ;; --nodatedDirs) NODATEDIRS=1 shift ;; --noload) NOLOAD=1 shift ;; --nopath) NOPATH=1 shift ;; --noroot) NOROOT=1 shift ;; --nocomment) DISABLE_COMMENT=1 shift ;; --comment) COMMENT="$2" shift 2 ;; --nocontrol) NOCONTROL=1 shift ;; --photographer) PHOTOGRAPHER=1 OPTS[$i]="$1" PHOTOGRAPHER_C="$2" (( i += 1 )) shift ;; --category) OPTS[$i]="$1" # fix quotes for mysql CATEGORY_SANE=$( echo $2 | sed -e "s/'/\\\\'/g" ) (( i += 1 )) CATEGORY_FILLED="1" shift ;; --album) OPTS[$i]="$1" ALBUM_SANE=$( echo $2 | sed -e "s/'/\\\\'/g" ) (( i += 1 )) ALBUM_FILLED="1" shift ;; --path) OPTS[$i]="$1" OPTS[$(( i += 1 ))]="$2" INDEX=$i DIRECTORY="$2" (( i += 1 )) DIRECTORY_FILLED="1" shift 2 ;; -*) OPTS[$i]="$1" ; (( i += 1 )) ; shift ;; *) #fix quotes to pass argument through "at", #whish trigger off a shell OPTS[$i]=$( echo "$1" | sed -e 's/\"/\\\"/g' ) OPTS[$i]="\"${OPTS[$i]}\"" ; (( i += 1 )) ; shift ;; esac done IFS=" " if [[ $DATEDIR == '' && $NODATEDIRS == '' ]];then echo "$USE_DATEDIRS_MSG" read i echo ${i:=y} > /dev/null if [[ $i == y ]]; then DATEDIR='--datedDirs'; fi fi # #Select album # if [[ $ALBUM_FILLED != 1 ]] ; then k="0" ALBUMS[$k]="INIT" k=1 while [[ ${ALBUMS[$(( k - 1 ))]} != '' ]];do ALBUMS[$k]=$(echo "SELECT album FROM albums WHERE album NOT IN ('Album Root') LIMIT ${k},1" | mysql -uzoph_rw -p$ZOPH_PASSWD $ZOPH_DB | sed -e '1d;' ) (( k += 1 )) done ALBUMS[$(( k - 1))]=$OTHER unset ALBUMS[0] unset ALBUMS[$k] echo $ALBUM_MSG select ALBUM in ${ALBUMS[@]} ; do if [[ $ALBUM != '' ]]; then break; fi done ALBUM[1]=$ALBUM if [[ ${ALBUM[1]} == $OTHER ]]; then echo $ALBUM_TYPE_MSG read ALBUM[1] fi ALBUM[1]="\"$(echo ${ALBUM[1]} | sed -e 's/"/\\\"/g')\"" ALBUM[0]="--album" echo ${ALBUM[@]} fi unset k if [ -z "$ALBUM_SANE" ] ; then ALBUM_SANE=$( echo ${ALBUM[1]} | sed -e "s/'/\\\\'/g;s/^\"//;s/\"$//;" ) fi #create album if not exists, and you have typed only one if [[ $(echo $ALBUM_SANE | grep -E ',' -) == '' ]] ; then EXIST_ALBUM=$(echo "SELECT album FROM albums WHERE album = '$ALBUM_SANE'" | mysql -uzoph_rw $ZOPH_DB -p$ZOPH_PASSWD ) if [[ $EXIST_ALBUM == '' ]]; then echo "Create album $ALBUM_SANE" echo "INSERT INTO albums (album,parent_album_id) VALUES ('$ALBUM_SANE',1)" | mysql -uzoph_rw $ZOPH_DB -p$ZOPH_PASSWD fi fi # #select Category # if [[ $CATEGORY_FILLED != 1 ]] ; then k="0" CATEGORIES[$k]="INIT" k=1 while [[ ${CATEGORIES[$(( k - 1 ))]} != '' ]];do CATEGORIES[$k]=$(echo "SELECT category FROM categories LIMIT ${k},1" | mysql -uzoph_rw -p$ZOPH_PASSWD $ZOPH_DB | sed -e '1d;') (( k += 1 )) done CATEGORIES[$(( k - 1))]=$OTHER unset CATEGORIES[0] unset CATEGORIES[$k] echo $CATEGORY_MSG select CATEGORY in "${CATEGORIES[@]}"; do if [[ $CATEGORY != '' ]] ; then break ; fi done CATEGORY[1]=$CATEGORY if [[ ${CATEGORY[1]} == $OTHER ]] ; then echo $CATEGORY_TYPE_MSG read CATEGORY[1] fi CATEGORY[1]="\"$(echo $CATEGORY | sed -e 's/"/\\\"/g')\"" CATEGORY[0]="--category" echo ${CATEGORY[@]} fi unset k if [ -z "$CATEGORY_SANE" ] ; then CATEGORY_SANE=$( echo ${CATEGORY[1]} | sed -e "s/'/\\\\'/g;s/^\"//;s/\"$//;" ) fi #Create category if you have typed only one if [[ $(echo $CATEGORY_SANE | grep -E ',' -) == '' ]] ; then EXIST_CATEGORY=$(echo "SELECT category FROM categories WHERE category = '$CATEGORY_SANE'" | mysql -uzoph_rw $ZOPH_DB -p$ZOPH_PASSWD) if [[ $EXIST_CATEGORY == '' ]]; then echo "Create Category $CATEGORY_SANE" echo "INSERT INTO categories (category,parent_category_id) VALUES ('$CATEGORY_SANE',1)" | mysql -uzoph_rw $ZOPH_DB -p$ZOPH_PASSWD fi fi cd $PHOTOS_ROOT # #Fill directory name # if [[ $DIRECTORY_FILLED != 1 && $NOPATH != 1 ]]; then FIND_CMD="find . -type d -group photo -perm -770 -o -type d -uid $UID" DIRECTORIES="$( $FIND_CMD | sed -e 's/^\.\///; s/.*mid//; s/.*thumb//; s/.*incoming.*//; s/.*[0-9]\{1,4\}.[0-9]\{1,2\}.[0-9]\{1,2\}//; s/^\.$//; s/lost+found//;') $OTHER" echo $DIRECTORY_MSG select DIRECTORY in $DIRECTORIES; do if [[ $DIRECTORY != '' ]] ; then break ; fi done DIRECTORY[1]=$DIRECTORY if [[ ${DIRECTORY[1]} == $OTHER ]] ; then # Ask directory name while it contains spaces SANE=1 while [[ $SANE != 0 ]]; do echo $DIRECTORY_TYPE_MSG read DIRECTORY[1] if [[ $(echo ${DIRECTORY[1]} | grep -E '(\ |\t)' -) == '' ]] ; then SANE=0 else echo $DIRECTORY_INSANE_MSG fi done fi DIRECTORY[0]="--path" echo ${DIRECTORY[@]} elif [[ $NOPATH != 1 ]]; then if [[ $(echo ${OPTS[$INDEX]} | grep -E '(\ |\t|\n)' -) == '' ]] ; then SANE=1 while [[ $SANE != 0 ]]; do echo $DIRECTORY_TYPE_MSG read OPTS[$INDEX] if [[ $(echo ${OPTS[$INDEX]} | grep -E '(\ |\t|\n)' -) == '' ]] ; then SANE=0 DIRECTORY[1]=${OPTS[$INDEX]} else echo $DIRECTORY_INSANE_MSG fi done fi DIRECTORY[0]="--path" fi #make directory UMASK=$(umask) umask 0002 mkdir -p ${DIRECTORY[1]} umask $UMASK # #fill photographer name # if [[ $PHOTOGRAPHER != 1 ]];then PHOTOGRAPHER_C="$( awk -F: {'print $3":"$5'} /etc/passwd | grep -e "^$UID:" | awk -F: '{ print $2 }' | awk -F, '{ print $1 }' )" PHOTOGRAPHER[1]="\"${PHOTOGRAPHER_C}\"" PHOTOGRAPHER[0]="--photographer" echo ${PHOTOGRAPHER[@]} fi # #fill comment # if [[ -z "$COMMENT" && -z "$DISABLE_COMMENT" ]] ; then echo -ne $ADD_COMMENT_MSG "© ${PHOTOGRAPHER_C}, $(date +%Y) $DATE_OF_PHOTO_MSG\n" read COMMENT case $COMMENT in d) COMMENT="© ${PHOTOGRAPHER_C}, $(date +%Y) " ;; n|"") DISABLE_COMMENT=1 ;; *) true ;; esac fi # #copy and control photos, rotate if needed, edit if needed, unset --datedDirs if needed # if [[ -z "$NOLOAD" ]] ; then #mount the camera if [[ "$(mount | grep $MOUNT_POINT)" == '' ]]; then mount $MOUNT_POINT || { echo "L'appareil n'est pas branché" && exit 1 ;} fi FILES=$( find $MOUNT_POINT -type f -name '*.jpg' -o -name '*.JPG' ) i=0 while [[ "$(ls -d incoming/$i 2>/dev/null)" == "incoming/$i" ]]; do (( i += 1 )) done #create an incoming directory as needed UMASK=$(umask) umask 0002 mkdir -p incoming/$i 2>/dev/null umask $UMASK DIRDEST=incoming/$i/ #copy safely photos in incoming directory o=0 for j in $FILES ; do SUFFIX=$(basename $j) SUFFIX=${SUFFIX/[^.]*./.} l=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) m=0 for p in ${VERIFY[@]} ; do q=$( basename $j ) if [[ $p == $q ]] ; then k=${DIRDEST}${q/${SUFFIX}/}${l[$m]}${n}$SUFFIX (( m += 1 )) if [[ $m == 25 ]] ; then (( n += 1 )) m=0 fi fi done VERIFY[$o]=$( basename $j ) (( o += 1 )) echo ${k:=${DIRDEST}} > /dev/null echo -n . cp $j $k unset n unset k done echo -ne "\n" DIR=incoming/$i/ #umount the camera umount $MOUNT_POINT else DIR="incoming/" fi for j in $(ls $DIR) ; do if [ -x "$( which jhead )" ]; then EXIFTAGDATE=$(jhead ${DIR}$j | grep -E "Date/Time" | awk -F: '{ print $2":"$3":"$4":"$5":"$6 }' | sed -e 's/^[[:space:]]*//;s/[[:space:]]/-/g') echo "$j - $DATE_MSG $EXIFTAGDATE" if [ -z $EXIFTAGDATE ] ; then echo "$NO_EXIF_DATE_MSG" ; DATEDIR='' if [ -z $DISABLE_COMMENT ]; then exiftran -ic "${COMMENT} $(date "+%Y:%m:%d-%T")" ${DIR}$j 2>/dev/null fi else if [ -z "$DISABLE_COMMENT" ]; then exiftran -ic "${COMMENT} $EXIFTAGDATE" ${DIR}$j 2>/dev/null fi fi fi done # rename photos to be imported safely for j in $(ls $DIR) ; do SUFFIX=$(basename $j) SUFFIX=${SUFFIX/[^.]*./.} k=$j l=(a b c d e f g h i j k l m n o p q r s t u v w x y z) m=0 DATE=$(jhead ${DIR}/${j} | grep "Date/Time" |\ awk -F: '{print $2 "." $3 "." $4 }' | awk '{print $1}') if [ -n $DATEDIR ]; then echo -ne "${DATE}\t" while [ -f ${DIRECTORY[1]}/${DATE}/$k ] ; do mv ${DIR}/$k ${DIR}/${j/${SUFFIX}/}${l[$m]}${n}$SUFFIX k=${j/.jpg/}${l[$m]}$n.jpg (( m += 1 )) if [[ $m == 25 ]] ; then (( n += 1 )) m=0 fi done j=$k else while [ -f ${DIRECTORY[1]}/$k ] ; do mv ${DIR}$k ${DIR}${j/${SUFFIX}/}${l[$m]}${n}$SUFFIX k=${j/.jpg/}${l[$m]}.jpg (( m += 1 )) if [[ $m == 25 ]] ; then (( n += 1 )) m=0 fi done j=$k fi unset n #display, rotate, edit photo if [ -z "$NOCONTROL" ] ; then if [[ $NOROOT == 1 ]] ; then qiv -w 400 -scale_down -e $DIR/$j & else qiv -x -m $DIR/$j fi echo $j echo $KEEP_MSG unset KEEP read KEEP echo ${KEEP:=y} >/dev/null if [[ $KEEP == 'n' ]]; then rm ${DIR}$j killall qiv 2>/dev/null else echo $ROTATE_MSG unset ROTATE read ROTATE killall qiv 2>/dev/null echo ${ROTATE:=n} > /dev/null if [[ $ROTATE == 'y' ]]; then exiftran -ip2 ${DIR}$j 2>/dev/null if [[ $NOROOT == 1 ]] ; then qiv -w 400 -scale_down -e $DIR/$j & else qiv -x -m $DIR/$j fi fi echo $EDIT_MSG unset EDIT read EDIT killall qiv 2>/dev/null echo ${EDIT:=n} > /dev/null if [[ $EDIT != n ]] ; then cp ${DIR}$j ${DIR}${j}.save $PHOTO_EDITOR ${DIR}$j jhead -te ${DIR}${j}.save ${DIR}$j rm ${DIR}${j}.save fi fi fi done # # execute zophImport via "at", to let the user quit immediately # if [[ -n $(ls ${PHOTOS_ROOT}/${DIR}) ]] ; then IFS='\' echo umask 0002 \; \ echo -n $MAIL \; \ zophImport "${OPTS[@]} ${ALBUM[@]} ${CATEGORY[@]} ${DIRECTORY[@]} ${PHOTOGRAPHER[@]}" \ $DATEDIR ${PHOTOS_ROOT}/${DIR}* \; \ if [ -d ${PHOTOS_ROOT}/${DIR}.xvpics ] \; then \ rm -r ${PHOTOS_ROOT}/${DIR}.xvpics \; \ fi \; \ if [ "$DIR" != "incoming/" ] \; then \ rmdir ${PHOTOS_ROOT}/$DIR \; \ fi \; \ echo $MAIL2 | at now + 1 minutes 2>/dev/null IFS=' ' # # display work message # clear echo -n $WORK atq echo -e $MAIL_MSG else echo $NO_PHOTO_MSG fi

Beautifier Valid XHTML 1.1 Valid CSS!

retour
commentaires
©left 2000-2005, Thomas Harding
Pub : [ Lynx, acute the web ]
[ projet GNU ]
[ la Debian 3.0 [Woody] est sortie ! ]
metooers