http://www.cli-apps.org/content/show.ph ... tent=69322
PLEASE NOTE A NEW VERSION SOME REPLIES BELOW!!!
Hello people,
after a lot of work, I would like to share with you my work.
this is a vamps based bash script to backup dvd9 to dvd5.
I know that there are a lot of solutions...but if you still seeking for, I purpose you the mine one.
features: angle-managing, vamps for better backups, works with >2.6.19 kernels, audio and subtitles managing, and many others....
the story of this script is there http://forums.gentoo.org/viewtopic-t-457186.html
...enjoy!
Code: Select all
#!/bin/bash
#
# to use backDvd you need: libdvdread vamps lsdvd dvdauthor
# optional: mplayer cdrtools
#
# All is born here http://forums.gentoo.org/viewtopic-t-457186.html
# Thanks a lot to ~L~ and his halkase script. I copy the structure of backDvd from halkase.
# let's start!
clear
echo " "
echo "########################################################################"
echo "# #"
echo "# This is backDvd 1.1 rc8 #"
echo "# #"
echo "# A script for backing up DVD9 main title to DVD5 - by yknuk #"
echo "# #"
echo "# This software is distributed under the GNU GPL terms. #"
echo "# #"
echo "# Use this software at your own risk! #"
echo "# backDvd comes with absolutely NO WARRANTY! #"
echo "# Don't blame me if your PC get crashed! #"
echo "########################################################################"
echo " "
echo " "
echo "* Welcome to backDvd! Press Enter key to start! (CTRL+C to exit)"
read junk
# check programs...
# checking for vamps...
if [ ! -f "/usr/bin/vamps" ]
then
echo "* !!! You don't have vamps-0.99.2 installed... please provide!"
exit
fi
# checking for play_cell...
if [ ! -f "/usr/bin/play_cell" ]
then
echo "* !!! You don't have play_cell (vamps-0.99.2) installed... please provide!"
exit
fi
# checking for libdvdread...
if [ ! -f "/usr/lib/libdvdread.so" ]
then
echo "* !!! You don't have libdvdread installed... please provide!"
exit
fi
# checking for ifo_dump_dvdread...
if [ ! -f "/usr/bin/ifo_dump_dvdread" ]
then
echo "* !!! You don't have ifo_dump_dvdread (at least libdvdread-0.9.6) installed... please provide!"
exit
fi
# checking for mplayer...
if [ ! -f "/usr/bin/mplayer" ]
then
clear
echo "# backDvd #"
echo " "
echo "* !!! You don't have mplayer installed!"
echo "* !!! If you continue you'll not able to see the preview!"
echo -n "* !!! Do you want to continue? (yes/no)"
read -e prev
if [ "$prev" = "yes" ]
then
preview="no"
else
exit
fi
else
preview="yes"
fi
# checking for lsdvd...
if [ ! -f "/usr/bin/lsdvd" ]
then
echo "* !!! You don't have lsdvd installed... please provide!"
exit
fi
# checking for dvdauthor...
if [ ! -f "/usr/bin/dvdauthor" ]
then
echo "* !!! You don't have dvdauthor installed... please provide!"
exit
fi
# checking for cdrtools (mkisofs)...
if [ ! -f "/usr/bin/mkisofs" ]
then
clear
echo "# backDvd #"
echo " "
echo "* !!! You don't have cdrtools installed!"
echo "* !!! If you continue you'll not able to create the iso file and/or burn the dvd!"
echo -n "* !!! Do you want to continue? (yes/no)"
read -e isofs
if [ "$isofs" = "yes" ]
then
createiso="no"
else
exit
fi
else
createiso="yes"
fi
# change that for meet your defaults...
home=~
#home="/home/backup"
defaultworkingdir="$home/film-dvd"
defaultdvd="/dev/dvd"
# go to the working directory...
clear
echo "# backDvd #"
echo " "
echo -n "* What is your working directory? (default $defaultworkingdir) : "
read -e working
if [ -z "$working" ]
then
working="$defaultworkingdir"
fi
# check the default working dir...
if [ ! -d "$working" ]
then
echo " "
echo "* Creating directory $working"
mkdir $working
fi
# enter working dir...
cd $working
if [ -d backDvd ]
then
echo " "
echo "* Cleaning backDvd dir..."
rm -rf backDvd
fi
mkdir backDvd
cd backDvd
# where to read...
clear
echo "# backDvd #"
echo " "
echo -n "* Where is your dvd device? (default $defaultdvd ): "
read -e device
if [ -z "$device" ]
then
device="$defaultdvd"
fi
echo " "
# grab dvd name...
defaultname=$( lsdvd | head -n 1 | tail -n 1 | awk -F' ' '{ print $3 }' )
# title name...
clear
echo "# backDvd #"
echo " "
echo -n "* What shall we call it? (default $defaultname): "
read -e dvdname
if [ -z "$dvdname" ]
then
dvdname="$defaultname"
fi
if [ -d $working/$dvdname ]
then
echo " "
echo "* A folder with the name \"$defaultname\" already exist!"
echo " "
echo -n "* I must DELETE it!!! Continue (yes/no)? (default no): "
read -e delete
if [ "$delete" = "yes" ]
then
rm -rf $working/$dvdname
echo "* Folder Deleted. continuing..."
else
exit
fi
fi
echo " "
mkdir $working/$dvdname
# what's in the dvd...
mai1=$( lsdvd | grep "Longest track:" | awk -F' ' '{ print $3 }' )
mai=$mai1
clear
echo "# backDvd #"
echo " "
echo "* These are the longest title/s on the dvd:"
echo " "
list=$( lsdvd | grep -v "Length: 00" | grep -v Disc | grep -v Longest | grep " " )
echo "$list"
echo " "
# which title to backup...
echo -n "* Which one do you want to backup? (default $mai) "
read -e main
if [ -z "$main" ]
then
main="$mai"
fi
# and then audio...
clear
echo "# backDvd #"
echo " "
echo "* These are the audio track for the titles $main: "
echo " "
lsdvd -t $main -a | grep Audio: | awk -F' ' '{ print $2,$5,$6,$5,$13,$14,$5,$8 }' | perl -pi -e 's/,$//g' | perl -pi -e 's/,//g'
echo " "
echo -n "* How many audio tracks do you want to backup? ( default 1 ) "
read -e numaud
if [ -z "$numaud" ]
then
numaud=1
fi
numaudplus=$[ 1 + $numaud ]
counter=1
while [ $counter -lt $numaudplus ]; do
echo -n "* Which language do you want to be the number $counter of $numaud? ( example: 1 ) "
read -e aidz
if [ -z "$aidz" ]
then
echo " "
echo "* You have to select the language, not just press enter! exiting..."
exit
fi
language=$( lsdvd -t $main -a | grep "Audio: $aidz" | awk -F' ' '{ print $4 }' )
if [ "$counter" = "1" ]
then
audpostorder="$counter"
aidcount="$aidz"
langs="$language"
else
audpostorder="$audpostorder,$counter"
aidcount="$aidcount,$aidz"
langs="$langs $language"
fi
counter=$( echo "scale=2; $counter + 1 " | bc )
done
# and the subtitles...
clear
echo "# backDvd #"
echo " "
echo -n "* Do you want to add subtitle tracks on your backup (yes/no)? (default no) "
read -e suba
if [ -z "$suba" ]
then
suba="no"
fi
if [ "$suba" = "yes" ]
then
echo " "
echo "* These are the avilable subtitles for the title $main:"
echo " "
lsdvd -t $main -s | grep Subtitle: | awk -F' ' '{ print $2,$5,$6 }' | perl -pi -e 's/,$//' | perl -pi -e 's/,//'
echo " "
echo -n "* How many subtitles do you want to backup? ( default 1 ) "
read -e numsub
if [ -z "$numsub" ]
then
numsub=1
fi
numsubplus=$[ 1 + $numsub ]
counter=1
while [ $counter -lt $numsubplus ]; do
echo -n "* Which subtitle do you want to be the number $counter of $numsub? ( example: 01 ) "
read -e nub
if [ -z "$nub" ]
then
echo " "
echo "* You have to select the subtitle, not just press enter! exiting..."
exit
fi
nubz=$( lsdvd -t $main -s | grep "Subtitle: $nub" | awk -F' ' '{ print $4 }' )
if [ "$counter" = "1" ]
then
subpost="$counter"
sidcount="$nub"
sub="$nubz"
else
subpost="$subpost,$counter"
sidcount="$sidcount,$nub"
sub="$sub $nubz"
fi
counter=$( echo "scale=2; $counter + 1 " | bc )
done
echo " "
fi
# angles...
ang=$( lsdvd -t $main -n 2>/dev/null | grep "Angles: " | awk -F' ' '{ print $4 }' )
if [ "$ang" = "1" ]
then
target=$ang
else
chang=yes
clear
echo "# backDvd #"
echo " "
echo "* There are $ang angles for this title."
echo " "
echo -n "* Wich one do you want to keep? ( default: 1 ) "
read -e target
if [ -z "$target" ]
then
target=1
fi
fi
# generate cell list...
echo " "
echo "* Retrieving cell list from DVD..."
cells=$( lsdvd -t $main -d | grep Cell: | awk -F' ' '{ print $2 }' | perl -pi -e 's/\n//' | perl -pi -e 's/,/ /g' )
ma=$( echo "$main" | bc )
pgc=$( title_info $defaultdvd | grep -A 1 "Title $ma:" | grep TTN | awk -F' ' '{ print $5}' | perl -pi -e 's/]$//' )
vts=$( title_info $defaultdvd | grep -A 1 "Title $ma:" | grep VTS | awk -F' ' '{ print $3}' )
# regenerate $cells angle-compliant, if needed...
if [ "$ang" -gt "1" ]
then
dangl=$( ifo_dump_dvdread $defaultdvd $vts | grep "block angle" | grep "first" | awk -F' ' '{ print $2 }' )
if [ "$target" -ne "1" ]
then
count1=1
count2=1
while [ "$count1" -le "$ang" ]; do
if [ "$count1" -ne "$target" ]
then
if [ "$count2" -eq "1" ]
then
dellist=$( echo "$dangl" )
count2=$( echo "scale=2; $count2 + 1 " | bc )
else
dellist=$( echo "$dellist" $'\n' "$dangl" )
fi
dangl=$( echo "$dangl" | awk -F' ' '{ print $1"+1" }' | bc )
fi
count1=$( echo "scale=2; $count1 + 1 " | bc )
done
else
count1=1
count2=1
while [ "$count1" -le "$ang" ]; do
if [ "$count1" -ne "$target" ]
then
if [ "$count2" -eq "1" ]
then
dangl=$( echo "$dangl" | awk -F' ' '{ print $1"+1" }' | bc )
dellist=$( echo "$dangl" )
count2=$( echo "scale=2; $count2 + 1 " | bc )
else
dangl=$( echo "$dangl" | awk -F' ' '{ print $1"+1" }' | bc )
dellist=$( echo "$dellist" $'\n' "$dangl" )
fi
fi
count1=$( echo "scale=2; $count1 + 1 " | bc )
done
fi
dellist=$( echo $dellist )
cells=$( echo $cells | perl -pi -e 's/\s+/\n/g' )
for x in $dellist
do
if [ $x -lt 10 ]
then
y="0$x"
cells=$(echo "$cells" | grep -v "$y")
else
cells=$(echo "$cells" | grep -v "$x")
fi
done
cells=$( echo $cells )
fi
# recap...
clear
echo "# backDvd #"
echo " "
echo "* These audio tracks will be included: \"$langs\""
echo " "
if [ "$suba" = "yes" ]
then
echo "* These subtitles will be included: \"$sub\""
echo " "
fi
if [ "$chang" = "yes" ]
then
echo "* The selected angle is the number \"$target\""
echo " "
fi
echo "* Press Enter key to start!"
read junk
# extracting...
echo "* Extracting cells..."
echo " "
if [ "$suba" = "yes" ]
then
subtitle="-s $sidcount"
else
subtitle=" "
fi
counter=1
echo -n "* Extracting cell number "
bs=$'\b'
for cellz in $cells
do
echo -n "$cellz"${bs}${bs}
# the line below was used in the script (until 1.1-rc7) until kernel 2.6.19 was introduced.
# if this command is used with an earler 2.6.19 version of the kernel,
# it returns the error "vamps: Fatal: Premature EOF". I don't know why!
# play_cell -r 0 -g $defaultdvd $vts $pgc $cellz | vamps -E 1 -a $aidcount $subtitle -S 1 > temp$cellz.mpeg
mkfifo $cellz.fifo
cat $cellz.fifo | vamps -E 1 -a $aidcount $subtitle -S 1 > temp$cellz.mpeg &
play_cell -r 0 -g $defaultdvd $vts $pgc $cellz > $cellz.fifo
rm $cellz.fifo
size=$( du -b temp$cellz.mpeg | awk -F' ' '{ print $1 }' | perl -pi -e 's/,$//' )
if [ "$counter" = "1" ]
then
filmz=$size
else
filmz=$[ $filmz + $size ]
fi
counter=$( echo "scale=2; $counter + 1 " | bc )
done
echo "...finished!"
# to shrink or not to shrink...
requa=$( echo "scale=2; $filmz / 4600000000 " | bc | perl -pi -e 's/\.//' )
if [ "$requa" -gt "105" ]
then
req=$( echo "scale=2; $filmz / 4600000000 " | bc ) #requant factor
echo " "
echo "* Shrinking needed!"
echo " "
echo "* Requant factor for this movie is: $req"
else
echo " "
echo "* No shrinking needed!"
req="0.9"
fi
# create palette file...
ifo_dump_dvdread $defaultdvd $vts | grep Color | head -n 16 | awk -F' ' '{ print $3 }' > palette.yuv
# create dvdauthor.xml...
echo " "
echo "* Authoring..."
echo "<dvdauthor dest=\"$working/$dvdname/dvd\" >" > dvdauthor.xml
echo "<vmgm />" >> dvdauthor.xml
echo "<titleset>" >> dvdauthor.xml
echo "<titles>" >> dvdauthor.xml
for langz in $langs
do
echo "<audio lang=\"$langz\" />" >> dvdauthor.xml
done
if [ "$suba" = "yes" ]
then
for subz in $sub
do
echo "<subpicture lang=\"$subz\" />" >> dvdauthor.xml
done
subpostorder="-s $subpost "
else
subpostorder=" "
fi
echo "<pgc palette=\"$working/backDvd/palette.yuv\" >" >> dvdauthor.xml
for chapters in $cells
do
if [ 0$( lsdvd -t $main -c | grep "Cell: $chapters" | awk -F' ' '{ print $7 }' ) = 0$chapters ]
then
chpt="chapters=\"0\""
else
chpt=" "
fi
echo "<vob file=\"vamps -E $req -a $audpostorder $subpostorder < temp$chapters.mpeg |\" $chpt />" >> dvdauthor.xml
done
echo "</pgc>" >> dvdauthor.xml
echo "</titles>" >> dvdauthor.xml
echo "</titleset>" >> dvdauthor.xml
echo "</dvdauthor>" >> dvdauthor.xml
# create dvd structure...
dvdauthor -x dvdauthor.xml 2>/dev/null
dvdauthor -o $working/$dvdname/dvd -T 2>/dev/null
# move to $working and release space...
cd $working
rm -rf backDvd
# preview...
if [ "$preview" = "yes" ]
then
clear
echo "# backDvd #"
echo " "
echo -n "* Do you want to preview the dvd (yes/no)? (default no) "
read -e prw
if [ -z "$prw" ]
then
prw=no
fi
if [ "$prw" = "yes" ]
then
echo " "
echo "* Hit enter to preview dvd (CTRL+C to skip, Q to stop preview)"
echo " "
read junk
mplayer dvd://1 -dvd-device $working/$dvdname/dvd >/dev/null 2>&1
fi
fi
# build iso or not...
if [ "$createiso" = yes ]
then
clear
echo "# backDvd #"
echo " "
echo -n "* Do you want to build the .iso file (yes/no)? (default no) "
read -e iso
if [ -z "$iso" ]
then
iso="no"
fi
else
iso="no"
fi
# build the .iso file...
if [ "$iso" = "yes" ]
then
echo " "
echo "* Building the iso file..."
mkisofs -quiet -dvd-video -V $defaultname -o $working/$dvdname.iso $working/$dvdname/dvd
fi
# burn dvd or not...
if [ "$createiso" = yes ]
then
clear
echo "# backDvd #"
echo " "
echo -n "* Do you want to burn the dvd (yes/no)? (default no) "
read -e burn
if [ -z "$burn" ]
then
burn="no"
fi
else
burn="no"
fi
# burn dvd...
if [ "$burn" = "yes" ]
then
echo " "
echo -n "* Please insert an empty dvd into the drive and press enter when done..."
read junk
echo " "
echo "* Burning..."
growisofs -quiet -dvd-compat -dvd-video -V $defaultname -Z $defaultdvd $working/$dvdname/dvd
fi
# Finish...!
clear
echo "# backDvd #"
echo " "
echo " "
echo "* The Dvd is located at $working/$dvdname"
echo " "
if [ "$iso" = "yes" ]
then
echo "* dvd iso is located at $working/$dvdname.iso"
echo " "
fi
if [ "$requa" -gt "105" ]
then
echo "* Requant factor for this movie is:" "$req"
echo " "
fi
echo "* Done!"
echo " "
echo "* Enjoy your backup!"
echo " "



