'
;;
none | *)
echo ''
;;
esac
}
print_html_table_end ()
{
if [ $GLOBAL_last_row_was_closed -eq 0 ]
then
echo ""
fi
echo ""
echo '
'
if [ -n "$GLOBAL_boilerplate_index_after_table_before_indexlinks" -a \
"$GLOBAL_boilerplate_index_after_table_before_indexlinks" != "undef" ]
then
echo "$GLOBAL_boilerplate_index_after_table_before_indexlinks"
fi
}
print_html_row_start ()
{
echo ""
echo ''
}
print_html_row_end ()
{
echo '
'
echo ""
if [ $GLOBAL_index_table_spacing = "loose" ]
then
#
echo "| |
"
fi
}
print_html_column_start ()
{
echo ' '
}
print_html_column_end ()
{
echo ' | '
}
# FIXME: I can't decide if the user's footer text should come
# before the "This page created" text or after that text. If they're
# putting a
tag, it would probably look better to put the
# This Page text after the user's footer text.
print_html_footer ()
{
local fn t date
fn="$*"
echo ""
if [ -n "$GLOBAL_this_page_created_text" -a \
"$GLOBAL_this_page_created_text" != "undef" ]
then
date=`date '+%Y-%m-%d'`
t=`echo "$GLOBAL_this_page_created_text" |
sed -e 's,@LINKSTART@,,' |
sed -e 's,@LINKEND@,,' -e "s,@DATE@,${date},"`
[ -n "$t" ] && echo "$t
"
fi
if [ -n "$GLOBAL_boilerplate_footer" -a "$GLOBAL_boilerplate_footer" != undef ]
then
echo ""
echo "$GLOBAL_boilerplate_footer"
echo ""
fi
cat << __EOM__
__EOM__
if [ -n "$GLOBAL_boilerplate_index_end_of_page" -a \
"$GLOBAL_boilerplate_index_end_of_page" != undef ]
then
echo "$GLOBAL_boilerplate_index_end_of_page"
elif [ -n "$GLOBAL_boilerplate_end_of_page" -a \
"$GLOBAL_boilerplate_end_of_page" != undef ]
then
echo "$GLOBAL_boilerplate_end_of_page"
else
echo "$GLOBAL_body_end_tag"
echo ''
fi
add_checksum_to_file "$fn"
remove_cleanup "$fn"
}
#########################################################
#### slideshow functions
#########################################################
create_slideshow ()
{
local fileset prev cur next
[ $GLOBAL_create_slideshow -eq 0 ] && return
progress_update_start_creating_slideshow_pages
remove_existing_slideshow_html_files
create_slideshow_image_list
while read fileset
do
prev=`echo "$fileset" | cut -d\| -f1`
cur=`echo "$fileset" | cut -d\| -f2`
next=`echo "$fileset" | cut -d\| -f3`
create_slideshow_source_file "$prev" "$cur" "$next"
if [ $GLOBAL_reduce_big_pics -eq 1 -a \
$GLOBAL_there_is_at_least_one_reduced_img -eq 1 ]
then
create_slideshow_reduced_file "$prev" "$cur" "$next"
fi
if [ $GLOBAL_create_large_images -eq 1 -a \
$GLOBAL_there_is_at_least_one_large_img -eq 1 ]
then
create_slideshow_large_file "$prev" "$cur" "$next"
fi
progress_update_created_slideshow_page
done < $GLOBAL_slideshow_image_list
progress_update_done_creating_slideshow_pages
}
create_slideshow_source_file ()
{
local prev_image cur_image next_image html_file
prev_image="$1"
cur_image="$2"
next_image="$3"
image_name_to_html_name "$cur_image"
html_file="$RETURN_html_name"
add_cleanup "$html_file"
touch "$html_file"
make_file_world_readable "$html_file"
# The following exec goop so I don't have to manually redirect every
# message to stderr in this function.
exec 5>&1 # save stdout fd to fd #5
exec > "$html_file" # redirect stdout to the file
print_slideshow_file_header "$prev_image" "$cur_image" "$next_image"
print_slideshow_top_navlinks "$prev_image" "$cur_image" "$next_image"
print_slideshow_image "$cur_image" "source"
print_slideshow_size_links "source" "$cur_image"
print_slideshow_image_description "$cur_image"
print_image_exif_info "$cur_image"
print_slideshow_file_footer
remove_cleanup "$html_file"
exec 1>&5 # Copy stdout fd back from temporary save fd, #5
}
create_slideshow_reduced_file ()
{
local prev_image cur_image next_image
local cur_source_image cur_reduced_image html_file
prev_image="$1"
cur_image="$2"
next_image="$3"
cur_source_image="$cur_image"
cur_reduced_image="$cur_image"
if [ "$prev_image" != NULL ]
then
source_name_to_reduced_name "$prev_image"
prev_image="$RETURN_reduced_name"
fi
source_name_to_reduced_name "$cur_image"
cur_reduced_image="$RETURN_reduced_name"
if [ -f "$RETURN_reduced_name" ]
then
cur_image="$RETURN_reduced_name"
else
source_name_to_large_name "$cur_image"
if [ -f "$RETURN_large_name" ]
then
cur_image="$RETURN_large_name"
fi
fi
if [ "$next_image" != NULL ]
then
source_name_to_reduced_name "$next_image"
next_image="$RETURN_reduced_name"
fi
image_name_to_html_name "$cur_reduced_image"
html_file="$RETURN_html_name"
add_cleanup "$html_file"
touch "$html_file"
make_file_world_readable "$html_file"
# The following exec goop so I don't have to manually redirect every
# message to stderr in this function.
exec 5>&1 # save stdout fd to fd #5
exec > "$html_file" # redirect stdout to the file
print_slideshow_file_header "$prev_image" "$cur_image" "$next_image"
print_slideshow_top_navlinks "$prev_image" "$cur_image" "$next_image"
print_slideshow_image "$cur_image" "reduced"
print_slideshow_size_links "reduced" "$cur_image"
print_slideshow_image_description "$cur_image"
print_image_exif_info "$cur_reduced_image"
print_slideshow_file_footer
remove_cleanup "$html_file"
exec 1>&5 # Copy stdout fd back from temporary save fd, #5
}
create_slideshow_large_file ()
{
local prev_image cur_image next_image
local cur_source_image cur_large_image html_file
prev_image="$1"
cur_image="$2"
next_image="$3"
cur_source_image="$cur_image"
cur_large_image="$cur_image"
if [ "$prev_image" != NULL ]
then
source_name_to_large_name "$prev_image"
prev_image="$RETURN_large_name"
fi
source_name_to_large_name "$cur_image"
cur_large_image="$RETURN_large_name"
if [ -f "$RETURN_large_name" ]
then
cur_image="$RETURN_large_name"
else
source_name_to_reduced_name "$cur_image"
if [ -f "$RETURN_reduced_name" ]
then
cur_image="$RETURN_reduced_name"
fi
fi
if [ "$next_image" != NULL ]
then
source_name_to_large_name "$next_image"
next_image="$RETURN_large_name"
fi
image_name_to_html_name "$cur_large_image"
html_file="$RETURN_html_name"
add_cleanup "$html_file"
touch "$html_file"
make_file_world_readable "$html_file"
# The following exec goop so I don't have to manually redirect every
# message to stderr in this function.
exec 5>&1 # save stdout fd to fd #5
exec > "$html_file" # redirect stdout to the file
print_slideshow_file_header "$prev_image" "$cur_image" "$next_image"
print_slideshow_top_navlinks "$prev_image" "$cur_image" "$next_image"
print_slideshow_image "$cur_image" "large"
print_slideshow_size_links "large" "$cur_image"
print_slideshow_image_description "$cur_image"
print_image_exif_info "$cur_large_image"
print_slideshow_file_footer
remove_cleanup "$html_file"
exec 1>&5 # Copy stdout fd back from temporary save fd, #5
}
javascript_navigate='
'
javascript_next_img='if (keyval == key_n || keyval == key_k) { location = "@NEXT@"; return true; }'
javascript_previous_img='if (keyval == key_p || keyval == key_j) { location = "@PREVIOUS@"; return true; }'
print_slideshow_file_header ()
{
local source_image prev_image next_image
local t t_prev t_next
prev_image="$1"
source_image="$2"
next_image="$3"
get_image_caption "$source_image"
is_this_a_boring_filename "$source_image"
if [ $GLOBAL_slideshow_print_javascript_navigation -eq 1 ]
then
if [ "$prev_image" != NULL -a "$prev_image" ]
then
image_name_to_html_name "$prev_image"
quote_url_chars "$RETURN_html_name"
t_prev=`echo "$javascript_previous_img" |
sed "s/@PREVIOUS@/${RETURN_url}/g"`
fi
if [ "$next_image" != NULL -a "$next_image" ]
then
image_name_to_html_name "$next_image"
quote_url_chars "$RETURN_html_name"
t_next=`echo "$javascript_next_img" |
sed "s/@NEXT@/${RETURN_url}/g"`
fi
t=`echo "$javascript_navigate" |
sed -e "s/@JAVASCRIPT_PREVIOUS@/${t_prev}/g" |
sed -e "s/@JAVASCRIPT_NEXT@/${t_next}/g"`
fi
#
echo ''
echo ''
echo ''
echo " $RETURN_caption_inline"
[ -n "$GLOBAL_meta_tag" -a "$GLOBAL_meta_tag" != undef ] && echo " $GLOBAL_meta_tag"
if [ "$GLOBAL_html_charset" != "undef" ]
then
echo " "
fi
echo " "
echo ' '
[ $GLOBAL_slideshow_print_javascript_navigation -eq 1 ] && echo "$t"
if [ -n "$GLOBAL_boilerplate_slideshow_insert_in_head" -a \
"$GLOBAL_boilerplate_slideshow_insert_in_head" != undef ]
then
echo "$GLOBAL_boilerplate_slideshow_insert_in_head"
elif [ -n "$GLOBAL_boilerplate_insert_in_head" -a \
"$GLOBAL_boilerplate_insert_in_head" != undef ]
then
echo "$GLOBAL_boilerplate_insert_in_head"
fi
echo ''
echo "$GLOBAL_body_tag"
echo ""
if [ -n "$GLOBAL_boilerplate_slideshow_before_title" -a \
"$GLOBAL_boilerplate_slideshow_before_title" != undef ]
then
echo "$GLOBAL_boilerplate_slideshow_before_title"
echo ""
elif [ -n "$GLOBAL_boilerplate_before_title" -a \
"$GLOBAL_boilerplate_before_title" != undef ]
then
echo "$GLOBAL_boilerplate_before_title"
echo ""
fi
if [ $GLOBAL_print_title_on_slideshow -eq 1 ]
then
get_directory_title
if [ -n "$RETURN_directory_title_inline" ]
then
if [ $RETURN_directory_title_is_from_user -eq 1 ]
then
echo $ac_n "$GLOBAL_slideshow_page_title_start_html$ac_c"
echo $ac_n "$RETURN_directory_title_inline$ac_c"
if [ $GLOBAL_heuristic_filenames_are_digicam_boring -eq 0 -o \
$RETURN_caption_was_from = "descriptions-file" -o \
$RETURN_is_boring -eq 0 ]
then
echo $ac_n " / $RETURN_caption_inline$ac_c"
fi
echo "$GLOBAL_slideshow_page_title_end_html"
elif [ $RETURN_caption_was_from = "descriptions-file" -o \
$RETURN_is_boring -eq 0 ]
then
echo $ac_n "$GLOBAL_slideshow_page_title_start_html$ac_c"
echo $ac_n "$RETURN_caption_inline$ac_c"
echo "$GLOBAL_slideshow_page_title_end_html"
fi
fi
fi
if [ -n "$GLOBAL_boilerplate_slideshow_after_title" -a \
"$GLOBAL_boilerplate_slideshow_after_title" != undef ]
then
echo "$GLOBAL_boilerplate_slideshow_after_title"
echo ""
elif [ -n "$GLOBAL_boilerplate_after_title" -a \
"$GLOBAL_boilerplate_after_title" != undef ]
then
echo "$GLOBAL_boilerplate_after_title"
echo ""
fi
}
print_slideshow_size_links ()
{
local current_image current_image_type
local reduced_image large_image orig_image
local reduced_link_text large_link_text orig_link_text
local size
local spacer t
current_image_type="$1"
current_image="$2"
if [ $GLOBAL_slideshow_img_size_across_two_lines -eq 1 ]
then
spacer="
"
else
spacer=" "
fi
generated_name_to_source_name "$current_image"
orig_image="$RETURN_source_name"
source_name_to_reduced_name "$orig_image"
reduced_image="$RETURN_reduced_name"
source_name_to_large_name "$orig_image"
large_image="$RETURN_large_name"
if [ -f "$reduced_image" ]
then
if [ $GLOBAL_print_img_size_on_slideshow -eq 1 ]
then
return_image_size "$reduced_image"
size="${spacer}(${RETURN_image_size_str})"
fi
t=`echo "$GLOBAL_reduced_text" | sed -e 's, ,\ ,g'`
if [ "$current_image_type" != "reduced" ]
then
image_name_to_html_name "$reduced_image"
quote_url_chars "$RETURN_html_name"
reduced_link_text="[${t}]$size"
else
reduced_link_text="[${t}]$size"
fi
fi
if [ -f "$large_image" ]
then
if [ $GLOBAL_print_img_size_on_slideshow -eq 1 ]
then
return_image_size "$large_image"
size="${spacer}(${RETURN_image_size_str})"
fi
t=`echo "$GLOBAL_large_text" | sed -e 's, ,\ ,g'`
if [ "$current_image_type" != "large" ]
then
image_name_to_html_name "$large_image"
quote_url_chars "$RETURN_html_name"
large_link_text="[${t}]$size"
else
large_link_text="[${t}]$size"
fi
fi
if [ -f "$orig_image" ]
then
if [ $GLOBAL_print_img_size_on_slideshow -eq 1 ]
then
return_image_size "$orig_image"
size="${spacer}(${RETURN_image_size_str})"
fi
t=`echo "$GLOBAL_original_text" | sed -e 's, ,\ ,g'`
if [ "$current_image_type" != "source" ]
then
image_name_to_html_name "$orig_image"
quote_url_chars "$RETURN_html_name"
orig_link_text="[${t}]$size"
else
orig_link_text="[${t}]$size"
fi
fi
[ -z "$reduced_link_text" -a -z "$large_link_text" ] && return
echo ''
echo '
'
echo " | $reduced_link_text | "
echo " | "
echo " $large_link_text | "
echo " | "
echo " $orig_link_text | "
echo '
'
}
print_slideshow_image_description ()
{
local image_name
image_name="$*"
get_image_description "$image_name"
if [ -n "$RETURN_image_description" ]
then
echo "$RETURN_image_description
"
fi
}
print_slideshow_file_footer ()
{
if [ -n "$GLOBAL_boilerplate_footer" -a \
"$GLOBAL_boilerplate_footer" != undef ]
then
echo ""
echo "$GLOBAL_boilerplate_footer"
echo ""
fi
if [ -n "$GLOBAL_boilerplate_slideshow_end_of_page" -a \
"$GLOBAL_boilerplate_slideshow_end_of_page" != undef ]
then
echo "$GLOBAL_boilerplate_slideshow_end_of_page"
elif [ -n "$GLOBAL_boilerplate_end_of_page" -a \
"$GLOBAL_boilerplate_end_of_page" != undef ]
then
echo "$GLOBAL_boilerplate_end_of_page"
else
echo "$GLOBAL_body_end_tag"
echo ""
fi
}
print_slideshow_image ()
{
local cur_image type target_pre target_post
local source_image click_target_image
local caption_quoted
cur_image="$1"
type="$2"
target_pre=""
target_post=""
get_image_caption "$cur_image"
is_this_a_boring_filename "$cur_image"
if [ $RETURN_is_boring -eq 1 -a $RETURN_caption_was_from = filename ]
then
caption_quoted=""
else
quote_html_chars "$RETURN_caption_inline"
caption_quoted="$RETURN_html"
fi
# If we're going to make the image clickable, then clicking proceeds
# in this order if all the image types exist:
# reduced -> large -> source -> reduced -> large -> ...
if [ $GLOBAL_slideshow_images_are_clickable -eq 1 ]
then
generated_name_to_source_name "$cur_image"
source_image="$RETURN_source_name"
source_name_to_large_name "$source_image"
source_name_to_reduced_name "$source_image"
if [ "$type" = "reduced" ]
then
if [ -f "$RETURN_large_name" ]
then
click_target_image="$RETURN_large_name"
else
click_target_image="$source_image"
fi
fi
if [ "$type" = "large" ]
then
click_target_image="$source_image"
fi
if [ "$type" = "source" ]
then
if [ -f "$RETURN_reduced_name" ]
then
click_target_image="$RETURN_reduced_name"
elif [ -f "$RETURN_large_name" ]
then
click_target_image="$RETURN_large_name" ]
fi
fi
if [ -n "$click_target_image" -a "$click_target_image" != "$cur_image" ]
then
image_name_to_html_name "$click_target_image"
quote_url_chars "$RETURN_html_name"
target_pre=""
target_post=""
fi
fi
get_dimensions "$cur_image"
echo ""
quote_url_chars "$cur_image"
echo "$target_pre

