I'm in the process of moving my dvd library to harddisk. It has TV shows and movies. I have worked out what I think is a good script and I wanted to see if anyone had any suggestions for improvements. The script is run automatically up insertion of a DVD. /var/tmp/dvd-import is on one the system drive. /var/srv/media is a second shared drive and /tmp is tmpfs (~2G)
Code: Select all
#!/bin/bash
TMPDIR=/var/tmp/dvd-import/
SUBDIR=/tmp/sub-import/
DISC=`/usr/bin/lsdvd | /bin/grep Disc | /bin/sed 's/Disc\ Title:\ //'`
DESTDIR=/var/srv/media/videos/holding/ripping/`/bin/date +%F-%a-%R| /bin/sed 's/:/-/'`-${DISC}
/bin/date
/bin/mkdir -p ${DESTDIR}
/bin/mkdir -p ${SUBDIR}
/bin/mkdir -p ${TMPDIR}
rawtitles=`/usr/bin/lsdvd -q | /bin/grep -v 00:0[0-9]:[0-9][0-9] | /bin/grep Length | /usr/bin/sort -k4,2 `
/bin/echo "${rawtitles}"
titles=`/bin/echo "${rawtitles}" | /usr/bin/uniq -f3 | /usr/bin/cut -b 8-9 | /bin/sed 's/^[0]*//'`
for title in $titles
do
/bin/echo title = $title
listing=`/usr/bin/lsdvd -qast ${title}`
/usr/bin/dvdxchap -t ${title} /dev/dvd > ${SUBDIR}/${DISC}-${title}.chap
VOBNAME=${TMPDIR}/${DISC}-${title}.vob
/usr/bin/mplayer dvd://${title} -dumpfile ${VOBNAME} -dumpstream
SUBOPTS=" "
subtracks=`/bin/echo "${listing}" | /bin/grep Subtitle | /usr/bin/cut -d":" -f2,3 |\
/bin/sed "s:,::g" | /usr/bin/cut -d" " -f2,4 | /bin/sed "s: :-:" `
for subtrack in ${subtracks}
do
set -- `/bin/echo $subtrack | /bin/sed -e "s:-: :" -e "s:xx:en:"`
N=$(($1-1))
L=`/bin/echo $2 | /bin/sed "s:xx:en:"`
/bin/echo "Extracting subtitle track ${N} of language ${L}"
/usr/bin/mencoder -really-quiet ${VOBNAME} \
-nosound -ovc copy -o /dev/null \
-vobsubout ${SUBDIR}/${DISC}-${title}-SUBS-${N} -sid ${N} \
-vobsuboutindex ${N} -vobsuboutid ${L}
if [ -s ${SUBDIR}/${DISC}-${title}-SUBS-${N}.sub ]
then
SUBOPTS=" ${SUBOPTS} --default-track 0:0 --language 0:${2} \
=${SUBDIR}/${DISC}-${title}-SUBS-${N}.idx \
=${SUBDIR}/${DISC}-${title}-SUBS-${N}.sub "
fi
done
AUDOPTS=" "
audiotracks=`/bin/echo "${listing}" | /bin/grep Frequency | \
/usr/bin/cut -d":" -f2,3 | /bin/sed "s:,::g" | \
/usr/bin/cut -d" " -f2,4 | /bin/sed "s: :-:" `
for audiotrack in ${audiotracks}
do
set -- `/bin/echo $audiotrack | /bin/sed -e "s:-: :" -e "s:xx:en:"`
L=`/bin/echo $2 | /bin/sed "s:xx:en:"`
AUDOPTS="${AUDOPTS} --language ${1}:${L}"
done
AUDOPTS=" -a `/bin/echo "${audiotracks}" | /usr/bin/cut -d"-" -f1 \
| /usr/bin/tr "\n" "," | /bin/sed -e 's/\(.*\),/\1/g'` ${AUDOPTS} "
/usr/bin/mkvmerge --default-language en -o ${DESTDIR}/${DISC}-${title}.mkv \
--engage no_simpleblocks -S ${AUDOPTS} =${VOBNAME} ${SUBOPTS} \
--chapters ${SUBDIR}/${DISC}-${title}.chap
done
/bin/rm -rf ${TMPDIR}/*.vob
/bin/rm -rf ${TMPDIR}/*.mkv
/bin/rm -rf ${SUBDIR}/*.sub
/bin/rm -rf ${SUBDIR}/*.idx
/bin/chown -R me:mine ${DESTDIR}
/usr/bin/eject
/bin/date


