# !/bin/bash
# copyright Philipp Salzgeber - www.salzgeber.at
#
# if no day is provided print out usage
if [ -z "$1" ]; then 
  echo "usage: $0 day [month] [year]"
  exit
else
  d=$1
fi
# if no parameter is provided for the month, use the current month
if [ -z "$2" ]; then
  m=$(date -u +"%m")
else
  m=`(printf "%02i" $2)`
fi
# if no parameter is provided for the year, use the current year
if [ -z "$3" ]; then
 y=$(date -u +"%Y") 
else
  y=$3
fi

# assemble the directory name
dirname=${y}${m}${d}
# create sub-directories for the cropped versions of the image
mkdir -p ${dirname}/right/
mkdir -p ${dirname}/left/
# loop through the hours of the day
for j in {0..23}
  do
  # prepend a leading zero to the hour
  hour=`(printf "%02i" $j)`
  # loop through the minutes of the hour
    for i in {0..59}    
       do
       # prepend a leading zero to the minute
       minute=`printf "%02i" $i`
       # assemble the filename
       filename=${y}${m}${d}${hour}${minute}
       # use wget do download the image
       wget http://extras.vodafone.is/trailers/fimmvorduhals/mx10-4-235-80/${y}/${m}/${d}/$hour/$minute.jpg -O ${dirname}/${filename}.jpg  
       # crop the right-hand side of the image in 16:9 aspect ratio
       convert -crop 1024x576+1025+0 ${dirname}/${filename}.jpg ${dirname}/right/right_${filename}.jpg
       # crop the left-hand side of the image in 16:9 aspect ratio
       convert -crop 1024x576+0+0 ${dirname}/${filename}.jpg ${dirname}/left/left_${filename}.jpg
       done   
  done


