From 1016cc3b78dac3e5c8b5a7faa7b74d17652d661a Mon Sep 17 00:00:00 2001
From: "Alan J. Pippin" <ajp@pippins.net>
Date: Sun, 7 Feb 2010 20:34:19 -0700
Subject: [PATCH] Fixed issue with handbrake profile not being passed through
 properly

---
 rip_dvd | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/rip_dvd b/rip_dvd
index ab0d415..601bde7 100755
--- a/rip_dvd
+++ b/rip_dvd
@@ -101,7 +101,7 @@ fi
 ##############################################################################################
 # Command line processing
 ##############################################################################################
-while (($#)) && getopts 162mvifkzx:ht:n:d:b:s:t:a:p:e:j:l: opt "$@"
+while (($#)) && getopts 162wmvifkzx:ht:n:d:b:s:t:a:p:e:j:l: opt "$@"
 do
     case $opt in
         (n)     dvdname=$OPTARG;;
@@ -124,7 +124,7 @@ do
 	(x)     extension=$OPTARG;;
 	(j)     eject_disk=$OPTARG;;
 	(l)     aid_override=$OPTARG;;
-        (w)     set -$opt;;
+        (w)     set -x;;
         (h)     show_usage=1;;
         (:)     echo >&2 "$0: $OPTARG requires a value"; errors=errors+1;;
         (\?)    echo >&2 "$0: invalid option '$OPTARG'"; errors=errors+1;;
@@ -459,6 +459,7 @@ function encode_vob_file_handbrake {
   typeset handbrake_video_encoder_opts=""
   typeset filetype=""
   typeset handbrake_audio_opts=""
+  typeset hb_profile=""
 
   # Set a variable that we will use later to determine if we found a handler for $profile or not
   typeset -i found_profile=0    
@@ -557,7 +558,6 @@ function encode_vob_file_handbrake {
     
     # extract the HandBrake Profile name from $profile
     hb_profile=`echo "$profile" | sed 's/hb_//g' | sed 's/_/ /g'`
-    handbrake_opts[0]="-Z \"$hb_profile\""
   fi
 
   # Make sure we found a handler for the given profile
@@ -591,9 +591,15 @@ function encode_vob_file_handbrake {
   done
   
   # Execute the handbrake command to encode the video
-  echo -e "\n   Encoding: $handbrake_cli -i \"$vobfile\" -o \"$final_output_file\" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1" >> "$logfile"
-  $handbrake_cli -i "$vobfile" -o "$final_output_file" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1
-  handbrake_retval=$?
+  if [ -n "$hb_profile" ]; then
+    echo -e "\n   Encoding: $handbrake_cli -i \"$vobfile\" -o \"$final_output_file\" -Z \"$hb_profile\" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1" >> "$logfile"
+    $handbrake_cli -i "$vobfile" -o "$final_output_file" -Z "$hb_profile" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1
+    handbrake_retval=$?
+  else 
+    echo -e "\n   Encoding: $handbrake_cli -i \"$vobfile\" -o \"$final_output_file\" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1" >> "$logfile"
+    $handbrake_cli -i "$vobfile" -o "$final_output_file" $handbrake_cmd_line_opts $handbrake_audio_opts $handbrake_video_encoder_opts $PASSES >> $encodelog 2>&1
+    handbrake_retval=$?
+  fi
   if [ $handbrake_retval != 0 ]; then
     fatal_and_exit "-E- Unhandled handbrake error"
   fi
-- 
2.34.1