#!/bin/bash echo -e "--||shrinkDVD||-- v0.1 (c) 2005 by zwobbl ;)\n" TMPDIR=/tmp/shrinkdvd VAMPS=`which vamps` VAMPSEXTRACT=`which vamps-extract` DVDAUTHOR=`which dvdauthor` LSDVD=`which lsdvd` function usage () { UNDERLINE_ON=`echo -e "\033[4m"` UNDERLINE_OFF=`echo -e "\033[0m"` cat << __EOF__ Usage: `basename ${PROGNAME}` ${UNDERLINE_ON}mandatory options${UNDERLINE_OFF} --chapter|-c - defines start and end chapter to extract. --output|-o destination directory to store the DVD-Video file structure in. --title|-t title to extract from input file. ${UNDERLINE_ON}miscellaneous options${UNDERLINE_OFF} -a|--audio [:] audio channel selection for vamps and optional description for dvdauthor. -f|--factor vaporize factor that correspons to vamps -E option. -h|--help this message you're reading right now. -s|--subtitle [: subtitle selection for vamps and optional description for dvdauthor. -p|--palette palette file for dvdauthor. -v|--verbose show some more infos while running. __EOF__ exit $1 } function warning () { echo "WARNING: $1" WARNING=1 } function do_confirm () { echo -n "$1 [Y/n] " read ANSWER if ! [ "${ANSWER}" = "Y" -o "${ANSWER}" = "y" -o -z "${ANSWER}" ]; then exit 0 fi } function error () { if [ ${__PRGCHK} -ne 1 ]; then check_programs fi echo "ERROR: $1" exit 1 } function cleanup () { kill -9 ${PIDS} 2>/dev/null rm -rf ${TMPDIR} } function interrupt () { echo "ALERT: shrinking interrupted! aborting processes and cleaning up..." cleanup exit 1 } function parse_parameters () { PARAMTYPE="none" INPUT="" for PARAM in "$@" ; do if [ "`echo ${PARAM} | cut -c 1`" = "-" ]; then if [ "${PARAMTYPE}" != "none" ]; then error "wrong parameter: ${PARAM}" else case ${PARAM} in -c|--chapter) PARAMTYPE=chapter ;; -o|--output) PARAMTYPE=output ;; -t|--title) PARAMTYPE=title ;; -a|--audio) PARAMTYPE=audio ;; -f|--factor) PARAMTYPE=factor ;; -h|--help) usage 0 ;; -s|--subtitle) PARAMTYPE=subtitle ;; -p|--palette) PARAMTYPE=palette ;; -v|--verbose) VERBOSE=1 ;; esac continue fi fi case ${PARAMTYPE} in title) TITLE=${PARAM} ;; chapter) CHAPTER=${PARAM} ;; audio) AUDIO=${PARAM} ;; subtitle) SUBTITLE=${PARAM} ;; output) OUTPUT=${PARAM} ;; palette) PALETTE=${PARAM} ;; factor) FACTOR=${PARAM} ;; *) if [ "${PARAMTYPE}" = "none" -a -z "${INPUT}" ]; then INPUT=${PARAM} else error "wrong parameter: ${PARAM}" fi ;; esac PARAMTYPE="none" done if [ "${PARAMTYPE}" != "none" ]; then error "parameter missing for ${PARAM}" fi } function check_number () { test $1 -eq $1 2>/dev/null } function check_programs () { __PRGCHK=1 if [ ! -x "${VAMPS}" ]; then error "vamps was not found or is not installed." elif [ ! -x "${VAMPSEXTRACT}" ]; then error "vamps-extract was not found or is not installed." elif [ ! -x "${DVDAUTHOR}" ]; then error "dvdauthor was not found or is not installed." fi if [ ! -x "${VAMPS}" ]; then warning "lsdvd was not found or is not installed." fi } function check_requirements () { if [ -z "${INPUT}" ]; then error "input device is required" elif [ -z "${OUTPUT}" ]; then error "output directory is required" elif [ -z ${TITLE} ]; then error "title selection is required" elif [ -z ${CHAPTER} ]; then error "chapter selection is required" elif ! [ -e "${INPUT}" ]; then error "input device does not exist" fi } function check_title () { if ! check_number ${TITLE} || [ ${TITLE} -le 0 ]; then error "invalid title selection" fi } function check_chapters () { CHAPTER_START=`echo $CHAPTER | cut -d "-" -f 1` CHAPTER_END=`echo $CHAPTER | cut -d "-" -f 2 -s` CHAPTER_CHECK=`echo $CHAPTER | cut -d "-" -f 3- -s` if ! check_number $CHAPTER_START || ! check_number $CHAPTER_END || [ "$CHAPTER_CHECK" ]; then error "invalid chapter selection" fi if [ $CHAPTER_START -gt $CHAPTER_END ]; then error "start chapter is greater than end chapter" fi } function check_audio () { if ! [ -z "${AUDIO}" ]; then AUDIO_VAMPS=`echo ${AUDIO} | cut -d ":" -f 1` AUDIO_DVDAUTHOR=`echo ${AUDIO} | cut -d ":" -f 2 -s` AUDIO_CHECK=`echo ${AUDIO} | cut -d ":" -f 3 -s` if [ -z "${AUDIO_VAMPS}" -o "${AUDIO_CHECK}" ]; then error "invalid audio channel selection" fi if [ "${AUDIO_DVDAUTHOR}" ]; then DVDAUTHOR_OPTIONS="-a ${AUDIO_DVDAUTHOR} ${DVDAUTHOR_OPTIONS} " else warning "no language/type information given for audio channel selection!" fi else warning "no audio channel was choosen! I enable first audio channel as default." AUDIO="1" AUDIO_VAMPS="1" fi VAMPS_OPTIONS="-a ${AUDIO_VAMPS} ${VAMPS_OPTIONS}" } function check_subtitle () { if ! [ -z "${SUBTITLE}" ]; then SUBTITLE_VAMPS=`echo ${SUBTITLE} | cut -d ":" -f 1` SUBTITLE_DVDAUTHOR=`echo ${SUBTITLE} | cut -d ":" -f 2 -s` SUBTITLE_CHECK=`echo ${SUBTITLE} | cut -d ":" -f 3 -s` if [ -z "${SUBTITLE_VAMPS}" -o "${SUBTITLE_CHECK}" ]; then error "invalid subtitle selection" fi if [ "${SUBTITLE_DVDAUTHOR}" ]; then DVDAUTHOR_OPTIONS="-s ${SUBTITLE_DVDAUTHOR} ${DVDAUTHOR_OPTIONS}" else warning "no language information given for subtitle selection!" fi VAMPS_OPTIONS="-s ${SUBTITLE_VAMPS} ${VAMPS_OPTIONS}" fi } function check_factor () { if ! [ -z "${FACTOR}" ]; then FACTOR_INT=`echo ${FACTOR} | cut -d "." -f 1` FACTOR_DEC=`echo ${FACTOR} | cut -d "." -f 2 -s` FACTOR_CHK=`echo ${FACTOR} | cut -d "." -f 3- -s` if ! check_number ${FACTOR_INT} || ! check_number ${FACTOR_DEC} || [ ${FACTOR_CHK} ]; then error "invalid vaporize factor" fi else FACTOR=1 fi VAMPS_OPTIONS="-E $FACTOR ${VAMPS_OPTIONS}" } function check_palette () { if [ "${PALETTE}" ]; then if [ ! -e "${PALETTE}" ]; then error "palette file does not exists" fi DVDAUTHOR_OPTIONS="-p ${PALETTE} ${DVDAUTHOR_OPTIONS}" else warning "no palette file specified! subtitles may be broken." fi } function get_fifo_file () { FIFO=`printf ${TMPDIR}/chapter%.4d.mpeg $1` } ## here we start ## PROGNAME=$0 WARNING=0 __PRGCHK=0 VERBOSE=0 DEBUG=0 VAMPS_OPTIONS="" DVDAUTHOR_OPTIONS="" parse_parameters "$@" check_programs check_requirements check_title check_chapters check_palette check_subtitle check_audio check_factor cat << __EOF__ intput device: ${INPUT} output directory: ${OUTPUT} selected title: ${TITLE} start chapter: ${CHAPTER_START} end chapter: ${CHAPTER_END} vaporize factor: ${FACTOR} audio channels: ${AUDIO} subtitles: ${SUBTITLE} palette file: ${PALETTE} __EOF__ if [ $VERBOSE -eq 1 ]; then echo -e "\nvamps options:\t\t${VAMPS_OPTIONS}" echo -e "dvdauthor options:\t${DVDAUTHOR_OPTIONS}\n" fi if [ ${WARNING} -eq 1 ]; then echo "Please check warnings printed above!" fi do_confirm "Do you want to start shrinking DVD?" trap 'interrupt SIGINT' SIGINT rm ${TMPDIR} -rf mkdir ${TMPDIR} PIDS="" DVDAUTHOR_CHAPTERS="" for ((CHAPTER=${CHAPTER_START}; ${CHAPTER}<=${CHAPTER_END}; CHAPTER++)) ; do printf "preparing extraction of title %2d chapter %2d\n" ${TITLE} ${CHAPTER} get_fifo_file $CHAPTER mkfifo $FIFO ${VAMPS-EXTRACT} ${TITLE} ${CHAPTER} 1 "${INPUT}" 2>/dev/null \ | ${VAMPS} ${VAMPS_OPTIONS} > ${FIFO} 2>/dev/null & PIDS="${PIDS} $!" DVDAUTHOR_CHAPTERS="${DVDAUTHOR_CHAPTERS} -C ${FIFO}" done if [ $VERBOSE -eq 1 ]; then echo -e "\ndvdauthor chapter options:\t${DVDAUTHOR_CHAPTERS}\n" fi ${DVDAUTHOR} -o "${OUTPUT}" ${DVDAUTHOR_CHAPTERS} ${DVDAUTHOR_OPTIONS} ${DVDAUTHOR} -o "${OUTPUT}" -T if [ -x ${LSDVD} ]; then ${LSDVD} -x "${OUTPUT}" fi cleanup