Merge commit 'origin'
[rip_dvd/.git] / rip_dvd.wrap
1 #!/bin/bash
2 # The purpose of this script is to encapsulate the calls
3 # made to the rip_dvd script. This is done to help distribute
4 # the resulting ripped files to the proper folders. This
5 # script is called from the mythtv menus for example with a
6 # smaller set of options.
7
8 ##############################################
9 # COMMAND LINE PROCESSING
10
11 # get the dvdtype from the command line
12 dvdtype=$1
13
14 # remove the dvdtype from the args, and interpret the rest
15 # of the args to be passed directly to the rip_dvd script.
16 shift 1
17
18 ##############################################
19 if [ -z "$dvdtype" ]; then
20   echo "-E- $0 <dvdtype>' is a required option"
21   usage
22 fi
23
24 mydir=$(cd $(dirname $0) && pwd)
25 if [ -z "$ripcmd" ]
26 then
27   if [ -x "$mydir/rip_dvd" ]
28   then
29     ripcmd="$mydir/rip_dvd"
30   else
31     echo >&2 "Cannot find your rip_dvd command!"
32     exit 1
33   fi
34 fi
35
36 ##############################################################################
37 # Local Machine Settings:
38 # Sources both the "default" conf file tracked by GIT (rip_dvd.conf.dist)
39 # and the local conf file created by each local machine (rip_dvd.conf)
40 # Copy the rip_dvd.conf.dist file to rip_dvd.conf and edit the later.
41 # This will allow you to override all the default values to meet your needs
42 # in a way that won't get clobbered when you pull updates from my GIT repo.
43 ##############################################################################
44 config="${0%/*}/rip_dvd.conf"
45
46 # The config file will be searched for in the following location order:
47 found_config=0
48
49 # 1) /path/to/rip_dvd/script/rip_dvd.conf.dist
50 [ -e "${config}.dist" ] && found_config=1 && . "${config}.dist"
51
52 # 2) /path/to/rip_dvd/script/rip_dvd.conf
53 [ -e "${config}" ] && found_config=1 && . "${config}"
54
55 # 3) /etc/rip_dvd.conf
56 [ -e "/etc/rip_dvd.conf" ] && found_config=1 && . "/etc/rip_dvd.conf"
57
58 # 4) $PWD/rip_dvd.conf
59 [ -e "$PWD/rip_dvd.conf" ] && found_config=1 && . "$PWD/rip_dvd.conf"
60
61 # Check to make sure we found the config file
62 if [ $found_config -eq 0 ]; then
63   echo "-E- Unable to find the rip_dvd.conf file: $config"
64   exit 1
65 fi
66
67 ##############################################
68 # get the name of the DVD from the DVD disk
69 dvdname=`volname $dev | awk '{ print $1 }'`
70 dvdname=${dvdname%.} # remove trailing '.' character
71
72 ##############################################
73 # Find out what type of DVD we are ripping
74 # And set our destination directory appropriately
75 # dvdtype parameter:
76 # - netflix = DVD ripped as an entire ISO image
77 #   since these are only kept around until we watch them,
78 #   there is no need to do anything less than full iso.
79 # - collection = Only DVD main feature is ripped
80 # - childrens = Only DVD main feature is ripped
81 # - church = Only DVD main feature is ripped
82 rip_opts="$* -j 2"
83 if [ "$dvdtype" == "netflix" ]; then
84   echo "-> Ripping Netflix DVD"
85   dest=/myth/video/DVDs/Netflix
86   rip_opts="$rip_opts"
87 elif [ "$dvdtype" == "collection" ]; then
88   echo "-> Ripping Personal Collection DVD"
89   dest=/myth/video/DVDs/Collection
90   rip_opts="$rip_opts"
91 elif [ "$dvdtype" == "childrens" ]; then
92   echo "-> Ripping Children's DVD"
93   dest=/myth/video/DVDs/Childrens
94   rip_opts="$rip_opts"
95 elif [ "$dvdtype" == "church" ]; then
96   echo "-> Ripping Church DVD"
97   dest=/myth/video/DVDs/Church
98   rip_opts="$rip_opts"
99 else
100   echo '-E- Must specify dvdtype as "netflix" or "collection" or "childrens" or "church"'
101   usage
102 fi
103
104 ##############################################
105 # Display progress window
106
107 # Pop up an xterm window and run the script inside of it
108 echo "xterm -T \"Ripping->$dvdname\" -geometry 72x15+20+10 -bg black -fg white -e \"/bin/bash\" -c \"$ripcmd -d $dest $rip_opts\" &"
109 xterm -T "Ripping->$dvdname" -geometry 72x15+20+10 -bg black -fg white -e "/bin/bash" -c "$ripcmd -d $dest $rip_opts" &
110
111 ##############################################
112 # OR display the script output directly in the terminal it's called from
113 #$ripcmd -d $dest $rip_opts
114
115 ##############################################