#!/bin/sh
# Extract details of declared hero/document video from directives.
#   $1 must be the .*.HTML body source or some head portion of it.
#   $2 must be the name of the host .*.html body source for error messages.
# Video path returned is relative to the top of the www site,
# and does not contain any of [ '"=] so can be unquoted as HTML attr values.
if [ $# -lt 2 ]; then
    echo "Missing hero/video HTML input and source name." 1>&2
    exit 2
fi

# Returns on stdout the name of the hero image, else script exits non-zero.
# The hero image must be under img/ and non-zero-sized.
# No upper bounds on video size are enforced here.

# <!-- VIDEO ... --> tags relative to root of *static* site.
#
# Note: all videos should be under img/ for immutability/cacheability.

# File to read the input HTML file (directives) from.
INPUTHTML=$1

VIDEO=`sed < $INPUTHTML -n -e 's/^<!-- *VIDEO *\(img\/[^ =>"'\'']*\) *--> *$/\1/p'`
if [ "X" != "X$VIDEO" -a -f "$VIDEO" -a -s "$VIDEO" ]; then
    echo "$VIDEO"
    exit 0
fi

# Hero video not found.
#echo "Missing hero/thumbnail video for $2..." 1>&2
#exit 1

exit 1
