-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvdrip
executable file
·300 lines (238 loc) · 7.15 KB
/
dvdrip
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
source /usr/share/diskripper/config
#set -xv
ripdir="${DVD_ripdir}"
encdir="${movie_outdir}"
outformat="${DVD_outformat}"
logdir=/home/${user}/.var/log/diskrip/dvd/
install -d -o $user -g $user ${logdir}
ripdirSuffix=""
encdirSuffix=""
episodeStartNum=0
###################
GetDiscname()
{
discname=$(lsdvd $device | grep "Disc Title")
discname=${discname:12}
if [[ $discname == "" ]]; then
discname=$(blkid -o value -s LABEL $device)
fi
discname=$(tr '_' ' ' <<<"$discname")
discname=$(echo "$discname" | tr '[:upper:]' '[:lower:]')
arr=( $discname )
discname=${arr[@]^}
touch ${logdir}riplist.txt
echo "ripping disc $discname " >> ${logdir}riplist.txt
}
CalcEncodeDir()
{
i=1
if [[ ripdirSuffix != "" ]]; then
encdirSuffix=$ripdirSuffix
else
while [ -d "${encdir}/${discname}${encdirSuffix}" ]; do
((i=i+1))
encdirSuffix=".$i"
done
fi
encdir="${encdir}/${discname}${encdirSuffix}"
install -d -o $user -g $user "$encdir"
}
RipDisk()
{
echo "ripping disc $discname" > "$logfile"
i=1
while [ -d "${ripdir}/${discname}${ripdirSuffix}" ]; do
((i=i+1))
ripdirSuffix=".$i"
done
ripdir=${ripdir}/${discname}${ripdirSuffix}
install -d -o $user -g $user "$ripdir"
if [[ $test == true ]]; then
echo "makemkvcon -r --progress=stdout --minlength=1500 --decrypt mkv dev:$device $titlenum \"$ripdir\""
else
makemkvcon -r --progress=stdout --minlength=1500 --decrypt mkv dev:$device $titlenum "$ripdir" >> "$logfile";
chown -R $user:$user "$ripdir"
fi
sleep 2 ;
}
EncodeFiles()
{
IFS=',' read -ra encfiles <<< "$encFileNums"
numFiles=`find "$ripdir" -maxdepth 1 -iname "*.${outformat}" -printf x | wc -c`
if [[ $episodeStartNum > 0 ]]; then
e=$episodeStartNum
else
e=1
fi
i=1
while IFS= read -r -d $'\0' file;
do
if [[ $encFileNums != "" ]] && [[ ! ${encfiles[@]} =~ $i ]]; then
continue
fi
title=$(mkvinfo "${file}" | grep Title)
title=${title:11}
if [[ $title == "" ]]; then
title=${discname}${encdirSuffix}
fi
fileoutname="${title}"
if (( $numFiles > 1 )); then
fileoutname="${fileoutname}_$e"
((e=e+1))
fi
fileoutname="${fileoutname}.${outformat}"
if [[ $move == true ]]; then
mv "$file" "${encdir}/${fileoutname}"
else
if [[ $encode == true ]] ; then
echo "Encoding $file to ${fileoutname}" >> "$logfile";
if [[ $test == true ]]; then
encstr="echo ${ffmpeg_string}"
eval $encstr
else
encstr=${ffmpeg_string}
eval "${encstr}" 2> >(tee -a "$logfile");
RC=$?
if [ "${RC}" -eq "0" ]; then
echo "removing $file"
rm "$file"
fi
fi
fi
fi
chown -R $user:$user "$encdir"
echo "File = ${encdir}/${fileoutname} ---- Disc = ${discname}" >> "${logdir}riplist.txt"
((i=i+1))
done < <(find "$ripdir" -maxdepth 1 -iname "*.${outformat}" -print0 | sort -z)
# remove directory if empty
if [ -z "$( ls -A ${ripdir} )" ]; then
rmdir ${ripdir}
fi
}
###################
RipDiskMode()
{
titlenum="all"
encode=true
while getopts ":t:Tme" flag; do
case ${flag} in
t) titlenum=${OPTARG}
shift 2 ;;
T) test=true
shift;;
m) move=true
shift;;
e) encode=true
shift;;
esac
done
device=$1
GetDiscname
logfile="${logdir}${discname}.log"
RipDisk
if [[ $move == true ]] || [[ $encode == true ]] ; then
CalcEncodeDir
EncodeFiles
fi
eject -r $device
}
EncodeMode()
{
while getopts ":d:i:o:s:f:T" flag; do
case ${flag} in
d) discname=${OPTARG};;
i) indir=${OPTARG};;
o) outdir=${OPTARG};;
s) episodeStartNum=${OPTARG};;
f) encFileNums=${OPTARG};;
T) test=true;;
esac
done
logfile="${logdir}${discname}.log"
ripdir="${ripdir}/${indir}"
encdir="${encdir}/${outdir}"
install -d -o $user -g $user "$encdir"
encode=true
EncodeFiles
}
EpisodeRenameMode()
{
while getopts ":i:n:s:T" flag; do
case ${flag} in
i) inpaths=${OPTARG};;
n) seriesName=${OPTARG};;
s) season=${OPTARG};;
T) test=true;;
esac
done
outdir="${tv_outdir}/${seriesName}/season ${season}"
install -d "$outdir"
e=1
IFS='|' read -ra paths <<< "$inpaths"
for in in "${paths[@]}"; do
numFiles=`find "$in" -maxdepth 1 -iname "*.${outformat}" -printf x | wc -c`
echo $e
while IFS= read -r -d $'\0' file;
do
if [[ $test == true ]]; then echo "mv \"$file\" \"${outdir}/${seriesName} - S${season}E${e}.${outformat}\""
else
mv "$file" "${outdir}/${seriesName} - S${season}E${e}.${outformat}"
fi
((e=$e+1))
done < <(find "$in" -maxdepth 1 -iname "*.${outformat}" -print0 | sort -z)
done
}
InfoMode()
{
device=$1
makemkvcon --progress=stdout --minlength=1500 info dev:$device | grep ""
}
Help()
{
# Display Help
echo -e "bdrip -h Show this Help menu
bdrip [mode] [options]
Modes:
ripdisk [options] <dev> - rips and optinally encodes/moves resulting files to new folder
options:
-T -test rip, print makemkvcon command without ripping
-t <int> -title number - select title to rip
-m -move ripped files without encoding
-e -encode files to ouput
dev: -specify device
encode [options]: - encodes previously ripped files
options:
-T -test encode, print ffmped command without encoding
-d -specify discname
-i <str> -input directory
-o <str> -output directory
-s <int> -specify start file number squencing, default is 1
-f <int> -specify files to encode. comma delimeted list numbers representing sort index in directory.
ex: -f \"1,3,4\" . This will encode get the first, third and fourth file in directory.
episodes[options]: -combines files in multiple folders to one season folder and renames them.
Files are processed alphabeticaly in each directory, and each directory
is process in the order passes ass argument
ex: dvdrip episodes -n \"Friends\" -i \"Friends/Friends-Disc1\" -s \"1\"
results in file naming: Friends/season 1/Friends S1E1.mkv
-T -test move, print command without moving files
-i -array of directory paths containing tv episodes.
ex. -i \"Friends Disc1|Friends Disc2\"
-n -Name of TV show
-s -Season number
info <dev>: -print makemkvcon info about disc
options:
-t -print title info
dev: -specify device
"
}
###################
mode=$1
shift
case $mode in
-h) Help;;
ripdisk) RipDiskMode "${@}";;
encode) EncodeMode "${@}";;
episodes) EpisodeRenameMode "${@}";;
"info") InfoMode "${@}";;
esac