Friday, March 26, 2010

Headless dvd ripping for xbmc.

As always use at your own risk. This blog assumes you are not afraid of the shell.

I will describe how I am able to Rip my DVDs from my HTPC running XBMC-Live. I like to use DVDFab HD Decrypter because they do a fine job of keeping up with all the stupid shit the movie people do to keep you from making easy legal backups. This should work on Blu ray but I don't own any Blu ray movies/Drives nor will I until the make a real Blu ray player for linux.

Must install required software
ssh to your XBMC-Live box(ex. ssh user@xbmc-live -X)
the -X will send any X information to your display

if your running windows you will need something like:
http://www.straightrunning.com/XmingNotes/
or a keyboard and mouse and be in front of your TV.

cd ~
sudo apt-get install wine wget xvfb
wget http://www.kegel.com/wine/winetricks
sh winetricks corefonts vcrun6sp6


goto http://www.dvdfab.com/free.htm
and grab the latest DVDFab HD Decrypter
I just right click the link or button and select "copy link location" then in the console type wget and then paste the link. Sometimes you need to surround the link with single quotes to preserve the URL.
it would look like this:

wget 'http://www.dvdfab.com/mlink/download.php?g=DVDFAB6'
wine DVDFab____.exe


use tab to auto-complete..
if you get some errors like:
"Application tried to create a window, but no driver could be loaded.
Make sure that your X server is running and that $DISPLAY is set correctly."
go back to the top and read this again.
wine will be pretty verbose with "fixme:" stuff but you can ignore all that.

Install the program and uncheck every option it gives you.

when its done you can run it by doing the following..

wine ~/.wine/drive_c/Program\ Files/DVDFab\ 7/DVDFab.exe


For anything that pops up select the "don't bother me next time" check box.

Click the green checkmark button on the right side of the title bar.

this seemed a little broken to me the only way to navigate the is to click in the menu box and hit the down key.
In here we want to turn off sounds (general ->sound)
and under DVD to DVD I changed default output size to "DVD9" (shouldn't be necessary) I do this becasue I transcode them to H.264 video and pass thru the audio using handbrake. If you plan to just burn them to a standard 4.3 GB DVD-R/+R/RW then you would want to keep that at DVD5

My XBMC-Live install in sitting on a 8GB esata stick.. I don't have much in the way of space so I make up for that by having Gigabit lan to a sever with a large amount of space.

I already have a directory that I can write to mounted but wine will only see the free space of the current drive unless I add a new drive as a network share.

winecfg


A window will pop up click the "Drives tab" add a dive letter select your folder on the server you have write access to and click "show advanced" then choose type of "network share.
we are done in there so hit "ok."

I created the file .wine/drive_c/Program\ Files/DVDFab\ 7/dvdfab.bat with this in it:


c:\Program Files\DVDFab 7\DVDFab.exe /MODE "FULLDISC" /SRC "D:\" /DEST "E:\" /OUTDISC DVD9 /CLOSE


choose your own options from
http://www.dvdfab.com/docs/index.php/Main/RunningProgramCommandLine
pop in a DVD and run:

wineconsole C:\\Program\ Files\\DVDFab\ 7\\dvdfab.bat


If everything goes will it should rip your movie and close it self.

to put it in a script you just

/usr/bin/xvfb-run /usr/bin/wineconsole C:\\Program\ Files\\DVDFab\ 7\\dvdfab.bat


I'm using "launcher" program addon for XBMC, for some reason I had to launch it twice for it to rip.. I wrote a bash script for a work-around, it will stop you from ripping the same disc twice or overwriting a ripped dvd because of unimaginative DVD volume names. This script goes on the XBMC box. It doesn't copy well here is the link. I usually save them to /usr/local/bin/ and don't for get to enable execution "chmod +x"


It would go something like this for each script:
download the file, move it to /usr/local/bin/
sudo mv DVDFab /usr/local/bin/
make it executable and readable for all and writable for the owner
sudo chmod 755 /usr/local/bin/DVDFab
change the owner and group to root(so you don't accidentally delete it or change it. 
sudo chown root:root  /usr/local/bin/DVDFab


DVDFab:

#!/bin/bash
#kill wine and xvfb if they are already running. Die Mofo!
killall -I wineconsole.exe
killall -I xvfb
#must be mounted first.
mount /dev/cdrom
#get the name of the DVD
VOLNAME=`volname`
DVDLOCATION="/media/gigantor/downloads/ARCHIVE/FullDisc/$VOLNAME"
#1st attempt to backup the DVD
#if the folder allready exsists display warning and exit.
if [ -d $DVDLOCATION ]; then
        wget 'http://xbmc:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification("DVD folder already exists. Go fix it.","",11000,"/home/xbmc/.xbmc/Green-Help.png"))' -o /dev/null -q -O /dev/null
        exit
else
        /usr/bin/xvfb-run /usr/bin/wineconsole C:\\Program\ Files\\DVDFab\ 7\\dvdfab.bat
fi

#If the folder exists
if [ -d $DVDLOCATION ]; then
        #send popup to xbmc and stop here if the folder exists
        wget 'http://xbmc:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification("DVD Rip complete","",11000,"/home/xbmc/.xbmc/Green-Help.png"))' -o /dev/null -q -O /dev/null
        umount /dev/cdrom
        exit
else
        #if at first you don't succeed...
        /usr/bin/xvfb-run /usr/bin/wineconsole C:\\Program\ Files\\DVDFab\ 7\\dvdfab.bat
        if [ -d $DVDLOCATION ]; then
                wget 'http://xbmc:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification("DVD Rip complete","",11000,"/home/xbmc/.xbmc/Green-Help.png"))' -o /dev/null -q -O /dev/null
        fi
fi

umount /dev/cdrom


You know it is successful when the tray pops out.

I would like to turn this into a XBMC plugin and automate the transcoding. I wrote a simple bash script to use HandbrakeCLI
here is a link to the script.


hb:

#!/bin/bash

if [ "$1" = "--help" ] || [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
  echo "for to make MKV h.246 video with passthrough AC3 audio from Movie DVD and subtitle"
  echo "HighQ movie :Usage $0 movie input output"
  echo "LowQ movie  :Usage $0 moviel input output"
  echo "HighQ TV    :Usage $0 tv input Name.of.Show Season starting.episode.number number.of.shows.on.disc"
  echo "LowQ TV     :Usage $0 tvl input Name.of.Show Season starting.episode.number number.of.shows.on.disc"

  exit 0
fi
saveto=/bfhdd/downloads/ARCHIVE/
saveuser=james
savegroup=media
savemod=775
let epend=$5+$6-1
i=0

case $1 in
        movie)
        /usr/bin/HandBrakeCLI -i "$2" -o "$3" -L -e x264 -q 20.0 -a 1,1 -E ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mkv --detelecine --decomb --loose-anamorphic -m -N eng --subtitle 1 -v 9 -x b-adapt=2:rc-lookahead=40
        ;;
        moviel)
        /usr/bin/HandBrakeCLI -i "$2" -o "$3" -L -e x264 -q 20.0 -a 1 -E lame -B 160 -6 auto -R 48 -D 0.0,0.0 -f mkv --detelecine --decomb --loose-anamorphic -m -N eng --subtitle 1 -x b-adapt=2:rc-lookahead=40
        ;;
        tv)
          for ep in $(seq $5 1 $epend)
                do
                  let i=i+1;
                  epno=$(printf %02d $ep)
                  seno=$(printf %02d $4)
                  file_name="$saveto$3 - S${seno}E${epno}.mkv"
                  if [ !-f file_name ]; then
                    /usr/bin/HandBrakeCLI -i "$2" -o "$file_name" -t $i -e x264 -q 20.0 -a 1,1 -E ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mkv -$
                    chown $saveuser:$savegroup "$file_name"
                    chmod $savemod "$file_name"
                  fi
          done
        ;;
        tvl)
          for ep in $(seq $4 1 $epend)
                do
                  let i=i+1;
                  epno=$(printf %02d $ep)
                  seno=$(printf %02d $4)
                  file_name="$saveto$3 - S${seno}E${epno}.mkv"
                  /usr/bin/HandBrakeCLI -i "$2" -o "$file_name" -t $i -e x264 -q 20.0 -a 1 -E lame -B 160 -6 dpl2 -R 48 -D 0.0 -f mkv --strict-anamorphic -m -N eng --subtitle 1 --subtitle-default -v 9 -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0
                  chown $saveuser:$savegroup "$file_name"
                  chmod $savemod "$file_name"
                done
        ;;
