/
ripmydvd
142 lines (115 loc) · 3.64 KB
/
ripmydvd
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
#cito M:755 O:0 G:0 T:/usr/local/bin/ripmydvd
#------------------------------------------------------------------------------
# Project Name - ShellProjects/source/ripmydvd
# Started On - Fri 29 Sep 21:19:47 BST 2017
# Last Change - Mon 19 Jun 23:34:57 BST 2023
# Author E-Mail - terminalforlife@yahoo.com
# Author GitHub - https://github.com/terminalforlife
#------------------------------------------------------------------------------
# Shell program using FFMPEG and MPlayer to rip your DVD.
#------------------------------------------------------------------------------
CurVer='2022-01-30'
Progrm='ripmydvd'
Usage() {
while read; do
printf "%s\n" "$REPLY"
done <<-EOF
Usage: $Progrm [OPTS] {-t|--title N[-N]} TARGET
-h, --help - Displays this help information.
-v, --version - Output only the version datestamp.
--aid X - Where X is the audio channel.
--alang X - Where X is the audio language; en or eng?
--asid X - Where X is the audio substream ID.
--endcmd CMD - Execute CMD command when ripping is done.
--startcmd CMD - Execute CMD command before ripping begins.
-C, --combine - Wrong language? This option should work.
-d, --device X - Use device X instead of '/dev/sr0'.
-e, --eject - Eject the device's tray upon completion.
-t, --title N[-N] - Where N is the title number on the DVD.
You may wish to use lsdvd to help you, especially with audio.
The '-C' option requires '--aid' or '--alang'. This will rip the
audio and video separately, then they will be combined into TARGET.
EOF
}
Err() {
printf 'Err: %s\n' "$2" 1>&2
(( $1 > 0 )) && exit $1
}
while [[ -n $1 ]]; do
case $1 in
--help|-h|-\?)
Usage; exit 0 ;;
--version|-v)
printf '%s\n' "$CurVer"; exit 0 ;;
--device|-d)
shift
[[ -b $1 ]] || Err 1 "Device not found at: $1"
Device=$1 ;;
--combine|-C)
Combine='True' ;;
--title|-t)
shift
if [[ $1 =~ ^([0-9]+|[0-9]+-[0-9]+)$ ]]; then
Title=$1
else
Err 1 'Invalid title.'
fi ;;
--aid)
shift
AID="-aid $1" ;;
--asid)
shift
ASID="-asid $1" ;;
--alang)
shift
ALang="-alang $1" ;;
--eject|-e)
Eject='True' ;;
--startcmd)
shift
StartCmd=$1 ;;
--endcmd)
shift
EndCmd=$1 ;;
*)
break ;;
esac
shift
done
Target="$*"
for CurDep in eject mkfifo ffmpeg mplayer; {
if ! type -P "$CurDep" &> /dev/null; then
Err 0 "Dependency '$CurDep' not met."
(( DepCount++ ))
fi
}
(( DepCount == 0 )) || exit 1
[[ -n $Target ]] || Err 1 'You need to provide a filename.'
[[ -n $Title ]] || Err 1 'Missing TARGET title to rip.'
[[ -n $Device ]] || Device='/dev/sr0'
FIFO="/tmp/stream_${$}.dump"
MPlayerArgs1="$AID $ASID $ALang -nosub -really-quiet -nolirc -nocache -vo x11"
MPlayerArgs2="-zoom -dumpstream -dumpfile "$FIFO" dvd://$Title/$Device"
[[ -n $StartCmd ]] && ($StartCmd)
if mkfifo "$FIFO"; then
if [[ $Combine == True ]]; then
if [[ -z $ALang && -z $AID ]]; then
Err 1 "Option '--combine' requires '--alang' or '--aid'."
fi
mplayer $MPlayerArgs1 -dumpaudio -dumpfile "/tmp/audio.dump"\
dvd://$Title/$Device &> /dev/null
mplayer $MPlayerArgs1 -dumpvideo -dumpfile "$FIFO"\
dvd://$Title/$Device &> /dev/null & disown
ffmpeg -loglevel fatal -stats -i /tmp/audio.dump -i "$FIFO" "$Target"
else
mplayer $MPlayerArgs1 $MPlayerArgs2 &> /dev/null & disown
ffmpeg -loglevel fatal -stats -i "$FIFO" "$Target"
fi
[[ -n $EndCmd ]] && ($EndCmd)
if [[ $Eject == True ]]; then
eject $Device
fi
else
Err 'Failed to create FIFO.'
fi