#! /bin/ksh # Disclaimer: ugly as fook but I just wanted to try how this could be done # in ksh. It's a database for my movie collection with fancy thumbnails # and codec information printed on the page. Now that you know how it looks, # go use another language. SQL="/usr/bin/sqlite3" DB="movie.db" echo 'Content-type: text/html' echo '' echo '' echo '' echo '' echo '' echo ' ' echo ' MovieDB' echo ' ' echo ' ' echo ' ' COUNT=$(${SQL} ${DB} 'SELECT COUNT(title) FROM movie') echo "

MovieDB (${COUNT} movies)

" # # Parse query string # SEARCH_TERM=${QUERY_STRING##search-term=} SEARCH_TERM=${SEARCH_TERM%%&*} SEARCH_TEXT=${QUERY_STRING##*search-text=} SEARCH_TEXT=${SEARCH_TEXT%%&*} SORT_TYPE=${QUERY_STRING##*sort-type=} SORT_TYPE=${SORT_TYPE%%&*} if [ -z ${SORT_TYPE} ]; then SORT_TYPE="title" fi SORT_ORDER=${QUERY_STRING##*sort-order=} SORT_ORDER=${SORT_ORDER%%&*} if [ -z ${SORT_ORDER} ]; then SORT_ORDER="ascending" fi QUERY='SELECT * FROM movie' if ! [ -z ${SEARCH_TEXT} ]; then QUERY=${QUERY}' WHERE title LIKE' case ${SEARCH_TERM} in contain) QUERY=${QUERY}" '%${SEARCH_TEXT}%'" ;; begins) QUERY=${QUERY}" '${SEARCH_TEXT}%'" ;; ends) QUERY=${QUERY}" '%${SEARCH_TEXT}'" ;; esac fi if ! [ -z ${SORT_TYPE} ]; then case ${SORT_TYPE} in title) QUERY=${QUERY}" ORDER BY title" ;; year) QUERY=${QUERY}" ORDER BY year" ;; esac if ! [ -z ${SORT_ORDER} ]; then case ${SORT_ORDER} in ascending) QUERY=${QUERY}" ASC" ;; descending) QUERY=${QUERY}" DESC" ;; esac fi fi # # Search bar # case ${SEARCH_TERM} in contain) SEL_CON="selected";; begins) SEL_BEG="selected";; ends) SEL_END="selected";; esac echo '
' echo ' ' echo ' ' echo " " echo ' ' case ${SORT_TYPE} in title) SORT_TITLE="selected";; year) SORT_YEAR="selected";; esac echo ' ' echo ' ' case ${SORT_ORDER} in ascending) SORT_ASC="selected";; descending) SORT_DESC="selected";; esac echo ' ' echo ' order.' echo ' ' echo '
' echo ' ' # # Movie list # (this is the really ugly part) # IFS=${IFS#??} for LINE in $(${SQL} ${DB} ${QUERY}); do PATH=${LINE%%|*} #echo "PATH=${PATH}
" TITLE=${LINE#*|} TITLE=${TITLE%%|*} #echo "TITLE=${TITLE}
" YEAR=${PATH##*\[} YEAR=${YEAR%%]*} #echo "YEAR=${YEAR}
" FPS=${LINE%|*|*|*} FPS=${FPS##*|} #echo "FPS=${FPS}
" ACODEC=${LINE#*|*|*|*|*|*} ACODEC=${ACODEC%%|*} #echo "ACODEC=${ACODEC}
" VCODEC=${LINE#*|*|*|*|*|*|*} VCODEC=${VCODEC%%|*} #echo "VCODEC=${VCODEC}
" RES=${LINE##*|} #echo "RES=${RES}" IMDB=$(echo ${TITLE} | sed s/\ /+/g) IMDB="http://www.imdb.com/find?s=all&q="${IMDB} #echo IMDB=\"${IMDB}\" THUMB=${LINE#*|*|*|} THUMB=${THUMB%%|*} #echo "THUMB=${THUMB}" echo ' ' echo ' ' echo ' ' echo ' ' echo ' ' done echo '
' echo "
${TITLE}" echo ' ('${YEAR}')' echo '
' echo " ${VCODEC}, ${RES}, ${FPS} fps
" echo " ${ACODEC}" echo '

' echo " PLAY" echo '

' echo '
' echo '
' echo '
' echo " " echo " " echo '
' echo '
' echo ' ' echo ''