$target_post
"
echo ""
}
print_slideshow_top_navlinks ()
{
local prev_image cur_image next_image
local prev_html cur_html next_html
local prev_markup middle_markup next_markup index_href
local imgno imgtotal right_text left_text
local t
prev_image="$1"
cur_image="$2"
next_image="$3"
prev_html="$prev_image"
cur_html="$cur_image"
next_html="$next_image"
middle_markup=""
if [ "$prev_image" != NULL ]
then
image_name_to_html_name "$prev_image"
prev_html="$RETURN_html_name"
fi
image_name_to_html_name "$cur_image"
cur_html="$RETURN_html_name"
if [ "$next_image" != NULL ]
then
image_name_to_html_name "$next_image"
next_html="$RETURN_html_name"
fi
## Emit link to previous image
if [ "$prev_image" = NULL ]
then
prev_markup="$GLOBAL_slideshow_previous_pre_link$GLOBAL_slideshow_previous$GLOBAL_slideshow_previous_post_link"
else
quote_url_chars "$prev_html"
prev_markup="$GLOBAL_slideshow_previous_pre_link$GLOBAL_slideshow_previous$GLOBAL_slideshow_previous_post_link"
fi
## Emit link to next image
if [ "$next_image" = NULL ]
then
next_markup="$GLOBAL_slideshow_next_pre_link$GLOBAL_slideshow_next$GLOBAL_slideshow_next_post_link"
else
quote_url_chars "$next_html"
next_markup="$GLOBAL_slideshow_next_pre_link$GLOBAL_slideshow_next$GLOBAL_slideshow_next_post_link"
fi
## Emit link to index
map_image_to_index "$cur_image"
middle_markup="$GLOBAL_slideshow_ret_to_index_pre_link$GLOBAL_slideshow_ret_to_index$GLOBAL_slideshow_ret_to_index_post_link"
## Get "Image xx of yy" info
get_image_number "$cur_image"
imgno="$RETURN_image_number"
imgtotal="$RETURN_number_of_images"
if [ -n "$imgno" -a -n "$imgtotal" ]
then
t=`echo "$GLOBAL_image_xx_of_yy_text" |
sed -e "s,@CURRENT@,${imgno}," -e "s,@TOTAL@,${imgtotal},"`
right_txt="$t"
left_txt=""
else
right_txt=" "
left_txt=" "
fi
get_image_timestamp_from_dates_file "$cur_image"
if [ -n "$RETURN_timestamp" ]
then
left_txt="$RETURN_timestamp"
fi
echo ''
echo ''
echo ""
echo " | $left_txt | "
echo ' '
echo ' '
echo " | $prev_markup | "
echo " | "
echo " $middle_markup | "
echo " | "
echo " $next_markup | "
echo ' '
echo ' | '
echo " $right_txt | "
echo '
'
echo '
'
echo ''
}
create_slideshow_image_list ()
{
local number_of_files
local prev_num cur_num next_num
local prev_image cur_image next_image
number_of_files=`cat $GLOBAL_image_list_tmpfile | wc -l | sed 's, ,,g'`
cur_num=1
make_tmpfile ss-source
GLOBAL_slideshow_image_list=$RETURN_tmpfile
while [ $cur_num -le $number_of_files ]
do
prev_num=`expr $cur_num - 1`
next_num=`expr $cur_num + 1`
if [ $cur_num -eq 1 ]
then
prev_image=NULL
else
prev_image=`cat $GLOBAL_image_list_tmpfile | sed -n "${prev_num}p"`
fi
cur_image=`cat $GLOBAL_image_list_tmpfile | sed -n "${cur_num}p"`
if [ $cur_num -eq $number_of_files ]
then
next_image=NULL
else
next_image=`cat $GLOBAL_image_list_tmpfile | sed -n "${next_num}p"`
fi
echo "${prev_image}|${cur_image}|${next_image}" >> $GLOBAL_slideshow_image_list
cur_num=`expr $cur_num + 1`
done
}
remove_existing_slideshow_html_files ()
{
local file_list fn
make_tmpfile file_list
file_list=$RETURN_tmpfile
ls -1 | grep "\.$GLOBAL_html_file_suffix" > $file_list
while read fn
do
if grep "makethumbs generated HTML file which may be removed without warning" "$fn" >/dev/null 2>&1
then
rm -f "$fn"
fi
done < $file_list
}
#########################################################
#### Progress printing functions
#########################################################
# Descriptions.txt
progress_update_start_descriptions ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
}
progress_update_created_descriptions ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Created $GLOBAL_descriptions_filename$ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
progress_update_updated_descriptions ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Updated $GLOBAL_descriptions_filename$ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
# Dates.txt
progress_update_start_updating_dates ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
}
progress_update_done_updating_dates ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Updated $GLOBAL_dates_filename$ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
progress_update_start_creating_dates ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Creating $GLOBAL_dates_filename $ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
}
progress_update_created_date ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n ".$ac_c" >&2
}
progress_update_done_creating_dates ()
{
local time
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n " done.$ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
# index.html
progress_update_start_creating_index_html ()
{
local fn
fn="$*"
[ -z "$fn" ] && fn="$GLOBAL_index_filename"
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Creating $fn$ac_c" >&2
}
progress_update_done_creating_index_html ()
{
local time
[ $GLOBAL_show_progress -eq 0 ] && return
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
# reduced/thumbnail images
progress_update_start_creating_reduced_images ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Making reduced/thumbnail images $ac_c" >&2
GLOBAL_did_we_reduce_anything=0
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
}
progress_update_created_reduced_image ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "o$ac_c" >&2
GLOBAL_did_we_reduce_anything=1
}
progress_update_created_large_image ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "O$ac_c" >&2
GLOBAL_did_we_reduce_anything=1
}
progress_update_created_thumbnail_image ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n ".$ac_c" >&2
GLOBAL_did_we_reduce_anything=1
}
progress_update_done_creating_reduced_images ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
if [ $GLOBAL_did_we_reduce_anything -eq 0 ]
then
echo $ac_n "(none regenerated)$ac_c" >&2
else
echo $ac_n " done.$ac_c" >&2
fi
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
# slideshow pages
progress_update_start_creating_slideshow_pages ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n "Making slideshow pages $ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
GLOBAL_progress_timestamp_start=`date '+%s' 2>/dev/null`
fi
}
progress_update_created_slideshow_page ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n ".$ac_c" >&2
}
progress_update_done_creating_slideshow_pages ()
{
[ $GLOBAL_show_progress -eq 0 ] && return
echo $ac_n " done.$ac_c" >&2
if [ $GLOBAL_show_timings -eq 1 ]
then
print_timestamp_diff $GLOBAL_progress_timestamp_start `date '+%s'`
fi
echo "" >&2
}
print_timestamp_diff ()
{
local start end
local secs
local mins
start=$1
end=$2
secs=""
mins=""
[ -z "$start" -o -z "$end" ] && return
secs=`expr $end - $start 2>/dev/null`
[ -z "$secs" ] && return
if [ $secs -ge 100 ]
then
mins=`expr $secs / 60`
secs=`expr $secs % 60`
echo $ac_n " ($mins minutes $secs seconds)$ac_c" >&2
else
echo $ac_n " ($secs seconds)$ac_c" >&2
fi
}
#########################################################
#### checksum checking functions, unmodified file removal
#########################################################
remove_file_if_unmodified ()
{
local filename
filename="$*"
verify_file_checksum "$filename"
if [ $RETURN_cksum_ok -eq 1 ]
then
rm -f "$filename"
return
fi
}
# $RETURN_cksum_ok is '1' if a valid checksum is found. If no checksum
# is found, or the checksum doesn't match, a '0' is returned (i.e. the
# user may have modified this file for all we know).
verify_file_checksum ()
{
local filename sum_program recorded_sum sum_output
filename="$*"
RETURN_cksum_ok=0
if grep ',\1,'`
recorded_sum=`grep ',\2,'`
find_in_path "$sum_program"
[ $RETURN_found -eq 0 ] && return
sum_output=`grep -v '" >> "$filename"
}
normalize_checksum_string ()
{
local istr
istr="$*"
istr=`echo "$istr" | sed -e 's,^[ ]*,,' -e 's,[ ]*$,,' \
-e 's,[ ][ ]*, ,'`
RETURN_str_norm="$istr"
}
#########################################################
#### descriptions.txt support
#########################################################
create_descriptions_file ()
{
local max i l
progress_update_start_descriptions
if [ -f $GLOBAL_descriptions_filename ]
then
update_descriptions_file
return
fi
add_cleanup $GLOBAL_descriptions_filename
touch $GLOBAL_descriptions_filename
make_file_world_readable $GLOBAL_descriptions_filename
echo '[short title] (best to avoid HTML markup here, keep it short,
s are OK)' > $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
echo '[longer page description] (all the HTML you want, as many lines as you want)' >> $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
echo '[captions] (best to avoid HTML markup here, keep it short,
s are OK)' >> $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
# find max length of image names
max=0
while read i
do
l=`echo "$i" | awk '{print length}'`
[ $l -gt $max ] && max=$l
done < $GLOBAL_image_list_tmpfile
while read i
do
echo "$i" |
awk "{printf (\"%-${max}s \\n\""', $0);}' >> $GLOBAL_descriptions_filename
done < $GLOBAL_image_list_tmpfile
echo '' >> $GLOBAL_descriptions_filename
echo '[descriptions] (all the HTML you want, but each file on just one line)' >> $GLOBAL_descriptions_filename
echo '' >> $GLOBAL_descriptions_filename
while read i
do
echo "$i" |
awk "{printf (\"%-${max}s \\n\""', $0);}' >> $GLOBAL_descriptions_filename
done < $GLOBAL_image_list_tmpfile
remove_cleanup $GLOBAL_descriptions_filename
make_file_world_readable $GLOBAL_descriptions_filename
progress_update_created_descriptions
}
update_descriptions_file ()
{
local filenames_to_add fn new_desc oldsz newsz
make_tmpfile newfiles
filenames_to_add="$RETURN_tmpfile"
while read fn
do
check_if_file_in_descriptions_file "$fn"
if [ $RETURN_file_is_present -eq 0 ]
then
echo "$fn " >> $filenames_to_add
fi
done < $GLOBAL_image_list_tmpfile
[ ! -s $filenames_to_add ] && return
make_tmpfile new-desc
new_desc="$RETURN_tmpfile"
cat $GLOBAL_descriptions_filename | sed '/^\[captions\]/,$d' > $new_desc
grep '^\[captions\]' $GLOBAL_descriptions_filename >> $new_desc
echo "" >> $new_desc
cat $GLOBAL_descriptions_filename |
sed '1,/^\[captions\]/d' |
sed '/^\[descriptions\]/,$d' | grep -v '^[ ]*$' >> $new_desc
cat $filenames_to_add >> $new_desc
echo "" >> $new_desc
grep '^\[descriptions\]' $GLOBAL_descriptions_filename >> $new_desc
echo "" >> $new_desc
cat $GLOBAL_descriptions_filename |
sed '1,/^\[descriptions\]/d' | grep -v '^[ ]*$' >> $new_desc
cat $filenames_to_add >> $new_desc
[ ! -s "$new_desc" ] && return
oldsz=`ls -l $GLOBAL_descriptions_filename | awk '{print $5}' | sed 's,[^0-9],,g'`
newsz=`ls -l $new_desc | awk '{print $5}' | sed 's,[^0-9],,g'`
# If the new one isn't larger than the old one, something is wrong.
if [ $newsz -gt $oldsz ]
then
cat $new_desc > $GLOBAL_descriptions_filename
else
echo WARNING: Some problem updating the $GLOBAL_descriptions_filename 1>&2
fi
progress_update_updated_descriptions
}
#
validate_descriptions_file ()
{
local is_valid
[ ! -f $GLOBAL_descriptions_filename ] && return
[ $GLOBAL_descriptions_file_validated -eq 1 ] && return
[ $GLOBAL_descriptions_file_is_invalid -eq 1 ] && return
is_valid=`cat $GLOBAL_descriptions_filename |
egrep '^\[short title\]|^\[longer page description\]|^\[captions\]|^\[descriptions\]' |
awk 'BEGIN { state = 0 } { \
if ($1 == "[short" && $2 == "title]" && state == 0 )
{ state = 1 ; next }
if ($1 == "[longer" && $2 == "page" && state == 1)
{ state = 2 ; next}
if ($1 == "[captions]" && state == 2)
{ state = 3; next}
if ($1 == "[descriptions]" && state == 3)
{ print "ok"; next}
print "error"
}'`
if [ -n "$is_valid" ]
then
if [ "$is_valid" = "ok" ]
then
GLOBAL_descriptions_file_validated=1
else
echo WARNING: Invalid $GLOBAL_descriptions_filename ! Ignoring. 1>&2
GLOBAL_descriptions_file_is_invalid=1
fi
fi
}
check_if_file_in_descriptions_file ()
{
local title_count no_title_count tot
RETURN_file_is_present=0
quote_egrep_chars "$*"
title_count=`egrep "^$RETURN_egrep[ ]*[^ ].*\$" $GLOBAL_descriptions_filename | wc -l | sed 's,[^0-9],,g'`
no_title_count=`egrep "^$RETURN_egrep[ ]*\$" $GLOBAL_descriptions_filename | wc -l | sed 's,[^0-9],,g'`
tot=`expr "$title_count" + "$no_title_count"`
if [ -n "$tot" -a "$tot" -ge 2 ]
then
RETURN_file_is_present=1
fi
if [ $GLOBAL_no_image_titles_or_descriptions -eq 1 -a "$title_count" -gt 0 ]
then
GLOBAL_no_image_titles_or_descriptions=0
fi
}
get_short_page_title_from_descriptions_file ()
{
RETURN_short_page_title=""
[ ! -f $GLOBAL_descriptions_filename ] && return
validate_descriptions_file
[ $GLOBAL_descriptions_file_validated -eq 0 ] && return
RETURN_short_page_title=`cat $GLOBAL_descriptions_filename | grep -v '^#' |
awk 'BEGIN { seen_title = 0; seen_longerdesc = 0; } \
{ \
if ($1 == "[short" && $2 == "title]") { seen_title = 1; next; }
if (seen_title != 1) { next; }
if ($1 == "[longer" && $2 == "page") { seen_longerdesc = 1; next; }
if (seen_longerdesc == 1) { next; }
print;
}' | grep -v '^[ ]*$'`
RETURN_short_page_title=`echo "$RETURN_short_page_title" |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
}
get_page_description_from_descriptions_file ()
{
RETURN_page_description=""
[ ! -f $GLOBAL_descriptions_filename ] && return
validate_descriptions_file
[ $GLOBAL_descriptions_file_validated -eq 0 ] && return
RETURN_page_description=`cat $GLOBAL_descriptions_filename | grep -v '^#' |
awk 'BEGIN { seen_longerdesc = 0; seen_captions = 0; } \
{ \
if ($1 == "[longer" && $2 == "page") { seen_longdesc = 1; next; }
if (seen_longdesc != 1) { next; }
if ($1 == "[captions]") { seen_captions = 1; next; }
if (seen_captions == 1) { next; }
print;
}' | grep -v '^[ ]*$'`
RETURN_page_description=`echo "$RETURN_page_description" |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
}
get_image_caption_from_descriptions_file ()
{
local fn
fn="$*"
RETURN_image_caption=""
[ ! -f $GLOBAL_descriptions_filename ] && return
[ $GLOBAL_no_image_titles_or_descriptions -eq 1 ] && return
[ -z "$fn" ] && return
validate_descriptions_file
[ $GLOBAL_descriptions_file_validated -eq 0 ] && return
generated_name_to_source_name "$fn"
fn="$RETURN_source_name"
RETURN_image_caption=`\
egrep "^${fn}"' |^\[captions\]|^\[descriptions\]' \
$GLOBAL_descriptions_filename |
awk 'BEGIN { seen_captions = 0; seen_desc = 0; } \
{ \
if ($1 == "[captions]") { seen_captions = 1; next; }
if (seen_captions != 1) { next; }
if ($1 == "[descriptions]") { seen_desc = 1; next; }
if (seen_desc == 1) { next; }
print
}' | grep -v '^[ ]*$' | head -1`
RETURN_image_caption=`echo "$RETURN_image_caption" | sed "s/${fn}//" |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
}
get_image_description_from_descriptions_file ()
{
local fn
fn="$*"
RETURN_image_description=""
[ ! -f $GLOBAL_descriptions_filename ] && return
[ $GLOBAL_no_image_titles_or_descriptions -eq 1 ] && return
[ -z "$fn" ] && return
validate_descriptions_file
[ $GLOBAL_descriptions_file_validated -eq 0 ] && return
generated_name_to_source_name "$fn"
fn="$RETURN_source_name"
RETURN_image_description=`\
egrep "^${fn}"' |^\[captions\]|^\[descriptions\]' \
$GLOBAL_descriptions_filename |
awk 'BEGIN { seen_desc = 0; } \
{ \
if ($1 == "[descriptions]") { seen_desc = 1; next; }
if (seen_desc != 1) { next; }
print
}' | grep -v '^[ ]*$' | head -1`
RETURN_image_description=`echo "$RETURN_image_description" |
sed "s/${fn}//" |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
}
# Return the filenames in the [captions] section, in the order they
# appear in the file.
get_caption_filenames_from_descriptions_file ()
{
RETURN_captions_tmpfile=""
[ ! -f $GLOBAL_descriptions_filename ] && return
validate_descriptions_file
[ $GLOBAL_descriptions_file_validated -eq 0 ] && return
make_tmpfile captions
RETURN_captions_tmpfile="$RETURN_tmpfile"
cat $GLOBAL_descriptions_filename |
sed '1,/^\[captions\]/d' |
sed '/^\[descriptions\]/,$d' |
grep -v '^[ ]*$' |
sed 's,^\(.*\)\.\([jgp][pin][gfg]\)[ ].*,\1.\2,' \
>> $RETURN_captions_tmpfile
}
## The functions that the rest of the script will use:
get_image_caption ()
{
local fn
fn="$*"
get_image_caption_from_descriptions_file "$fn"
if [ -n "$RETURN_image_caption" ]
then
RETURN_caption="$RETURN_image_caption"
RETURN_caption_was_from="descriptions-file"
RETURN_caption_inline=`echo "$RETURN_caption" |
sed -e 's, *<[Bb][Rr]> *, ,g' -e 's, *<[Bb][Rr] */> *, ,g'`
else
RETURN_caption=`echo "$fn" |
sed -e 's,-[trl]\.[jpgpnggif]*$,,' \
-e 's,\.[jpgpnggif]*$,,' \
-e 's,-, ,g' -e 's,_, ,g'`
RETURN_caption_inline="$RETURN_caption"
RETURN_caption_was_from="filename"
fi
}
get_image_caption_for_main_index ()
{
local fn
fn="$*"
get_image_caption "$fn"
[ "$RETURN_caption_was_from" = "descriptions-file" ] && return
[ $GLOBAL_use_timestamps_as_captions -eq 0 ] && return
if [ $GLOBAL_heuristic_filenames_are_digicam_boring -eq 1 ]
then
get_image_timestamp_from_dates_file "$fn"
if [ $GLOBAL_heuristic_days_are_identical -eq 0 -a -n "$RETURN_date" ]
then
iso8601_format_datestr_to_human "$RETURN_date"
if [ -n "$RETURN_human_date" ]
then
RETURN_caption="$RETURN_human_date"
return
fi
fi
if [ -n "$RETURN_time" ]
then
RETURN_caption="$RETURN_time"
return
fi
fi
}
is_this_a_boring_filename ()
{
local fn t
generated_name_to_source_name "$*"
fn="$RETURN_source_name"
RETURN_is_boring=0
[ $GLOBAL_heuristic_filenames_are_digicam_boring -eq 0 ] && return
t=`echo "$fn" | sed 's,[ ]*[0-9]*[ ]*,,g'`
if [ -n "$t" -a -n "$GLOBAL_heuristic_filename_pattern" -a \
"$t" = "$GLOBAL_heuristic_filename_pattern" ]
then
RETURN_is_boring=1
fi
}
get_image_description ()
{
get_image_description_from_descriptions_file "$*"
}
get_directory_title ()
{
local t
get_short_page_title_from_descriptions_file
if [ -n "$RETURN_short_page_title" ]
then
RETURN_directory_title="$RETURN_short_page_title"
RETURN_directory_title_inline=`echo "$RETURN_short_page_title" |
sed -e 's, *<[Bb][Rr]> *, ,g' -e 's, *<[Bb][Rr] */> *, ,g'`
RETURN_directory_title_is_from_user=1
else
t=`pwd`
RETURN_directory_title=`basename "$t"`
RETURN_directory_title_inline="$RETURN_directory_title"
RETURN_directory_title_is_from_user=0
fi
}
get_directory_description ()
{
get_page_description_from_descriptions_file
RETURN_directory_description="$RETURN_page_description"
}
#########################################################
#### dates.txt support
#########################################################
create_dates_file ()
{
local fn
if [ -f $GLOBAL_dates_filename ]
then
update_dates_file
return
fi
touch $GLOBAL_dates_filename
make_file_world_readable $GLOBAL_dates_filename
cat > $GLOBAL_dates_filename << __EOF__
# This is a one-time generated file (but updated whenever new images are added)
# which records the timestamps of images for various purposes. You can modify
# any entry if you wish--makethumbs will not regenerate a timestamp unless
# this file is completely removed or an image's entry in this file is removed.
# Each line has three fields -- FILENAME | DATE | TIME .
# DATE should be YYYY-MM-DD, but need not be.
# TIME should be HH:MM, but need not be.
__EOF__
add_cleanup $GLOBAL_dates_filename
progress_update_start_creating_dates
while read fn
do
get_image_time_date "$fn"
echo "${fn}|${RETURN_date}|${RETURN_time}" >> $GLOBAL_dates_filename
progress_update_created_date
done < $GLOBAL_image_list_tmpfile
remove_cleanup "$GLOBAL_dates_filename"
make_file_world_readable "$GLOBAL_dates_filename"
progress_update_done_creating_dates
}
update_dates_file ()
{
local fn updated
[ ! -f $GLOBAL_dates_filename ] && return
updated=0
progress_update_start_updating_dates
while read fn
do
if grep "^${fn}|.*|.*" $GLOBAL_dates_filename >/dev/null 2>&1
then
continue
fi
get_image_time_date "$fn"
echo "${fn}|${RETURN_date}|${RETURN_time}" >> $GLOBAL_dates_filename
updated=1
done < $GLOBAL_image_list_tmpfile
[ $updated -eq 1 ] && progress_update_done_updating_dates
}
get_image_timestamp_from_dates_file ()
{
local fn l
RETURN_timestamp=""
RETURN_date=""
RETURN_time=""
generated_name_to_source_name "$*"
fn="$RETURN_source_name"
[ ! -f $GLOBAL_dates_filename ] && return
l=`grep "^${fn}|.*|.*$" $GLOBAL_dates_filename 2>/dev/null | head -1`
if [ -n "$l" ]
then
if [ `echo "$l" | awk -F\| '{print NF}'` -eq 3 ]
then
RETURN_date=`echo "$l" | awk -F\| '{print $2}' |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
RETURN_time=`echo "$l" | awk -F\| '{print $3}'|
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
if [ -n "$RETURN_time" -a -n "$RETURN_date" ]
then
RETURN_timestamp="$RETURN_date $RETURN_time"
else
RETURN_timestamp="$RETURN_date$RETURN_time"
fi
fi
fi
}
# Set up some global variables for the index.html image captioning.
# If the user hasn't set a caption by hand, and the filename looks
# uninteresting (e.g. it's a digicam name like P8382010.jpg), then
#
# if we have multiple days in this directory, let's use the day name
# for the caption.
#
# if all images are from the same day, then let's use the time.
#
# This function sets up the necessary state to do something intelligent
# at caption emitting time.
analyze_filenames_and_dates ()
{
local t empty_count same_day_count count boring_pattern
GLOBAL_total_image_count=`cat "$GLOBAL_image_list_tmpfile" | wc -l |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
[ $GLOBAL_total_image_count -eq 0 ] && return
t=`cat "$GLOBAL_image_list_tmpfile" | grep '[0-9][0-9][0-9]' |
sed -e 's,^P[0-9A-Ca-c],P,' -e 's,[0-9],,g' |
sort | uniq -c | sort -rn | head -1 |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
# No boring digicam-style filenames in this dir?
if [ -z "$t" ]
then
return
fi
# More than 70% of the filenames are identical sans numbers? Probably
# from a digicam or some other uninteresting filename.
count=`echo "$t" | cut -d ' ' -f1 | sed 's,[^0-9],,g'`
boring_pattern=`echo "$t" | sed -e 's,^[ ]*[0-9]*[ ]*,,g'`
count=`expr "$count" \* 100`
if [ `expr "$count" / $GLOBAL_total_image_count` -ge 70 ]
then
GLOBAL_heuristic_filenames_are_digicam_boring=1
GLOBAL_heuristic_filename_pattern="$boring_pattern"
fi
empty_count=`cat "$GLOBAL_dates_filename" | egrep -v '^#|^$' |
awk -F\| '{if (NF == 3) {print $2}}' |
grep '^[ ]*$' | wc -l |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
same_day_count=`cat "$GLOBAL_dates_filename" | egrep -v '^#|^$' |
awk -F\| '{if (NF == 3) {print $2}}' |
grep -v '^[ ]*$' | sort | uniq -c | sort -rn | head -1 |
sed -e 's,^[ ]*\([0-9]*\).*,\1,'`
# More than 80% of the image's days are identical?
# Less than 20% of the image's times are missing? Note it.
if [ -n "$empty_count" -a -n "$same_day_count" ]
then
empty_count=`expr "$empty_count" \* 100`
same_day_count=`expr "$same_day_count" \* 100`
if [ `expr "$empty_count" / $GLOBAL_total_image_count` -le 20 -a \
`expr "$same_day_count" / $GLOBAL_total_image_count` -ge 80 ]
then
GLOBAL_heuristic_days_are_identical=1
fi
fi
empty_count=`cat "$GLOBAL_dates_filename" | egrep -v '^#|^$' |
awk -F\| '{if (NF == 3) {print $3}}' |
grep '^[ ]*$' | wc -l |
sed -e 's,^[ ]*,,' -e 's,[ ]*$,,'`
empty_count=`expr "$empty_count" \* 100`
if [ `expr "$empty_count" / $GLOBAL_total_image_count` -gt 80 ]
then
GLOBAL_heuristic_times_are_absent=0
fi
}
iso8601_format_datestr_to_human ()
{
local date year month day t
date="$*"
RETURN_human_date="$date"
if echo "$date" | egrep '^(19|20)[0-9][0-9]-[01][0-9]-[0-3][0-9]$' >/dev/null 2>&1
then
:
else
return
fi
year=`echo "$date" | sed 's,.*\([12][09][0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\).*,\1,'`
month=`echo "$date" | sed 's,.*\([12][09][0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\).*,\2,'`
day=`echo "$date" | sed 's,.*\([12][09][0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\).*,\3,'`
month=`echo "$month" | sed \
-e "s,^01\$,$GLOBAL_monthname_01_text," -e "s,^02\$,$GLOBAL_monthname_02_text," \
-e "s,^03\$,$GLOBAL_monthname_03_text," -e "s,^04\$,$GLOBAL_monthname_04_text," \
-e "s,^05\$,$GLOBAL_monthname_05_text," -e "s,^06\$,$GLOBAL_monthname_06_text," \
-e "s,^07\$,$GLOBAL_monthname_07_text," -e "s,^08\$,$GLOBAL_monthname_08_text," \
-e "s,^09\$,$GLOBAL_monthname_09_text," -e "s,^10\$,$GLOBAL_monthname_10_text," \
-e "s,^11\$,$GLOBAL_monthname_11_text," -e "s,^12\$,$GLOBAL_monthname_12_text,"`
month=`echo "$month" | sed -e 's, ,\ ,g'`
day=`echo "$day" | sed 's,^0,,'`
if [ -n "$year" -a -n "$month" -a -n "$day" ]
then
t=`echo "$GLOBAL_date_formatting_text" |
sed -e "s,@MONTH@,${month}," -e "s,@DAY@,${day}," -e "s,@YEAR@,${year},"`
RETURN_human_date=`echo "$t" | sed 's, ,\ ,g'`
fi
}
#########################################################
#### Get EXIF et al information and add it to slideshow pages
#########################################################
# This function should add the photo information using a variety
# of programs to recover the EXIF data embedded in the JPEG.
#
# The order of precedence is currently
# INFO.TXT -> jhead -> metacam -> dump-exif
#
# But I think metacam is seing the most active development and it will
# probably come before jhead in the future.
print_image_exif_info ()
{
local fn html
fn="$*"
image_name_to_html_name "$fn"
html="$RETURN_html_name"
generated_name_to_source_name "$fn"
fn="$RETURN_source_name"
print_libexif_info "$fn"
[ $RETURN_printed_something -eq 1 ] && return
print_coolpix_info_txt "$fn"
[ $RETURN_printed_something -eq 1 ] && return
print_jhead_info "$fn"
[ $RETURN_printed_something -eq 1 ] && return
print_metacam_info "$fn"
[ $RETURN_printed_something -eq 1 ] && return
print_gphoto_exifdump_info "$fn"
[ $RETURN_printed_something -eq 1 ] && return
print_dumpexif_info "$fn"
[ $RETURN_printed_something -eq 1 ] && return
}
print_coolpix_info_txt ()
{
local fn
RETURN_printed_something=0
fn="$*"
get_coolpix_info_txt "$fn"
if [ -n "$RETURN_info_txt" ]
then
echo ""
echo ""
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
print_jhead_info ()
{
local fn
RETURN_printed_something=0
fn="$*"
[ $GLOBAL_jhead_is_present -eq 0 ] && return
if jhead "$fn" 2>&1 | grep -i 'Exposure time *:' >/dev/null
then
echo ""
echo ""
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
# "exif" is from the libexif project:
# http://www.sourceforge.net/projects/libexif
# It's comprehensive but not so pretty without a little reformatting
# Output looks like this in rev 0.4:
#--------------------+-----------------------------------------------------------
#Tag |Value
#--------------------+-----------------------------------------------------------
#Image Description |
#Manufacturer |NIKON CORPORATION
#Model |NIKON D100
#x-Resolution |300/1
#y-Resolution |300/1
#Resolution Unit |Inch
#Software |Ver.0.32
#Date and Time |2002:05:16 00:19:17
#YCbCr Positioning |co-sited
# [...]
# etc
print_libexif_info ()
{
local fn
RETURN_printed_something=0
fn="$*"
[ $GLOBAL_exif_is_present -eq 0 ] && return
if exif "$fn" 2>&1 | grep -i 'Image Description' > /dev/null
then
echo ""
echo ""
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
print_metacam_info ()
{
local fn
RETURN_printed_something=0
fn="$*"
[ $GLOBAL_metacam_is_present -eq 0 ] && return
if metacam "$fn" 2>&1 | grep -i 'Focal Length: ' >/dev/null
then
echo ""
echo ""
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
print_gphoto_exifdump_info ()
{
local fn
fn="$*"
RETURN_printed_something=0
[ $GLOBAL_gphotoexifdump_is_present -eq 0 ] && return
get_gphoto_exifdump_info "$fn"
if [ -n "$RETURN_gphoto_info" ]
then
echo ""
echo ""
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
# Convert this:
# Tag 0x10F Make = 'SONY'
# Tag 0x132 DateTime = '2001:10:31 13:45:19'
# Tag 0x9205 MaxApertureValue = 28/10=2.8
# Into this:
# Camera make : SONY
# Date/Time : 2001:10:31 13:45:19
# Max Aperture : f/2.8
# gphoto 0.4.3's gphoto-exifdump outputs like this, but it's such a useless
# format that I'd suspect they'll change it eventually... I'll need to keep
# an eye on that or makethumbs could start inserting garbage into peoples
# image galleries.
get_gphoto_exifdump_info ()
{
local fn t
RETURN_gphoto_info=""
fn="$*"
[ $GLOBAL_gphotoexifdump_is_present -eq 0 ] && return
t=`gphoto-exifdump "$fn" 2>/dev/null |
egrep 'Make|Model|DateTime|ExposureTime|FNumber|ISOSpeedRatings|MaxApertureValue|Flash|FocalLength' |
egrep -v 'MakerNote|FlashPixVersion' | sed 's,^Tag 0x[0-9a-fA-F]* *,,' |
sed -e 's,DateTimeOriginal,DateTime,' -e 's,DateTimeDigitized,DateTime,' |
sort | uniq | sed -e 's,^[ ]*,,' -e 's,[ ]*$,,' |
sed -e "s,.*Make.*'\(.*\)'\$,a Camera make : \1," \
-e "s,.*Model.*'\(.*\)'\$,b Camera model : \1," \
-e "s,.*DateTime.*'\(.*\)'\$,c Date/Time : \1," \
-e 's,.*Flash = 0.*,d Flash : No,' \
-e 's,.*Flash = 1.*,d Flash : Yes,' \
-e 's,.*ExposureTime.*= *\([0-9.]*\)$,f Exposure time: \1s,' \
-e 's,.*FNumber.*= *\([0-9.]*\)$,g Aperture : f/\1,' \
-e 's,.*ISOSpeedRatings = *\([0-9.]*\)$,h ISO equiv. : \1,' \
-e 's,.*MaxApertureValue.*= *\([0-9.]*\)$,i Max Aperture : f/\1,' \
-e 's,.*FocalLength.*= *\([0-9.]*\)$,e Focal Length : \1mm,' |
grep -v '^Tag' | sort | cut -d ' ' -f 2-`
if [ -n "$t" ]
then
RETURN_gphoto_info="$t"
fi
}
print_dumpexif_info ()
{
local fn
RETURN_printed_something=0
fn="$*"
[ $GLOBAL_dumpexif_is_present -eq 0 ] && return
if dump-exif "$fn" 2>&1 | grep -i 'ExposureTime:' >/dev/null
then
if [ $GLOBAL_show_image_info -eq 1 ]
then
echo ""
else
echo ""
fi
echo ""
RETURN_printed_something=1
fi
}
get_coolpix_info_txt ()
{
local filename lineno
filename="$*"
RETURN_info_txt=""
[ ! -f INFO.TXT ] && return
generated_name_to_source_name "$filename"
filename="$RETURN_source_name"
if cat INFO.TXT | tr -d '\r' | grep -i "^$filename\$" >/dev/null 2>&1
then
:
else
return
fi
lineno=`cat -n INFO.TXT | tr -d '\r' |
grep -i "^[ ]*[0-9]*[ ]*$filename\$" | cut -f1 |
sed 's,[^0-9],,g'`
RETURN_info_txt=`cat INFO.TXT |
tr -d '\r' | sed "1,${lineno}d" |
awk '{if (NF == 0) { exit } print " " $0;}' |
grep -v '^[ ]*$'`
}
#########################################################
#### Try to get image time/date data via a variety of means
#########################################################
get_image_time_date ()
{
local fn
generated_name_to_source_name "$*"
fn="$RETURN_source_name"
RETURN_time_date=""
RETURN_date=""
RETURN_time=""
get_time_date_via_metacam "$fn"
if [ -n "$RETURN_metacam_time_date" ]
then
RETURN_time_date="$RETURN_metacam_time_date"
RETURN_date="$RETURN_metacam_date"
RETURN_time="$RETURN_metacam_time"
return
fi
get_time_date_via_exiftools "$fn"
if [ -n "$RETURN_exiftools_time_date" ]
then
RETURN_time_date="$RETURN_exiftools_time_date"
RETURN_date="$RETURN_exiftools_date"
RETURN_time="$RETURN_exiftools_time"
return
fi
get_coolpix_time_date "$fn"
if [ -n "$RETURN_coolpix_time_date" ]
then
RETURN_time_date="$RETURN_coolpix_time_date"
RETURN_date="$RETURN_coolpix_date"
RETURN_time="$RETURN_coolpix_time"
return
fi
get_chillcam_time_date "$fn"
if [ -n "$RETURN_chillcam_time_date" ]
then
RETURN_time_date="$RETURN_chillcam_time_date"
RETURN_date="$RETURN_chillcam_date"
RETURN_time="$RETURN_chillcam_time"
return
fi
get_webcam32_time_date "$fn"
if [ -n "$RETURN_webcam32_time_date" ]
then
RETURN_time_date="$RETURN_webcam32_time_date"
RETURN_date="$RETURN_webcam32_date"
RETURN_time="$RETURN_webcam32_time"
return
fi
get_time_date_via_jhead "$fn"
if [ -n "$RETURN_jhead_time_date" ]
then
RETURN_time_date="$RETURN_jhead_time_date"
RETURN_date="$RETURN_jhead_date"
RETURN_time="$RETURN_jhead_time"
return
fi
get_time_date_via_strings "$fn"
if [ -n "$RETURN_strings_time_date" ]
then
RETURN_time_date="$RETURN_strings_time_date"
RETURN_date="$RETURN_strings_date"
RETURN_time="$RETURN_strings_time"
return
fi
get_date_via_preferred_filename "$fn"
if [ -n "$RETURN_preferred_filename_time_date" ]
then
RETURN_time_date="$RETURN_preferred_filename_time_date"
RETURN_date="$RETURN_preferred_filename_date"
RETURN_time="$RETURN_preferred_filename_time"
return
fi
get_date_via_filename_usa_specific "$fn"
if [ -n "$RETURN_usa_time_date" ]
then
RETURN_time_date="$RETURN_usa_time_date"
RETURN_date="$RETURN_usa_date"
RETURN_time="$RETURN_usa_time"
return
fi
guess_date_via_directory_name
if [ -n "$RETURN_guessed_date" ]
then
RETURN_time_date="$RETURN_guessed_time_date"
RETURN_date="$RETURN_guessed_date"
RETURN_time="$RETURN_guessed_time"
return
fi
get_date_via_filename_reluctantly "$fn"
if [ -n "$RETURN_reluctant_time_date" ]
then
RETURN_time_date="$RETURN_reluctant_time_date"
RETURN_date="$RETURN_reluctant_date"
RETURN_time="$RETURN_reluctant_time"
return
fi
}
# Get one of these lines from metacam output :
#
# Image Creation Date: 2001:12:23 13:39:48
# Image Capture Date: 2001:12:23 13:39:48
# Image Digitized Date: 2001:12:23 13:39:48
#
# All three may be present, or only one may be present.
get_time_date_via_metacam ()
{
local fn td
[ $GLOBAL_metacam_is_present -eq 0 ] && return
fn="$*"
RETURN_metacam_time_date=""
RETURN_metacam_date=""
RETURN_metacam_time=""
td=`metacam "$fn" 2>/dev/null |
egrep -i 'Image (Creation|Capture|Digitized) Date' |
grep -v '0000:00:00 00:00' |
head -1 | awk '{print $(NF-1) " " $NF}' | sed -e 's,[^0-9: ],,g' \
-e 's,\([12][0-9][0-9][0-9]\):\([01][0-9]\):\([0-3][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,\1-\2-\3 \4:\5,'`
if [ -n "$td" ]
then
RETURN_metacam_time_date="$td"
RETURN_metacam_date=`echo "$td" | awk '{print $1}'`
RETURN_metacam_time=`echo "$td" | awk '{print $2}'`
fi
}
# Get this line from dump-exif (a part of exif-tools) output :
#
# DateTimeOriginal: 2000:04:19 15:01:56
get_time_date_via_exiftools ()
{
local fn td
[ $GLOBAL_dumpexif_is_present -eq 0 ] && return
fn="$*"
RETURN_exiftools_time_date=""
RETURN_exiftools_date=""
RETURN_exiftools_time=""
td=`dump-exif "$fn" 2>/dev/null |
egrep -i 'DateTimeOriginal' |
grep -v '0000:00:00 00:00' |
head -1 | awk '{print $(NF-1) " " $NF}' | sed -e 's,[^0-9: ],,g' \
-e 's,\([12][0-9][0-9][0-9]\):\([01][0-9]\):\([0-3][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,\1-\2-\3 \4:\5,'`
if [ -n "$td" ]
then
RETURN_exiftools_time_date="$td"
RETURN_exiftools_date=`echo "$td" | awk '{print $1}'`
RETURN_exiftools_time=`echo "$td" | awk '{print $2}'`
fi
}
# Get this line from jhead output :
#
# Date/Time : 2000:04:30 16:26:56
get_time_date_via_jhead ()
{
local fn td
[ $GLOBAL_jhead_is_present -eq 0 ] && return
fn="$*"
RETURN_jhead_time_date=""
RETURN_jhead_date=""
RETURN_jhead_time=""
td=`jhead "$fn" 2>/dev/null |
egrep -i 'Date/Time *:' |
grep -v '0000:00:00 00:00' |
head -1 | awk '{print $(NF-1) " " $NF}' | sed -e 's,[^0-9: ],,g' \
-e 's,\([12][0-9][0-9][0-9]\):\([01][0-9]\):\([0-3][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,\1-\2-\3 \4:\5,'`
if [ -n "$td" ]
then
RETURN_jhead_time_date="$td"
RETURN_jhead_date=`echo "$td" | awk '{print $1}'`
RETURN_jhead_time=`echo "$td" | awk '{print $2}'`
fi
}
get_coolpix_time_date ()
{
local fn timestamp
fn="$*"
RETURN_coolpix_time_date=""
RETURN_coolpix_date=""
RETURN_coolpix_time=""
get_coolpix_info_txt "$fn"
if [ -n "$RETURN_info_txt" ]
then
timestamp=`echo "$RETURN_info_txt" | grep '^[ ]*DATE' |
awk '{print $3 " " $4}' | sed 's,\.,-,g' | sed 's,[^0-9 :-],,g'`
if [ -n "$timestamp" ]
then
RETURN_coolpix_time_date="$timestamp"
RETURN_coolpix_date=`echo "$timestamp" | awk '{print $1}'`
RETURN_coolpix_time=`echo "$timestamp" | awk '{print $2}'`
return
fi
fi
}
# See if we can find the date string with good old strings(1).
# The date is in there in the form of 2001:11:19 19:25:09
get_time_date_via_strings ()
{
local fn="$*"
local td
RETURN_strings_time_date=""
RETURN_strings_date=""
RETURN_strings_time=""
td=`strings "$fn" 2>/dev/null |
grep -v '0000:00:00 00:00' |
egrep '(19|20)[0-9][0-9]:(0[1-9]|1[0-2]):[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]' |
head -1 | awk '{print $(NF-1) " " $NF}' |
sed -e 's,[^0-9: ],,g' \
-e 's,\([12][0-9][0-9][0-9]\):\([01][0-9]\):\([0-3][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,\1-\2-\3 \4:\5,'`
if [ -n "$td" ]
then
RETURN_strings_time_date="$td"
RETURN_strings_date=`echo "$td" | awk '{print $1}'`
RETURN_strings_time=`echo "$td" | awk '{print $2}'`
fi
}
# Olympus cameras (C2000Z, C2020Z, C3030Z) have photo filenames in the form of
# P<4-DIGIT-SEQ-NO>.jpg
# If a person hasn't set the time/date in the camera, MONTH-DIGIT (a hex
# dgit) and DAY are 1, giving you a name of the form P101xxxx.jpg, which
# should be ignored. Yes, this means that photos taken on New Year's Day
# will not be recognized.
get_olympus_filename_date ()
{
local fn="$*"
local month day
RETURN_olympus_time_date=""
RETURN_olympus_date=""
RETURN_olympus_time=""
if echo "$fn" | egrep '^P[1-9A-Ca-c][0-3][0-9][0-9][0-9][0-9][0-9].jpg$' >/dev/null 2>&1
then
month=`echo "$fn" | sed -e 's,^P\(.\).*,\1,' \
-e "s,^1\$,$GLOBAL_monthname_01_text," -e "s,^2\$,$GLOBAL_monthname_02_text," \
-e "s,^3\$,$GLOBAL_monthname_03_text," -e "s,^4\$,$GLOBAL_monthname_04_text," \
-e "s,^5\$,$GLOBAL_monthname_05_text," -e "s,^6\$,$GLOBAL_monthname_06_text," \
-e "s,^7\$,$GLOBAL_monthname_07_text," -e "s,^8\$,$GLOBAL_monthname_08_text," \
-e "s,^9\$,$GLOBAL_monthname_09_text," -e "s,^[Aa]\$,$GLOBAL_monthname_10_text," \
-e "s,^[Bb]\$,$GLOBAL_monthname_11_text," -e "s,^[Cc]\$,$GLOBAL_monthname_12_text,"`
day=`echo "$fn" | sed -e 's,^P.\([0-3][0-9]\).*,\1,' -e 's,^0,,'`
if [ -n "$month" -a -n "$day" ]
then
[ "$month" = January -a "$day" = "1" ] && return
[ "$month" = 0 -a "$day" = "0" ] && return
RETURN_olympus_time_date="$month $day"
RETURN_olympus_date="$month $day"
RETURN_olympus_time=""
fi
fi
}
# This only tries to recognize dates in some form of YYYY-MM-DD.
# Americans might expect MM-DD-YYYY to work, or MM-DD-YY, but
# it's not globally unambiguous, so those Americans may now learn
# the joys of ISO 8601. Unless I feel like adding support for
# the US formats some day. Don't hold your breath.
guess_date_via_directory_name ()
{
local t
[ $GLOBAL_already_failed_guessing_date_from_dir -eq 1 ] && return
t=`pwd`
t=`basename "$t"`
RETURN_guessed_time_date=""
RETURN_guessed_date=""
RETURN_guessed_time=""
# Don't re-do work we've aready done during this makethumbs run.
if [ -n "$GLOBAL_static_var_guessed_date_from_dirname" ]
then
RETURN_guessed_time_date="$GLOBAL_static_var_guessed_date_from_dirname"
RETURN_guessed_date="$GLOBAL_static_var_guessed_date_from_dirname"
RETURN_guessed_time=""
return
fi
iso8601_date_decoder "$t"
if [ -n "$RETURN_iso8601_time_date" ]
then
RETURN_guessed_time_date="$RETURN_iso8601_time_date"
RETURN_guessed_date="$RETURN_iso8601_date"
RETURN_guessed_time="$RETURN_iso8601_time"
GLOBAL_static_var_guessed_date_from_dirname="$RETURN_iso8601_time_date"
else
GLOBAL_already_failed_guessing_date_from_dir=1
fi
}
get_date_via_preferred_filename ()
{
local fn
fn="$*"
RETURN_preferred_filename_time_date=""
RETURN_preferred_filename_date=""
RETURN_preferred_filename_time=""
iso8601_date_decoder "$fn"
if [ -n "$RETURN_iso8601_time_date" ]
then
RETURN_preferred_filename_time_date="$RETURN_iso8601_time_date"
RETURN_preferred_filename_date="$RETURN_iso8601_date"
RETURN_preferred_filename_time="$RETURN_iso8601_time"
return
fi
}
get_date_via_filename_usa_specific ()
{
local fn
fn="$*"
RETURN_usa_time_date=""
RETURN_usa_date=""
RETURN_usa_time=""
[ $GLOBAL_usa_specific_date_format_checks -eq 0 ] && return
try_ians_filename_format "$fn"
if [ -n "$RETURN_ians_date" ]
then
RETURN_usa_time_date="$RETURN_ians_time_date"
RETURN_usa_date="$RETURN_ians_date"
RETURN_usa_time="$RETURN_ians_time"
return
fi
try_erics_filename_format "$fn"
if [ -n "$RETURN_erics_date" ]
then
RETURN_usa_time_date="$RETURN_erics_time_date"
RETURN_usa_date="$RETURN_erics_date"
RETURN_usa_time="$RETURN_erics_time"
return
fi
}
get_date_via_filename_reluctantly ()
{
local fn
fn="$*"
RETURN_reluctant_time_date=""
RETURN_reluctant_date=""
RETURN_reluctant_time=""
get_olympus_filename_date "$fn"
if [ -n "$RETURN_olympus_date" ]
then
RETURN_reluctant_time_date="$RETURN_olympus_time_date"
RETURN_reluctant_date="$RETURN_olympus_date"
RETURN_reluctant_time="$RETURN_olympus_time"
return
fi
}
iso8601_date_decoder ()
{
local name canonical_fmt t
local fmt1 fmt2 fmt3 fmt4 fmt5 fmt6 fmt7 fmt8
name="$*"
RETURN_iso8601_time_date=""
RETURN_iso8601_time=""
RETURN_iso8601_date=""
canonical_fmt="[12][09][0-9][0-9]-[012][0-9]-[0-3][0-9]"
fmt1="$canonical_fmt"
fmt2="[12][09][0-9][0-9]-[012]?[0-9]-[0-3]?[0-9]"
fmt3="[12][09][0-9][0-9]_[012][0-9]_[0-3][0-9]"
fmt4="[12][09][0-9][0-9]_[012]?[0-9]_[0-3]?[0-9]"
fmt5="[12][09][0-9][0-9]\.[012][0-9]\.[0-3][0-9]"
fmt6="[12][09][0-9][0-9]\.[012]?[0-9]\.[0-3]?[0-9]"
fmt7="[12][09][0-9][0-9] [012]?[0-9] [0-3]?[0-9]"
fmt8="[12][09][0-9][0-9][012][0-9][0-3][0-9]"
for exp in "$fmt1" "$fmt2" "$fmt3" "$fmt4" "$fmt5" "$fmt6" "$fmt7" "$fmt8"
do
if echo "$name" | egrep "$exp" >/dev/null 2>&1
then
# Old fashioned awk's won't support gensub(), so use perl
# as a backup. I hate to do it, but gsub won't do what
# I need as near as I can tell...
if [ $GLOBAL_date_parser_program = "awk" ]
then
t=`echo "$name" | sed "s/.*\(${exp}\).*/\1/" |
$AWK '{\
datepat="^.*\([12][09][0-9][0-9]\)[^0-9]*\([01]?[0-9]\)[^0-9]*\([0-3]?[0-9]\)[^0-9]?.*$"
year = gensub (datepat, "\\\\1", "g", $0);
month = gensub (datepat, "\\\\2", "g", $0);
day = gensub (datepat, "\\\\3", "g", $0);
printf ("%s-%02d-%02d", year, month, day);
}'`
else
t=`echo "$name" | sed "s/.*\(${exp}\).*/\1/" |
perl -ne \
'if (/^.*([12][09]\d\d)[^\d]*([01]?\d)[^\d]*([0-3]?[\d])[^\d]?.*$/)
{printf ("%s-%02d-%02d\n", $1, $2, $3); }'`
fi
if echo "$t" | egrep "$canonical_fmt" >/dev/null 2>&1
then
RETURN_iso8601_time_date="$t"
RETURN_iso8601_date="$t"
RETURN_iso8601_time=""
return
fi
fi
done
}
# ChillCAM is a web cam program that embeds the time/date in the comment field.
# www.chillcam.com
# format is "MM/DD/YYYY HH:MM:SS"
get_chillcam_time_date ()
{
local fn t
fn="$*"
t=""
RETURN_chillcam_time_date=""
RETURN_chillcam_date=""
RETURN_chillcam_time=""
if [ $GLOBAL_rdjpgcom_is_present -eq 0 -a \
$GLOBAL_jhead_is_present -eq 0 -a \
$GLOBAL_jpegtopnm_is_present -eq 0 ]
then
return
fi
if [ $GLOBAL_rdjpgcom_is_present -eq 1 ]
then
t=`rdjpgcom "$fn" 2>/dev/null | grep -i chillcam | head -1`
fi
if [ -z "$t" -a $GLOBAL_jhead_is_present -eq 1 ]
then
t=`jhead "$fn" 2>/dev/null | grep -i chillcam | head -1`
fi
if [ -z "$t" -a $GLOBAL_jpegtopnm_is_present -eq 1 ]
then
t=`jpegtopnm -comment "$fn" 2>&1 >/dev/null | grep -i chillcam | head -1`
fi
[ -z "$t" ] && return
t=`echo "$t" | awk '{print $(NF-1) " " $NF}' |
sed -e 's,[^0-9/: ],,g' |
grep '[01][0-9]/[0-3][0-9]/[12][0-9][0-9][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]' |
sed -e 's,\([01][0-9]\)/\([0-3][0-9]\)/\([12][0-9][0-9][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,\3-\1-\2 \4:\5,'`
[ -z "$t" ] && return
RETURN_chillcam_time_date="$t"
RETURN_chillcam_date=`echo "$t" | awk '{print $1}'`
RETURN_chillcam_time=`echo "$t" | awk '{print $2}'`
}
# Webcam32 is some webcam snapshot program that puts the time/date in a
# jpeg comment. www.webcam32.com.
# format is "MM/DD/YY HH:MM:SS" in typical USA fashion.
get_webcam32_time_date ()
{
local fn t
fn="$*"
t=""
RETURN_chillcam_time_date=""
RETURN_chillcam_date=""
RETURN_chillcam_time=""
if [ $GLOBAL_rdjpgcom_is_present -eq 0 -a \
$GLOBAL_jhead_is_present -eq 0 -a \
$GLOBAL_jpegtopnm_is_present -eq 0 ]
then
return
fi
if [ $GLOBAL_rdjpgcom_is_present -eq 1 ]
then
t=`rdjpgcom "$fn" 2>/dev/null | grep -i webcam32 | head -1`
fi
if [ -z "$t" -a $GLOBAL_jhead_is_present -eq 1 ]
then
t=`jhead "$fn" 2>/dev/null | grep -i webcam32 | head -1`
fi
if [ -z "$t" -a $GLOBAL_jpegtopnm_is_present -eq 1 ]
then
t=`jpegtopnm -comment "$fn" 2>&1 >/dev/null | grep -i webcam32 | head -1`
fi
[ -z "$t" ] && return
t=`echo "$t" | awk '{print $(NF-1) " " $NF}' |
sed -e 's,[^0-9/: ],,g' |
grep '[01][0-9]/[0-3][0-9]/[0-9][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]' |
sed -e 's,\([01][0-9]\)/\([0-3][0-9]\)/\([0-8][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,20\3-\1-\2 \4:\5,' \
-e 's,\([01][0-9]\)/\([0-3][0-9]\)/\([9][0-9]\) \([012][0-9]\):\([0-6][0-9]\).*,19\3-\1-\2 \4:\5,'`
[ -z "$t" ] && return
RETURN_webcam32_time_date="$t"
RETURN_webcam32_date=`echo "$t" | awk '{print $1}'`
RETURN_webcam32_time=`echo "$t" | awk '{print $2}'`
}
#### USA SPECIFIC DATE FORMAT CHECKS
## Dates can be ordered by month/day/year or they can be ordered by
## day/month/year, depending on which part of the world you live in.
## I'd rather everyone use an ISO8601 unambiguous date, but they don't.
## The following timestamp checks all assume a US (MM/DD/year) format
## date string, and they can all be disabled by setting
## usa_specific_date_format_checks to zero in your .makethumbsrc file.
# Ian Lance Taylor has his images named MMDDYY-n+.jpg.
# (where 'n' is the sequence number on that day).
# I cheat and assume that years "00" - "29" are 2000-2029 and years
# "70-99" are 1970-1999.
try_ians_filename_format ()
{
local fn t
fn="$*"
RETURN_ians_time_date=""
RETURN_ians_date=""
RETURN_ians_time=""
[ $GLOBAL_usa_specific_date_format_checks -eq 0 ] && return
if echo "$fn" | egrep '^(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-27-9][0-9]-[1-9][0-9]*\.(jpg|gif|png)$' >/dev/null 2>&1
then
t=`echo "$fn" |
sed -e 's|^\([01][0-9]\)\([0-3][0-9]\)\([0-2][0-9]\).*|20\3-\1-\2|' \
-e 's|^\([01][0-9]\)\([0-3][0-9]\)\([7-9][0-9]\).*|19\3-\1-\2|'`
if [ -n "$t" ]
then
if echo "$t" | egrep '^(19|20)[0-9][0-9]-[01][0-9]-[0-3][0-9]$' >/dev/null 2>&1
then
RETURN_ians_time_date="$t"
RETURN_ians_date="$t"
RETURN_ians_time=""
return
fi
fi
fi
}
# Eric Perlman names his files with the date encoded in the filename
# in a format like "foo_(3-2-2002).jpg". (i.e. *MM-DD-YYYY* s.t. MM and DD
# can be single digit.)
try_erics_filename_format ()
{
local fn t month day year
fn="$*"
RETURN_erics_time_date=""
RETURN_erics_date=""
RETURN_erics_time=""
[ $GLOBAL_usa_specific_date_format_checks -eq 0 ] && return
if echo "$fn" | egrep '[(](0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])-(19|20)[0-9][0-9][)]' >/dev/null 2>&1
then
year=`echo "$fn" |
sed -e 's|.*[(]\([0-9]*\)-\([0-9]*\)-\([12][09][0-9][0-9]\)[)].*|\3|'`
month=`echo "$fn" |
sed -e 's|.*[(]\([0-9]*\)-\([0-9]*\)-\([12][09][0-9][0-9]\)[)].*|\1|'`
day=`echo "$fn" |
sed -e 's|.*[(]\([0-9]*\)-\([0-9]*\)-\([12][09][0-9][0-9]\)[)].*|\2|'`
t=`printf "%s-%02d-%02d" "$year" "$month" "$day" 2>/dev/null`
if [ -n "$t" ]
then
if echo "$t" | egrep '^(19|20)[0-9][0-9]-[01][0-9]-[0-3][0-9]$' >/dev/null 2>&1
then
RETURN_erics_time_date="$t"
RETURN_erics_date="$t"
RETURN_erics_time=""
return
fi
fi
fi
}
#########################################################
#### call to main
#########################################################
main ${1+"$@"}