Nicias

dvd-backup

Jul 6th, 2013
233
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. if [ -z "$1" ]; then
  4. TARGET=/dev/sr0
  5. else
  6. TARGET=$1
  7. fi
  8.  
  9. TMPDIR=/var/tmp/dvd-import/
  10. SUBDIR=/tmp/sub-import/
  11.  
  12. DISC=`/usr/bin/lsdvd ${TARGET} | /bin/grep Disc | /bin/sed 's/Disc\ Title:\ //'`
  13.  
  14. DESTDIR=/var/srv/media/videos/holding/ripping/`/bin/date +%F-%a-%R| /bin/sed 's/:/-/'`-${DISC}
  15.  
  16. REPORT=${DESTDIR}/report.txt
  17.  
  18. /bin/date
  19.  
  20. /bin/mkdir -p ${DESTDIR}
  21. /bin/mkdir -p ${SUBDIR}
  22. /bin/mkdir -p ${TMPDIR}
  23.  
  24. /usr/bin/lsdvd ${TARGET} -qas > ${REPORT}
  25.  
  26. rawtitles=`/usr/bin/lsdvd -q ${TARGET} | /bin/grep 0[0-1]:[1-5][0-9]:[0-9][0-9] \
  27. | /bin/grep Length | /usr/bin/sort -k4,2 `
  28. /bin/echo "${rawtitles}"
  29. if [ -z "$rawtitles" ] ; then
  30. echo "No episodes ripping longest"
  31. titles=`/usr/bin/lsdvd -q ${TARGET} | /bin/grep Longest | /usr/bin/cut -f3 -d" "`
  32. else
  33. titles=`/bin/echo "${rawtitles}" | /usr/bin/uniq -f3 | /usr/bin/cut -b 8-9 \
  34. | /bin/sed 's/^[0]*//'`
  35. fi
  36. for title in $titles
  37. do
  38. /bin/echo title = $title
  39. listing=`/usr/bin/lsdvd ${TARGET} -qast ${title}`
  40. /usr/bin/dvdxchap -t ${title} ${TARGET} > ${SUBDIR}/${DISC}-${title}.chap
  41. VOBNAME=${TMPDIR}/${DISC}-${title}.vob
  42. /usr/bin/mplayer -dvd-device ${TARGET} dvd://${title} -dumpfile ${VOBNAME} -dumpstream
  43. SUBOPTS=" "
  44. subtracks=`/bin/echo "${listing}" | /bin/grep Subtitle | /usr/bin/cut -d":" -f2,3 \
  45. | /bin/sed "s:,::g" | /usr/bin/cut -d" " -f2,4 | /bin/sed "s: :-:" `
  46. for subtrack in ${subtracks}
  47. do
  48. set -- `/bin/echo $subtrack | /bin/sed -e "s:-: :" -e "s:xx:en:"`
  49. N=$(($1-1))
  50. L=`/bin/echo $2 | /bin/sed "s:xx:en:"`
  51. /bin/echo "Extracting subtitle track ${N} of langauge ${L}"
  52. /usr/bin/mencoder -really-quiet ${VOBNAME} -nosound -ovc copy -o /dev/null \
  53. -vobsubout ${SUBDIR}/${DISC}-${title}-SUBS-${N} -sid ${N} \
  54. -vobsuboutindex ${N} -vobsuboutid ${L}
  55. if [ -s ${SUBDIR}/${DISC}-${title}-SUBS-${N}.sub ]
  56. then
  57. SUBOPTS="${SUBOPTS} --default-track 0:0 --language 0:${2} \
  58. =${SUBDIR}/${DISC}-${title}-SUBS-${N}.idx \
  59. =${SUBDIR}/${DISC}-${title}-SUBS-${N}.sub "
  60. fi
  61. done
  62. AUDOPTS=" "
  63. audiotracks=`/bin/echo "${listing}" | /bin/grep Frequency | \
  64. /usr/bin/cut -d":" -f2,3 | /bin/sed "s:,::g" | \
  65. /usr/bin/cut -d" " -f2,4 | /bin/sed "s: :-:" `
  66. for audiotrack in ${audiotracks}
  67. do
  68. set -- `/bin/echo $audiotrack | /bin/sed -e "s:-: :" -e "s:xx:en:"`
  69. L=`/bin/echo $2 | /bin/sed "s:xx:en:"`
  70. AUDOPTS="${AUDOPTS} --language ${1}:${L}"
  71. done
  72. AUDOPTS=" -a `/bin/echo "${audiotracks}" | /usr/bin/cut -d"-" -f1 | \
  73. /usr/bin/tr "\n" "," | /bin/sed -e 's/\(.*\),/\1/g'` ${AUDOPTS} "
  74. /usr/bin/mkvmerge --default-language en -o ${DESTDIR}/${DISC}-${title}.mkv \
  75. --engage no_simpleblocks -S ${AUDOPTS} =${VOBNAME} \
  76. ${SUBOPTS} --chapters ${SUBDIR}/${DISC}-${title}.chap
  77. done
  78.  
  79.  
  80. /bin/rm -rf ${TMPDIR}/*.vob
  81. /bin/rm -rf ${TMPDIR}/*.mkv
  82. /bin/rm -rf ${SUBDIR}/*.sub
  83. /bin/rm -rf ${SUBDIR}/*.idx
  84.  
  85.  
  86. /bin/chown -R me:mine ${DESTDIR}
  87. /usr/bin/eject
  88. /bin/date
RAW Paste Data