#!/bin/bash ## defaults MENUFONTSIZE=35 BACKGROUND="dvd-bg.png" COLOR="white" SHADOWCOLOR="black" SHADOWOFFSET=2 DVDREC="/dev/dvd" FONT="/usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf" AUTOBURN=0 WITHOUTMENU=0 ENCODE=0 ENCODETARGET="dvd" ################################################################################## ######## do not edit below this line if you don't know what you are doing ######## ################################################################################## # Copyright 2006 Peter 'piie' Feuerer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Contributions: # Christian 'acez' Wilhelm # Fabian 'maverick' Mettler # # thanks guys for doing really good qa! ;) # # TODO: # - check if enaugh space is available on hd # - implement the "without menu" option # - start writing usefull comments # - automatically guess font # - check if the given device is a dvd recorder # - bg color instead of background # - make tempfiles in .tmp dir # - bugfixes!!! # # Changelog: # 0.6.3: # - check that bash is used, not sh or something else # - fixed bug, that caused sed to print error because of growisofs waring # - improved the bar which is displayed while burning # - check if every program successes # - sizecheck of dvd and all movie titles # - added shadow to the menutitles # - implemented automatically google picture search for given searchstring # # 0.6.2: # - fixed some typos # - changed menu generation - selection not lost after 2 sec # - fix for some dvdplayer which couldnt handle the menu # # 0.6.1: # - fixed a bug, which caused that the errorlog was overwritten all the time # - fixed bug in getopts option string; -d was missing # - modified error messages for missing font and background # - added check whether the dvd-rec is a block device # - quit option deletes now the dvd folder # # 0.6: # - added gpl header # - checks if dvdauthor is in version 0.6.12 (it has a bug with the jump # function # - prints every single program which is missing, not the whole pile of shit # - added menu to choose before burning # - added iso generation # - added the autoburn option # - created an error log # - redirect stderr to the error log # - auto conversion from avi to dvd using ffmpeg # - unused stdout to /dev/null # - replaced crapy output of growisofs with a nice bar # # < 0.6: # - crappy shit, not very useful, except for some special cases # - if you find such a version, delete it immediately! VERSION="0.6.3" TITLECOUNT=0 NO_ARGS=0 E_OPTERROR=65 ERRORLOG="dvdmg-err.log" if [ "$(basename $SHELL)" != "bash" ] then echo echo "please use bash for this script!" echo "e.g. bash dvdmg" echo exit 1 fi exec 2>> $ERRORLOG # checks if program $1 of package $2 exists # check_prog $1 $2 check_prog() { if ! type -p $1 >/dev/null then echo echo "missing program: \"$1\" of package \"$2\"!" echo "please install this package!" echo exit 1 fi } # called when a program failed # program_failed $1 program_failed() { echo echo "ERROR! execution failed: $1" echo "for more information have a look into $ERRORLOG" echo # clean the fuck up echo "cleaning up" rm -f menuh.png menu.png menus.png menu.xml menu.mp2 menu.m2v menu.mpg dvdauthor.xml mainmenu.mpg background.jpg dvdmg-tempvid* exit 1 } # catches images from google # gimage_grabber "$1" gimage_grabber() { BACKGROUND="" ILOOPCOUNT=0 IMAGECOUNT=0 echo "catching images, this may take a while, depending on your internet connection" links --dump "http://images.google.de/images?q=$1+wallpaper&imgsz=xxlarge" | sed -n "s/.*imgurl=\([^&]*\)&.*/\1/p" > dvdmg-pictures.lst PICTURES_COUNT=$(cat dvdmg-pictures.lst | wc -l) cat dvdmg-pictures.lst | ( while read pic; do if ((ILOOPCOUNT==0)) then rm dvdmg-bg*.jpg convert xc:white -resize 400x320! dvdmg-preview-0.jpg cp dvdmg-preview-0.jpg dvdmg-preview-1.jpg cp dvdmg-preview-0.jpg dvdmg-preview-2.jpg cp dvdmg-preview-0.jpg dvdmg-preview-3.jpg cp dvdmg-preview-0.jpg dvdmg-bg-0.jpg cp dvdmg-preview-0.jpg dvdmg-bg-1.jpg cp dvdmg-preview-0.jpg dvdmg-bg-2.jpg cp dvdmg-preview-0.jpg dvdmg-bg-3.jpg fi echo -n "." if wget -T 3 -t 1 $pic -O dvdmg-temp-back.jpg &> /dev/null then SAME=0 convert -quality 100 -resize 720x576! dvdmg-temp-back.jpg "dvdmg-bg-$ILOOPCOUNT.jpg" echo -n "." convert -quality 100 -resize 400x320! dvdmg-temp-back.jpg "dvdmg-preview-$ILOOPCOUNT.jpg" echo -n "." AVERAGE=$(( $(convert -resize 1x1! -depth 1 dvdmg-temp-back.jpg txt:-|sed -n "s/0,0: ( *\([0-9][0-9]*\), *\([0-9][0-9]*\), *\([0-9][0-9]*\).*/(\1+\2+\3)\/3/p"))) # need to get the displays avarage color! convert -quality 100 -resize 15x12! -depth 1 -black-threshold $((AVERAGE+1)) -white-threshold $AVERAGE dvdmg-temp-back.jpg "dvdmg-$ILOOPCOUNT.txt" for((I=0;I/dev/null if (( CHOICE != -2 )) then mv "dvdmg-bg-$CHOICE.jpg" dvd_gimage_grabber_background.jpg rm dvdmg-menu-choice.jpg dvdmg-bg*.jpg exit 1 fi fi ((++IMAGECOUNT)) done ) RETURNCODE=$(echo ${PIPESTATUS[1]}) echo rm dvdmg-pictures.lst if [ "$RETURNCODE" = 1 ] then echo blubb BACKGROUND="dvd_gimage_grabber_background.jpg" return else return -1 fi } # burns dvd and replaces output of growisofs by a nice bar # burn_dvd burn_dvd() { echo "burning dvd:" growisofs -Z "$DVDREC" -dvd-video ./dvd 2>&1 | tee -a $ERRORLOG | ( while read line do for ((i=0;i<8;++i)) do echo -ne "\b\b\b\b\b\b\b\b" done d=$(echo $line | sed -n "s/^ *\([0-9][0-9]*\)\..*/\1/p") #echo $d #echo $line if [ "$d" != "" ] then echo -n " -[ " for ((i=0; i<50; ++i)) do if ((i> $ERRORLOG echo "==============================">> $ERRORLOG echo "exit" >> $ERRORLOG date >> $ERRORLOG echo "==============================">> $ERRORLOG echo >> $ERRORLOG exit 0 } check_prog "convert" "ImageMagick" check_prog "mplex" "mjpegtools" check_prog "jpeg2yuv" "mjpegtools" check_prog "mpeg2enc" "mjpegtools" check_prog "toolame" "toolame" check_prog "dd" "coreutils" check_prog "dvdauthor" "dvdauthor" check_prog "mpeg2desc" "dvdauthor" check_prog "spumux" "dvdauthor" check_prog "mkisofs" "mkisofs" check_prog "growisofs" "dvd+rw-tools" check_prog "dvd+rw-mediainfo" "dvd+rw-tools" check_prog "xine" "xine" check_prog "ffmpeg" "ffmpeg" #check_prog "" "" if [ $(dvdauthor 2>&1 | sed -n "s/.*version //p") == "0.6.12." ] then echo echo "your dvdauthor is in version 0.6.12, which has a shitty bug, please install 0.6.11 or a newer one!" echo exit 1 fi if [ $# -eq "$NO_ARGS" ] then print_help fi while getopts ":b:t:v:f:F:d:e:a:c:m:g:" Option do case $Option in b ) BACKGROUND=$OPTARG;; t ) TITLE[$TITLECOUNT]=$OPTARG;; v ) VID[$TITLECOUNT]=$OPTARG;((TITLECOUNT++));; f ) MENUFONTSIZE=$OPTARG;; F ) FONT=$OPTARG;; d ) DVDREC=$OPTARG;; e ) ENCODE=$OPTARG;; a ) AUTOBURN=$OPTARG;; c ) COLOR=$OPTARG;; m ) WITHOUTMENU=$OPTARG;; g ) GIMAGESEARCH=$OPTARG;; * ) echo "Unimplemented option chosen."; echo ; print_help;; # DEFAULT esac done if [ "$GIMAGESEARCH" != "" ] then if ! gimage_grabber "$GIMAGESEARCH" then echo echo "no image found, please search manually for it and use the -b option" echo exit 1 fi fi # check if background is a regular file if [ ! -f "$BACKGROUND" ] then echo "The selected background image is no regular file:" echo "\"$BACKGROUND\"" echo echo "choose another one with the option -b \"background-image.png\", or edit the first lines of this script" echo exit 1 fi # check if font is a regular file if [ ! -f "$FONT" ] then echo "The font you selected does not exist:" echo "\"$FONT\"" echo echo "choose another font with the option -f \"/path/to/font.ttf\", or edit the first lines of this script" echo " tested fonts:" echo " fedora: /usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf" echo " ubuntu: /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf" echo exit 1 fi # check if dvdrec is block device if [ ! -b "$DVDREC" ] then echo "The dvd-recorder device does not exist or is no block device" echo "\"$DVDREC\"" echo echo "choose the correct device with the option -d \"/path/device/\", or edit the first lines of this script" echo exit 1 fi # check if dvd directory already exists if [ -d "dvd" ] then echo "dvd-directory does already exist, do you want to overwrite it? (y|n)" read ANSWER if [ "$ANSWER" == "y" ] then rm -Rf dvd else exit 1 fi fi # timestamp into errorlog echo >> $ERRORLOG echo "==============================">> $ERRORLOG echo "start" >> $ERRORLOG date >> $ERRORLOG echo "==============================">> $ERRORLOG echo >> $ERRORLOG SIZE=0 # check if all videofiles exist and encode to dvd if ENCODE is 1 # calculate the size of the dvd for ((I=0;I /dev/null || program_failed "ffmpeg" VID[$I]="dvdmg-tempvid-$I.mpg" fi ((SIZE = SIZE + $(du ${VID[$I]} | cut -f 1) )) done # calculate free disk space FREE=$(df . | sed "s/ */ /g"| cut -d " " -f 4 | grep "[0-9][0-9]*") # complain, if too less space is left if (( FREE < SIZE )) then echo echo "not enaugh space on the disk;" echo "free space: $(( FREE / 1024)) MB" echo "needed: $(( SIZE / 1024)) MB" echo exit fi # complain, if dvd is getting bigger than 4,3GB # 4.7 fucking marketing GB, y the hell cant they simply # use the factor 1024, this costs us about 300 MB a dvd!! if (( 4700000 < SIZE )) then echo echo "the dvd image is getting bigger than 4.7 marketing GB (= real 4.38GB)" echo "the size is: $(( SIZE / 1024 )) MB" echo echo "do you want to proceed anyway? (y|n)" read ANSWER if [ "$ANSWER" != "y" ] then echo "aborted" echo "cleaning up" rm -f menuh.png menu.png menus.png menu.xml menu.mp2 menu.m2v menu.mpg dvdauthor.xml mainmenu.mpg background.jpg dvdmg-tempvid* exit 1 fi fi # converting background image echo "resizing background" rm -f background.jpg convert -quality 100 -resize 720x576! "$BACKGROUND" background.jpg || program_failed "convert" # creating empty pngs with the correct size rm -f menus.png menuh.png echo "creating blank menu" convert xc:transparent -resize 720x576! menus.png || program_failed "convert" convert xc:transparent -resize 720x576! menuh.png || program_failed "convert" # creating menu.png echo -en "creating menu\n " for ((I=0;I" >> menu.xml echo " " >> menu.xml echo " " >> menu.xml for ((I=1;I<=TITLECOUNT;I++)) do ((Y0=(I-1)*MENUFONTSIZE+(I)*20+20)) ((Y1=Y0+MENUFONTSIZE)) echo " " >> dvdauthor.xml done echo " " >>dvdauthor.xml echo " " >>dvdauthor.xml echo " " >>dvdauthor.xml echo " " >>dvdauthor.xml for ((I=0;I" >> dvdauthor.xml echo " " >> dvdauthor.xml echo " call vmgm menu 1; " >> dvdauthor.xml echo " " >> dvdauthor.xml done echo " " >>dvdauthor.xml echo " " >>dvdauthor.xml echo "" >>dvdauthor.xml # generating dvd-structure echo "generating dvd-structure" dvdauthor -x dvdauthor.xml >/dev/null || program_failed "dvdauthor" # clean the fuck up echo "cleaning up" rm -f menuh.png menu.png menus.png menu.xml menu.mp2 menu.m2v menu.mpg dvdauthor.xml mainmenu.mpg background.jpg dvdmg-tempvid* if [ "$AUTOBURN" == 0 ] then while true do echo echo "=============================================" echo " b) burn dvd" echo " v) view result with xine" echo " i) create iso image (video-dvd.iso)" echo " q) quit - delete the temporary dvd folder" echo " q!) quit - don't delete the temporary dvd folder" read ANSWER if [ "$ANSWER" = "b" ] then burn_dvd elif [ "$ANSWER" = "v" ] then xine dvd://$(pwd)/dvd >/dev/null elif [ "$ANSWER" = "i" ] then mkisofs -dvd-video -o video-dvd.iso -r ./dvd >/dev/null || program_failed "mkisofs" #exit program elif [ "$ANSWER" = "q" ] then rm -Rf ./dvd quit elif [ "$ANSWER" = "q!" ] then quit fi done else echo "automatically burn dvd is set!\n" echo "burning dvd:" burn_dvd quit fi