handle raw+jpeg
This commit is contained in:
parent
2b02cfcd43
commit
92f21dd914
|
@ -4,13 +4,15 @@ declare -A out_dirs=(
|
|||
["image"]="${HOME}/data/photos"
|
||||
["video"]="${HOME}/data/videos"
|
||||
)
|
||||
declare -a g_files=()
|
||||
# list of sidecar extensions
|
||||
SIDECAR="pp2 pp3 xmp bib"
|
||||
SIDECAR="pp3 xmp pp2 bib"
|
||||
# params
|
||||
TITLE=
|
||||
DELETE=0
|
||||
DEBUG=0
|
||||
YES=0
|
||||
NO_JPEG=0
|
||||
|
||||
import_photo()
|
||||
{
|
||||
|
@ -22,6 +24,7 @@ import_photo()
|
|||
mimetype=$(exiftool -mimetype -s3 "${image}" 2>/dev/null)
|
||||
mimetype_short=${mimetype%%/*}
|
||||
|
||||
# skip files not returning exif data
|
||||
if [ x"$?" != "x0" ]
|
||||
then
|
||||
if [ ${DEBUG} -eq 1 ]
|
||||
|
@ -31,6 +34,7 @@ import_photo()
|
|||
return
|
||||
fi
|
||||
|
||||
# skip unmanaged files
|
||||
if [ "${mimetype_short}" != "image" -a "${mimetype_short}" != "video" ]
|
||||
then
|
||||
echo "Skip file ${image} of unmanaged mime type ${mimetype}"
|
||||
|
@ -38,6 +42,33 @@ import_photo()
|
|||
fi
|
||||
local out=${out_dirs[$mimetype_short]}
|
||||
|
||||
# handle raw+jpeg
|
||||
if [ "${mimetype}" = "image/jpeg" -a ${NO_JPEG} -eq 1 ]
|
||||
then
|
||||
# if raw file exists, skip the jpeg
|
||||
local file_count=${#g_files[@]}
|
||||
local i
|
||||
for (( i = 0; i < file_count ; i++ ))
|
||||
do
|
||||
if [ "${g_files[$i]}" != "${image}" -a "${g_files[$i]%.*}" = "${image%.*}" ]
|
||||
then
|
||||
if [ ${DELETE} -eq 1 ]
|
||||
then
|
||||
rm -f "${image}"
|
||||
for side_ext in $SIDECAR
|
||||
do
|
||||
if [ -f "${image}.${side_ext}" ]
|
||||
then
|
||||
rm -f "${image}.${side_ext}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "Skip file ${image} from a RAW+jpeg pair"
|
||||
return
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# prepend date prefix to dest file name
|
||||
local file
|
||||
local prefix
|
||||
|
@ -87,12 +118,13 @@ import_photo()
|
|||
}
|
||||
|
||||
|
||||
while getopts "hdn:y" flag
|
||||
while getopts "hdjn:y" flag
|
||||
do
|
||||
case $flag in
|
||||
h)
|
||||
echo "Usage: $0 [options] <file|directory>..."
|
||||
echo "-d : delete source"
|
||||
echo "-j : RAW+jpeg, skip jpeg"
|
||||
echo "-n <name> : title"
|
||||
echo "-y : force-yes"
|
||||
exit
|
||||
|
@ -100,6 +132,9 @@ do
|
|||
d)
|
||||
DELETE=1
|
||||
;;
|
||||
j)
|
||||
NO_JPEG=1
|
||||
;;
|
||||
n)
|
||||
TITLE=${OPTARG}
|
||||
case ${TITLE} in
|
||||
|
@ -135,20 +170,42 @@ then
|
|||
fi
|
||||
fi
|
||||
|
||||
# build a complete file list
|
||||
for rsrc in `seq $OPTIND $#`
|
||||
do
|
||||
if [ -f "${!rsrc}" ]
|
||||
then
|
||||
import_photo "${TITLE}" "${!rsrc}"
|
||||
g_files+=("${!rsrc}")
|
||||
elif [ -d "${!rsrc}" ]
|
||||
then
|
||||
echo "Recursing into '${!rsrc}'"
|
||||
find "${!rsrc}" -type f | sort | while read file
|
||||
while read file
|
||||
do
|
||||
import_photo "${TITLE}" "${file}"
|
||||
done
|
||||
else
|
||||
echo "warning : '${!rsrc}' does not exists. file vanished during import (typical for sidecar files with agressive globing)?"
|
||||
g_files+=("${file}")
|
||||
done < <(find "${!rsrc}" -type f | sort)
|
||||
fi
|
||||
done
|
||||
|
||||
file_count=${#g_files[@]}
|
||||
for (( i = 0; i < file_count ; i++ ))
|
||||
do
|
||||
# skip sidecar files
|
||||
for side_ext in $SIDECAR
|
||||
do
|
||||
if [[ "${g_files[$i]}" == *"${side_ext}" ]]
|
||||
then
|
||||
if [ ${DEBUG} -eq 1 ]
|
||||
then
|
||||
echo "Skip sidecar file"
|
||||
fi
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
if [ -f "${g_files[$i]}" ]
|
||||
then
|
||||
import_photo "${TITLE}" "${g_files[$i]}"
|
||||
else
|
||||
echo "warning : '${g_files[$i]}' does not exists. file vanished during import (typical for sidecar files with agressive globing or jpeg in RAW+jpeg mode)?"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue