Added new eject_opts option for greater flexibility.
[rip_dvd/.git] / rip_dvd.wrap
index 09ba254ffeed64e59387320b41141965d27b64c4..3dc8f3aae719e4805bf1f1f48f80a893db38bcd9 100755 (executable)
@@ -1,4 +1,29 @@
 #!/bin/bash
+# The purpose of this script is to encapsulate the calls
+# made to the rip_dvd script. This is done to help distribute
+# the resulting ripped files to the proper folders. This
+# script is called from the mythtv menus for example with a
+# smaller set of options.
+
+##############################################
+# Don't run if a previous rip attempt is still running
+SCRIPT_NAME1="rip_dvd.wrap"
+SCRIPT_NAME2="xterm -T Ripping"
+MY_PID=$$
+PARENT_PID=$PPID
+GRAND_PID=$(ps -ef | grep "^[a-zA-Z]* [ ]* $PARENT_PID " | awk '{print $3}')
+GREAT_GRAND_PID=$(ps -ef | grep "^[a-zA-Z]* [ ]* $GRAND_PID " | awk '{print $3}')
+ps -ef | grep -e "$SCRIPT_NAME1" -e "$SCRIPT_NAME2" | grep -v grep | grep -v $MY_PID | grep -v $PARENT_PID | grep -v $GRAND_PID | grep -v $GREAT_GRAND_PID
+if [[ $? == 0 ]]; then
+  echo -e "-E- Found an instance of this script already running. Aborting this additional attempt to rip..."
+  echo -e "    my_pid=$MY_PID parent_pid=$PARENT_PID grand_pid=$GRAND_PID great_grand_pid=$GREAT_GRAND_PID\n"
+  CALLER=$(ps -ef | grep "^[a-zA-Z]* [ ]* $PPID " | awk '{print $3}')
+  CALLER_CALLER=$(ps -ef | grep "^[a-zA-Z]* [ ]* $CALLER " | awk '{print $3}')
+  echo I was called from $CALLER who was called by $CALLER_CALLER
+  ps -ef | grep $MY_PID | grep -v grep
+  ps -ef | grep $PARENT_PID | grep -v grep
+  exit 1
+fi
 
 ##############################################
 # COMMAND LINE PROCESSING
@@ -13,7 +38,19 @@ shift 1
 ##############################################
 if [ -z "$dvdtype" ]; then
   echo "-E- $0 <dvdtype>' is a required option"
-  usage
+  exit 1
+fi
+
+mydir=$(cd $(dirname $0) && pwd)
+if [ -z "$ripcmd" ]
+then
+  if [ -x "$mydir/rip_dvd" ]
+  then
+    ripcmd="$mydir/rip_dvd"
+  else
+    echo >&2 "Cannot find your rip_dvd command!"
+    exit 1
+  fi
 fi
 
 ##############################################################################
@@ -25,8 +62,27 @@ fi
 # in a way that won't get clobbered when you pull updates from my GIT repo.
 ##############################################################################
 config="${0%/*}/rip_dvd.conf"
-[ -e "${config}.dist" ] && . ${config}.dist
-[ -e "${config}" ] && . ${config}
+
+# The config file will be searched for in the following location order:
+found_config=0
+
+# 1) /path/to/rip_dvd/script/rip_dvd.conf.dist
+[ -e "${config}.dist" ] && found_config=1 && . "${config}.dist"
+
+# 2) /path/to/rip_dvd/script/rip_dvd.conf
+[ -e "${config}" ] && found_config=1 && . "${config}"
+
+# 3) /etc/rip_dvd.conf
+[ -e "/etc/rip_dvd.conf" ] && found_config=1 && . "/etc/rip_dvd.conf"
+
+# 4) $PWD/rip_dvd.conf
+[ -e "$PWD/rip_dvd.conf" ] && found_config=1 && . "$PWD/rip_dvd.conf"
+
+# Check to make sure we found the config file
+if [ $found_config -eq 0 ]; then
+  echo "-E- Unable to find the rip_dvd.conf file: $config"
+  exit 1
+fi
 
 ##############################################
 # get the name of the DVD from the DVD disk
@@ -41,28 +97,28 @@ dvdname=${dvdname%.} # remove trailing '.' character
 #   since these are only kept around until we watch them,
 #   there is no need to do anything less than full iso.
 # - collection = Only DVD main feature is ripped
-# - childrens = Only DVD main feature is ripped
+# - children = Only DVD main feature is ripped
 # - church = Only DVD main feature is ripped
 rip_opts="$* -j 2"
 if [ "$dvdtype" == "netflix" ]; then
   echo "-> Ripping Netflix DVD"
-  dest=/myth/video/DVDs/Netflix
+  dest="$moviedir/Netflix"
   rip_opts="$rip_opts"
 elif [ "$dvdtype" == "collection" ]; then
   echo "-> Ripping Personal Collection DVD"
-  dest=/myth/video/DVDs/Collection
+  dest="$moviedir/Collection"
   rip_opts="$rip_opts"
-elif [ "$dvdtype" == "childrens" ]; then
+elif [ "$dvdtype" == "children" ]; then
   echo "-> Ripping Children's DVD"
-  dest=/myth/video/DVDs/Childrens
+  dest="$moviedir/Children"
   rip_opts="$rip_opts"
 elif [ "$dvdtype" == "church" ]; then
   echo "-> Ripping Church DVD"
-  dest=/myth/video/DVDs/Church
+  dest="$moviedir/Church"
   rip_opts="$rip_opts"
 else
-  echo '-E- Must specify dvdtype as "netflix" or "collection" or "childrens" or "church"'
-  usage
+  echo '-E- Must specify dvdtype as "netflix" or "collection" or "children" or "church"'
+  exit 1
 fi
 
 ##############################################