-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoripper.sh
102 lines (88 loc) · 3.33 KB
/
autoripper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Derek Moyes <derek (dot) moyes (at) gmail
# https://github.com/derekmoyes/handbrake-automation
### Fill in these variables, before each rip #################################
## RipType:
## title : rips a single file for each title on the disc
## chapter: rips a single file for each chapter of a single title
riptype=title ## Uncomment only one of these
#riptype=chapter ## Uncomment only one of these
#videotitle=1 ## Set this for chapter ripping
#videochapters=53 ## Set this for chapter ripping
## DVDPath: Linux /dev/dvd, Mac /dev/yourdevice, VIDEO_TS
dvdpath=/dev/dvd
discname=OurVacationDisc1
## Encoder Tune: animation, film, grain
hbencodertune=film
hbpreset="General/HQ 1080p30 Surround"
## Storage Location: No trailing slash
storepath=/Users/yourusername/Movies
### Do not change stuff below here ###########################################
## Setup
# Detect OS, checking requirements
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*)
machine=Linux
echo "Linux machine type found, using GNU grep."
grepbin=grep
;;
Darwin*)
machine=Mac
echo "Mac machine type found, checking for GNU grep..."
if [ -f $(which ggrep) ]
then
echo "GNU grep (ggrep) found, continuing."
grepbin=$(which ggrep)
else
echo "GNU grep (ggrep) not found, you'll need to have brew installed, from:"
echo " https://brew.sh/"
echo ""
echo "Once you have brew, please install the GNU version of ggrep using:"
echo "$ brew install grep"
exit 1
fi
;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
# Create storage location
rippath=$storepath/zAutoRipping-$discname
echo "Creating $rippath..."
mkdir -p $rippath
### Start the work ###########################################################
case "${riptype}" in
title*)
echo "Beginning title rips..."
# Read handbrake's stderr into variable
rawout=$(HandBrakeCLI -i $dvdpath -t 0 2>&1 >/dev/null)
# Parse the variable to get the count
count=$(echo $rawout | $grepbin -Pao " title \d{1,2}+:" | wc -l)
for title in $(seq $count)
do
ripname=$rippath/$discname-t$title.mp4
echo Ripping $discname Title $title to $ripname
HandBrakeCLI --preset-import-gui --preset "$hbpreset" --encoder-tune $hbencodertune --input $dvdpath --output $ripname --title $title --all-audio
done
;;
chapter*)
echo "Beginning chapter rips..."
ripcounter=1
while [ $ripcounter -le $videochapters ];
do
ripname=$rippath/$discname-t$videotitle-ch$ripcounter.mp4
echo Ripping Title $videotitle Chapter $ripcounter to $ripname
HandBrakeCLI --preset-import-gui --preset "$hbpreset" --encoder-tune $hbencodertune --input $dvdpath --output $ripname --title $videotitle -c $ripcounter --all-audio
((ripcounter++))
done
;;
esac
sleep 5
### Clean up #################################################################
zdonePath=$storepath/RipDone
mkdir -p $zdonePath
mv $rippath $zdonePath/$discname
echo Completed $discname, stored at $zdonePath.
case "${machine}" in
Mac*) say Disc $discname rip complete;;
esac