esac
#end of hb


This script is for future use as a cron job. It searches for .info files in the directory of the rips, then trans-codes using handbrake.


Link


#!/bin/bash
backupdir="/where/you/have/DVDfab/ripping/to/FullDisc/"
moviedir="/where/you/have/your/movies/"
tvdir="/where/you/have/your/TV Shows/"
for file in $backupdir* ; do
        if [ -f "$file/.info" ]; then
                . $file/.info
                echo $type
                echo $title
                case $type in
                movie)
                if [ $movieyear ]; then
                  moviename="$moviedir$title ($movieyear).mkv"
                else
                  moviename="$moviedir$title.mkv"
                fi
                  /usr/bin/HandBrakeCLI -i "$file" -o "$moviename" -L -e x264 -q 20.0 -a 1,1 -E ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mkv --d$
                  rm $file/.info
                ;;
                tv)
                if [[ ( $season ) && ( $title ) && ( $startep ) && ( $numberep) ]]; then
                  tvsavedir="$tvdir$title/Season $season"
                  if [ ! -d "$tvdir$title" ]; then
                       /bin/mkdir "$tvdir$title" 
                  fi  
                  if [ ! -d "$tvsavedir" ]; then
                       /bin/mkdir "$tvsavedir" 
                  fi  
                  for ep in $(seq $startep 1 $epend)
                        do
                          let i=i+1;
                          epno=$(printf %02d $ep)
                          seno=$(printf %02d $season)
                          file_name="$tvsavedir/$title - S${seno}E${epno}.mkv"
                          /usr/bin/HandBrakeCLI -i "$2" -o "$file_name" -t $i -e x264 -q 20.0 -a 1,1 -E ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f$
                          chown root:media "$file_name"
                          chmod 555 "$file_name"
                  done   

                fi
                ;;
                esac
        fi     
        type=""
        title=""
        season=""
        startep=""
        numberep=""
done   



Some scripts where only tested on opensolaris but they should work on any *nix.(if you run as super user) some have not been tested yet.

I plan on keeping this up-to-date when as I change things so comment or email me if got something wrong of if it isn't working for you.

No comments:

Post a Comment