forked from nick-cromwell/makemkv-autorip-script
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathautorip.sh
86 lines (76 loc) · 2.7 KB
/
autorip.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
#!/bin/bash
# Defining variables for later use
SOURCEDRIVE="$1"
SCRIPTROOT="$(dirname """$(realpath "$0")""")"
CACHE="$(awk '/^cache/{print $1}' "$SCRIPTROOT/settings.cfg" | cut -d '=' -f2)"
DEBUG="$(awk '/^debug/{print $1}' "$SCRIPTROOT/settings.cfg" | cut -d '=' -f2)"
MINLENGTH="$(awk '/^minlength/{print $1}' "$SCRIPTROOT/settings.cfg" | cut -d '=' -f2)"
OUTPUTDIR="$(awk '/^outputdir/' "$SCRIPTROOT/settings.cfg" | cut -d '=' -f2 | cut -f1 -d"#" | xargs)"
ARGS=""
# Check if the source drive has actually been set and is available
if [ -z "$SOURCEDRIVE" ]; then
echo "[ERROR] Source Drive is not defined."
echo " When calling this script manually, make sure to pass the drive path as a variable: ./autorip.sh [DRIVE]"
exit 1
fi
setcd -i "$SOURCEDRIVE" | grep --quiet 'Disc found'
if [ ! $? ]; then
echo "[ERROR] $SOURCEDRIVE: Source Drive is not available."
exit 1
fi
# Construct the arguments for later use
if [[ $OUTPUTDIR == ""\~*"" ]]; then
if [[ $OUTPUTDIR == ""\~/*"" ]]; then
OUTPUTDIR=$(echo "$(eval echo ~"${SUDO_USER:-$USER}")/${OUTPUTDIR:2}" | sed 's:/*$::')
else
OUTPUTDIR="$(eval echo ~"${SUDO_USER:-$USER}")"
fi
fi
if [ -d "$OUTPUTDIR" ]; then
:
else
echo "[ERROR]: The output directory specified in settings.conf is invalid!"
exit 1
fi
if [ -d "$SCRIPTROOT/logs" ]; then
:
else
echo "[ERROR]: Log directory under $SCRIPTROOT/logs is missing! Trying to create it."
mkdir "$SCRIPTROOT/logs"
exit 1
fi
if [ -z "$CACHE" ]; then
if [ "$CACHE" = "-1" ]; then
:
elif [[ "$CACHE" =~ ^[0-9]+$ ]]; then
ARGS="--cache=$CACHE"
fi
fi
if [ "$DEBUG" = "true" ]; then
ARGS="$ARGS --debug"
fi
if [[ "$MINLENGTH" =~ ^[0-9]+$ ]]; then
ARGS="$ARGS --minlength=$MINLENGTH"
else
ARGS="$ARGS --minlength=0"
fi
# Match unix drive name to Make-MKV drive number and check it
SOURCEMMKVDRIVE=$(makemkvcon --robot --noscan --cache=1 info disc:9999 | grep "$SOURCEDRIVE" | grep -o -E '[0-9]+' | head -1)
if [ -z "$SOURCEMMKVDRIVE" ]; then
echo "[ERROR] $SOURCEDRIVE: Make-MKV Source Drive is not defined."
exit 1
fi
echo "[INFO] $SOURCEDRIVE: Started ripping process"
#Extract DVD Title from Drive
DISKTITLERAW=$(blkid -o value -s LABEL "$SOURCEDRIVE")
DISKTITLERAW=${DISKTITLERAW// /_}
NOWDATE=$(date +"%F_%H-%M-%S")
DISKTITLE="${DISKTITLERAW}_-_$NOWDATE"
mkdir "$OUTPUTDIR/$DISKTITLE"
makemkvcon mkv --messages="${SCRIPTROOT}/logs/${NOWDATE}_$DISKTITLERAW.log" --noscan --robot $ARGS disc:"$SOURCEMMKVDRIVE" all "${OUTPUTDIR}/${DISKTITLE}"
if [ $? -le 1 ]; then
echo "[INFO] $SOURCEDRIVE: Ripping finished (exit code $?), ejecting"
else
echo "[ERROR] $SOURCEDRIVE: RIPPING FAILED (exit code $?), ejecting. Please check the logs under ${SCRIPTROOT}/logs/${NOWDATE}_${DISKTITLERAW}.log"
fi
eject "$SOURCEDRIVE"