Unattended DVD Ripping

Updated: Sun, Feb 14, 2010 - 2:42am

I recently purchased a large number of movies from a very cool video store which was closing. It was a terrible disaster. Sure, I got a bunch of DVDs from it. But I did not gain access to any new movies -- I could have rented all these any time I wanted. Instead, the amazing collection in the possession of the video store is now split up in the hands of a bunch of individuals like me. It is not a collection anymore, and is far, far less useful to the community.

But this is a technical blog, not a library science blog. So where could I be headed with this?

Well, I don't want to sit around and import all these DVDs by hand. I want to set up a machine so that I can just drop a DVD in there and walk away, and have it rip the DVD for me. I got a headless computer and set it on my network. It's got a DVD drive, a large hard drive, and a samba server.

I set up ivman to respond to the dvd insertion event and to fire a script.

I edited /etc/ivman/IvmConfigActions.xml. Here is a stripped-down version of that file:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ivm:ActionsConfig version="0.2" xmlns:ivm="http://www.eikke.com/ivm">
  4. <!-- This is what I added -->
  5. <ivm:Match name="hal.volume.disc.is_videodvd" value="true">
  6. <ivm:Option name="exec" value="/opt/ripdvd.sh '$hal.block.device$'" />
  7. </ivm:Match>
  9. </ivm:ActionsConfig>

I based that entry off of a sample that was left in the comments of the Debian ivman package's version of IvmConfigActions.xml. The comment shows how to mount the dvd and then play it with mplayer.

My version of the file runs my ripdvd.sh script, which runs Handbrake to rip the dvd. I also decorate the script with some beeps to let me know that it's working, and eject the disc when done.

Note that, while Debian provides a Handbrake package, I installed it from source instead. In building it, it downloads the source code of all of its codec dependencies and builds them.

Here's the text of my ripdvd.sh script.

  1. #!/bin/sh
  3. # Acknowledge that we are starting
  4. beep -f 1400 -l 250
  6. DVD="$1"
  7. HANDBRAKE=/opt/handbrake/bin/HandBrakeCLI
  8. LOG="logger -p daemon.info -t ripdvd.sh "
  9. OUTDIR="/var/Data/Movies/Imports/"
  11. function beep_success() {
  12. beep -f 750 -l 80 -r 5 -D 20
  13. }
  15. function beep_failure() {
  16. beep -f 200 -l 900
  17. }
  19. function dvdrip() {
  20. $LOG "Beginning rip of $DVD"
  21. local LABEL=`file -s "$DVD" | cut -f 2- -d "'" | cut -f 1 -d "'" | sed -e 's/ *$//'`
  22. $LOG "$DVD contains $LABEL"
  23. $LOG $HANDBRAKE --verbose 9 --input "$DVD" --longest --output "$OUTDIR/$LABEL.avi" --size 600 --native-language eng --aencoder lame
  24. $HANDBRAKE --verbose 9 --input "$DVD" --longest --output "$OUTDIR/$LABEL.avi" --size 600 --native-language eng --aencoder lame 2>&1 > $OUTDIR/HandBrake.log
  25. local STATUS="$?"
  26. $LOG "Finished importing $LABEL from $DVD (status = $STATUS)"
  27. return $STATUS
  28. }
  30. if dvdrip; then
  31. beep_success
  32. else
  33. beep_failure
  34. fi
  36. eject

I have also attached the ripdvd.sh script for download.

Your rating: None Average: 2.6 (5 votes)
ripdvd.sh.txt919 bytes